@matheusbsbs / matheus-bagliano / commits / 5698454ea0
Fork 0

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

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@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Apr 14, 2007 at 16:22 UTC 5698454ea052369dc98d38b45c21307b07a6c4a3
1 file changed +25 -7
builtin-ls-files.c
+25 -7
@@ -89,20 +89,38 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
89 static void show_other_files(struct dir_struct *dir)
90 {
91 int i;
92 +
93 +
94 + /*
95 + * Skip matching and unmerged entries for the paths,
96 + * since we want just "others".
97 + *
98 + * (Matching entries are normally pruned during
99 + * the directory tree walk, but will show up for
100 + * gitlinks because we don't necessarily have
101 + * dir->show_other_directories set to suppress
102 + * them).
103 + */
104 for (i = 0; i < dir->nr; i++) {
93 - /* We should not have a matching entry, but we
94 - * may have an unmerged entry for this path.
95 - */
105 struct dir_entry *ent = dir->entries[i];
97 - int pos = cache_name_pos(ent->name, ent->len);
106 + int len, pos;
107 struct cache_entry *ce;
108 +
109 + /*
110 + * Remove the '/' at the end that directory
111 + * walking adds for directory entries.
112 + */
113 + len = ent->len;
114 + if (len && ent->name[len-1] == '/')
115 + len--;
116 + pos = cache_name_pos(ent->name, len);
117 if (0 <= pos)
100 - die("bug in show-other-files");
118 + continue; /* exact match */
119 pos = -pos - 1;
120 if (pos < active_nr) {
121 ce = active_cache[pos];
104 - if (ce_namelen(ce) == ent->len &&
105 - !memcmp(ce->name, ent->name, ent->len))
122 + if (ce_namelen(ce) == len &&
123 + !memcmp(ce->name, ent->name, len))
124 continue; /* Yup, this one exists unmerged */
125 }
126 show_dir_entry(tag_other, ent);