Skip to content

Commit 6eacc39

Browse files
committed
Merge branch 'en/fill-directory-exponential'
The directory traversal code had redundant recursive calls which made its performance characteristics exponential with respect to the depth of the tree, which was corrected. * en/fill-directory-exponential: completion: fix 'git add' on paths under an untracked directory Fix error-prone fill_directory() API; make it only return matches dir: replace double pathspec matching with single in treat_directory() dir: include DIR_KEEP_UNTRACKED_CONTENTS handling in treat_directory() dir: replace exponential algorithm with a linear one dir: refactor treat_directory to clarify control flow dir: fix confusion based on variable tense dir: fix broken comment dir: consolidate treat_path() and treat_one_path() dir: fix simple typo in comment t3000: add more testcases testing a variety of ls-files issues t7063: more thorough status checking
2 parents 48eee46 + c0af173 commit 6eacc39

File tree

10 files changed

+437
-201
lines changed

10 files changed

+437
-201
lines changed

builtin/clean.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -983,12 +983,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
983983
if (!cache_name_is_other(ent->name, ent->len))
984984
continue;
985985

986-
if (pathspec.nr)
987-
matches = dir_path_match(&the_index, ent, &pathspec, 0, NULL);
988-
989-
if (pathspec.nr && !matches)
990-
continue;
991-
992986
if (lstat(ent->name, &st))
993987
die_errno("Cannot lstat '%s'", ent->name);
994988

builtin/grep.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,6 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
701701

702702
fill_directory(&dir, opt->repo->index, pathspec);
703703
for (i = 0; i < dir.nr; i++) {
704-
if (!dir_path_match(opt->repo->index, dir.entries[i], pathspec, 0, NULL))
705-
continue;
706704
hit |= grep_file(opt, dir.entries[i]->name);
707705
if (hit && opt->status_only)
708706
break;

builtin/ls-files.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ static void show_dir_entry(const struct index_state *istate,
128128
if (len > ent->len)
129129
die("git ls-files: internal error - directory entry not superset of prefix");
130130

131-
if (!dir_path_match(istate, ent, &pathspec, len, ps_matched))
132-
return;
131+
/* If ps_matches is non-NULL, figure out which pathspec(s) match. */
132+
if (ps_matched)
133+
dir_path_match(istate, ent, &pathspec, len, ps_matched);
133134

134135
fputs(tag, stdout);
135136
write_eolinfo(istate, NULL, ent->name);

builtin/stash.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -861,30 +861,23 @@ static int get_untracked_files(const struct pathspec *ps, int include_untracked,
861861
struct strbuf *untracked_files)
862862
{
863863
int i;
864-
int max_len;
865864
int found = 0;
866-
char *seen;
867865
struct dir_struct dir;
868866

869867
memset(&dir, 0, sizeof(dir));
870868
if (include_untracked != INCLUDE_ALL_FILES)
871869
setup_standard_excludes(&dir);
872870

873-
seen = xcalloc(ps->nr, 1);
874-
875-
max_len = fill_directory(&dir, the_repository->index, ps);
871+
fill_directory(&dir, the_repository->index, ps);
876872
for (i = 0; i < dir.nr; i++) {
877873
struct dir_entry *ent = dir.entries[i];
878-
if (dir_path_match(&the_index, ent, ps, max_len, seen)) {
879-
found++;
880-
strbuf_addstr(untracked_files, ent->name);
881-
/* NUL-terminate: will be fed to update-index -z */
882-
strbuf_addch(untracked_files, '\0');
883-
}
874+
found++;
875+
strbuf_addstr(untracked_files, ent->name);
876+
/* NUL-terminate: will be fed to update-index -z */
877+
strbuf_addch(untracked_files, '\0');
884878
free(ent);
885879
}
886880

887-
free(seen);
888881
free(dir.entries);
889882
free(dir.ignored);
890883
clear_directory(&dir);

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ __git_index_files ()
504504
{
505505
local root="$2" match="$3"
506506

507-
__git_ls_files_helper "$root" "$1" "$match" |
507+
__git_ls_files_helper "$root" "$1" "${match:-?}" |
508508
awk -F / -v pfx="${2//\\/\\\\}" '{
509509
paths[$1] = 1
510510
}

0 commit comments

Comments
 (0)