Skip to content

Commit 5698454

Browse files
torvaldsJunio C Hamano
authored andcommitted
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>
1 parent f9135db commit 5698454

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

builtin-ls-files.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,38 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
8989
static void show_other_files(struct dir_struct *dir)
9090
{
9191
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+
*/
92104
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-
*/
96105
struct dir_entry *ent = dir->entries[i];
97-
int pos = cache_name_pos(ent->name, ent->len);
106+
int len, pos;
98107
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);
99117
if (0 <= pos)
100-
die("bug in show-other-files");
118+
continue; /* exact match */
101119
pos = -pos - 1;
102120
if (pos < active_nr) {
103121
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))
106124
continue; /* Yup, this one exists unmerged */
107125
}
108126
show_dir_entry(tag_other, ent);

0 commit comments

Comments
 (0)