ls-files -i: pay attention to exclusion of leading paths
"git ls-files --exclude=t/ -i" does not show paths in directory t/ that have been added to the index, but it should. The excluded() API was designed for callers who walk the tree from the top, checking each level of the directory hierarchy as it descends if it is excluded, and not even bothering to recurse into an excluded directory. This would allow us optimize for a common case by not having to check if the exclude pattern "foo/" matches when looking at "foo/bar", because the caller should have noticed that "foo" is excluded and did not even bother to read "foo/bar" out of opendir()/readdir() to call it. The code for "ls-files -i" however walks the index linearly, feeding paths without checking if the leading directory is already excluded. Introduce a helper function path_excluded() to let this caller properly call excluded() check for higher hierarchies as necessary. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@ -203,6 +203,10 @@ static void show_ru_info(void)
|
||||
static void show_files(struct dir_struct *dir)
|
||||
{
|
||||
int i;
|
||||
struct path_exclude_check check;
|
||||
|
||||
if ((dir->flags & DIR_SHOW_IGNORED))
|
||||
path_exclude_check_init(&check, dir);
|
||||
|
||||
/* For cached/deleted files we don't need to even do the readdir */
|
||||
if (show_others || show_killed) {
|
||||
@ -215,9 +219,8 @@ static void show_files(struct dir_struct *dir)
|
||||
if (show_cached | show_stage) {
|
||||
for (i = 0; i < active_nr; i++) {
|
||||
struct cache_entry *ce = active_cache[i];
|
||||
int dtype = ce_to_dtype(ce);
|
||||
if (dir->flags & DIR_SHOW_IGNORED &&
|
||||
!excluded(dir, ce->name, &dtype))
|
||||
if ((dir->flags & DIR_SHOW_IGNORED) &&
|
||||
!path_excluded(&check, ce))
|
||||
continue;
|
||||
if (show_unmerged && !ce_stage(ce))
|
||||
continue;
|
||||
@ -232,9 +235,8 @@ static void show_files(struct dir_struct *dir)
|
||||
struct cache_entry *ce = active_cache[i];
|
||||
struct stat st;
|
||||
int err;
|
||||
int dtype = ce_to_dtype(ce);
|
||||
if (dir->flags & DIR_SHOW_IGNORED &&
|
||||
!excluded(dir, ce->name, &dtype))
|
||||
if ((dir->flags & DIR_SHOW_IGNORED) &&
|
||||
!path_excluded(&check, ce))
|
||||
continue;
|
||||
if (ce->ce_flags & CE_UPDATE)
|
||||
continue;
|
||||
@ -247,6 +249,9 @@ static void show_files(struct dir_struct *dir)
|
||||
show_ce_entry(tag_modified, ce);
|
||||
}
|
||||
}
|
||||
|
||||
if ((dir->flags & DIR_SHOW_IGNORED))
|
||||
path_exclude_check_clear(&check);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user