summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Clemens Buchacher <drizzd@gmx.net>2018-04-04 09:46:58 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-04-10 16:00:53 +0900
commit78a2d2123103f4524bfce30511e0a8b2d27d3502 (patch)
treeccd046b72f49c85bb3c6a19290fdeee0bd07fd98
parentGit 2.17 (diff)
downloadtgif-78a2d2123103f4524bfce30511e0a8b2d27d3502.tar.xz
completion: improve ls-files filter performance
From the output of ls-files, we remove all but the leftmost path component and then we eliminate duplicates. We do this in a while loop, which is a performance bottleneck when the number of iterations is large (e.g. for 60000 files in linux.git). $ COMP_WORDS=(git status -- ar) COMP_CWORD=3; time _git real 0m11.876s user 0m4.685s sys 0m6.808s Replacing the loop with the cut command improves performance significantly: $ COMP_WORDS=(git status -- ar) COMP_CWORD=3; time _git real 0m1.372s user 0m0.263s sys 0m0.167s The measurements were done with Msys2 bash, which is used by Git for Windows. When filtering the ls-files output we take care not to touch absolute paths. This is redundant, because ls-files will never output absolute paths. Remove the unnecessary operations. The issue was reported here: https://github.com/git-for-windows/git/issues/1533 Signed-off-by: Clemens Buchacher <drizzd@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--contrib/completion/git-completion.bash7
1 files changed, 1 insertions, 6 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b09c8a2362..f69cb5cdff 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -388,12 +388,7 @@ __git_index_files ()
local root="${2-.}" file
__git_ls_files_helper "$root" "$1" |
- while read -r file; do
- case "$file" in
- ?*/*) echo "${file%%/*}" ;;
- *) echo "$file" ;;
- esac
- done | sort | uniq
+ cut -f1 -d/ | sort | uniq
}
# Lists branches from the local repository.