Skip to content

Commit ea95c7b

Browse files
szedergitster
authored andcommitted
completion: improve untracked directory filtering for filename completion
Similar to Bash's default filename completion, our git-aware filename completion stops at directory boundaries, i.e. it doesn't offer the full 'path/to/file' at first, but only 'path/'. To achieve that the completion script runs 'git ls-files' with specific command line options to get the list of relevant paths under the current directory, and then processes each path to strip all but the base directory or filename (see __git_index_files()). To offer only modified and untracked files for 'git add' the completion script runs 'git ls-files --exclude-standard --others --modified'. This command lists all non-ignored files in untracked directories, which leads to a noticeable delay caused by the processing mentioned above if there are a lot of such files (__git_index_files() specifies '--exclude-standard' internally): $ mkdir untracked-dir $ for i in {1..10000} ; do >untracked-dir/$i ; done $ time __git_index_files "--others --modified" untracked-dir real 0m0.537s user 0m0.452s sys 0m0.160s Eliminate this delay by additionally passing the '--directory --no-empty-directory' options to 'git ls-files' to show only the directory name of non-empty untracked directories instead their whole content: $ time __git_index_files "--others --modified --directory --no-empty-directory" untracked-dir real 0m0.029s user 0m0.020s sys 0m0.004s Filename completion for 'git clean' suffers from the same delay, as it offers untracked files, too. The fix could be the same, but since it actually makes sense to 'git clean' empty directories, in this case we only pass the '--directory' option to 'git ls-files'. Reported-by: Isaac Levy <[email protected]> Signed-off-by: SZEDER Gábor <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8d83871 commit ea95c7b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

contrib/completion/git-completion.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ _git_add ()
901901
esac
902902

903903
# XXX should we check for --update and --all options ?
904-
__git_complete_index_file "--others --modified"
904+
__git_complete_index_file "--others --modified --directory --no-empty-directory"
905905
}
906906

907907
_git_archive ()
@@ -1063,7 +1063,7 @@ _git_clean ()
10631063
esac
10641064

10651065
# XXX should we check for -x option ?
1066-
__git_complete_index_file "--others"
1066+
__git_complete_index_file "--others --directory"
10671067
}
10681068

10691069
_git_clone ()

0 commit comments

Comments
 (0)