refactor handling of "other" files in ls-files and status
When the "git status" display code was originally converted
to C, we copied the code from ls-files to discover whether a
pathname returned by read_directory was an "other", or
untracked, file.
Much later, 5698454e
updated the code in ls-files to handle
some new cases caused by gitlinks. This left the code in
wt-status.c broken: it would display submodule directories
as untracked directories. Nobody noticed until now, however,
because unless status.showUntrackedFiles was set to "all",
submodule directories were not actually reported by
read_directory. So the bug was only triggered in the
presence of a submodule _and_ this config option.
This patch pulls the ls-files code into a new function,
cache_name_is_other, and uses it in both places. This should
leave the ls-files functionality the same and fix the bug
in status.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
8ed0a740dd
commit
98fa473887
@ -91,39 +91,10 @@ 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++) {
|
||||
struct dir_entry *ent = dir->entries[i];
|
||||
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)
|
||||
continue; /* exact match */
|
||||
pos = -pos - 1;
|
||||
if (pos < active_nr) {
|
||||
ce = active_cache[pos];
|
||||
if (ce_namelen(ce) == len &&
|
||||
!memcmp(ce->name, ent->name, len))
|
||||
continue; /* Yup, this one exists unmerged */
|
||||
}
|
||||
if (!cache_name_is_other(ent->name, ent->len))
|
||||
continue;
|
||||
show_dir_entry(tag_other, ent);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user