Fix some "git ls-files -o" fallout from gitlinks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since "git ls-files" doesn't really pass down any details on what it 
really wants done to the directory walking code, the directory walking 
code doesn't really know whether the caller wants to know about gitlink 
directories, or whether it wants to just know about ignored files.

So the directory walking code will return those gitlink directories unless 
the caller has explicitly told it not to ("dir->show_other_directories" 
tells the directory walker to only show "other" directories).

This kind of confuses "git ls-files -o", because
 - it didn't really expect to see entries listed that were already in the 
   index, unless they  were unmerged, and would die on that unexpected 
   setup, rather than just "continue".
 - it didn't know how to match directory entries with the final "/" 

This trivial change updates the "show_other_files()" function to handle 
both of these issues gracefully. There really was no reason to die, when 
the obviously correct thing for the function was to just ignore files it 
already knew about (that's what "other" means here!).

Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
---

Quite frankly, I also debated just telling the directory reading functions 
exactly what we wanted, and we migth want to do that too (moving all the 
"static int" flags in builtin-ls-files.c to just be bitfield members of 
the "struct dir_struct" instead). 

But regardless of whether we'd like to extend and flesh out the 
"read_directory()" interface, this is definitely the right thing to do 
*anyway*.

 builtin-ls-files.c |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 74a6aca..f7c066b 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -89,20 +89,38 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
 static void show_other_files(struct dir_struct *dir)
 {
 	int i;
+
+
+	/*
+	 * Skip matching and unmerged entries for the paths,
+	 * since we want just "others".
+	 *
+	 * (Matching entries are normally pruned during
+	 * the directory tree walk, but will show up for
+	 * gitlinks because we don't necessarily have
+	 * dir->show_other_directories set to suppress
+	 * them).
+	 */
 	for (i = 0; i < dir->nr; i++) {
-		/* We should not have a matching entry, but we
-		 * may have an unmerged entry for this path.
-		 */
 		struct dir_entry *ent = dir->entries[i];
-		int pos = cache_name_pos(ent->name, ent->len);
+		int len, pos;
 		struct cache_entry *ce;
+
+		/*
+		 * Remove the '/' at the end that directory
+		 * walking adds for directory entries.
+		 */
+		len = ent->len;
+		if (len && ent->name[len-1] == '/')
+			len--;
+		pos = cache_name_pos(ent->name, len);
 		if (0 <= pos)
-			die("bug in show-other-files");
+			continue;	/* exact match */
 		pos = -pos - 1;
 		if (pos < active_nr) { 
 			ce = active_cache[pos];
-			if (ce_namelen(ce) == ent->len &&
-			    !memcmp(ce->name, ent->name, ent->len))
+			if (ce_namelen(ce) == len &&
+			    !memcmp(ce->name, ent->name, len))
 				continue; /* Yup, this one exists unmerged */
 		}
 		show_dir_entry(tag_other, ent);
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]