[PATCH 10/12] completion: let 'for-each-ref' sort remote branches for 'checkout' DWIMery
- From
SZEDER Gábor <szeder.dev@gmail.com>
- Date
- Feb 3, 2017, 02:54 UTC
- Message-ID
- <20170203025405.8242-11-szeder.dev@gmail.com>
- In-Reply-To
- <20170203025405.8242-1-szeder.dev@gmail.com>
When listing unique remote branches for 'git checkout's tracking DWIMery, __git_refs() runs the classic '... |sort |uniq -u' pattern to filter out duplicate remote branches.
Let 'git for-each-ref' do the sorting, sparing the overhead of fork()+exec()ing 'sort' and a stage in the pipeline where potentially relatively large amount of data can be passed between two subsequent pipeline stages.
This speeds up refs completion for 'git checkout' a bit when a lot of remote branches match the current word to be completed. Listing a single local and 100k remote branches, all packed, best of five:
On Linux, before:
$ time __git_complete_refs --track
real 0m1.856s
user 0m1.816s
sys 0m0.060sAfter:
real 0m1.550s
user 0m1.512s
sys 0m0.060sOn Windows, before:
real 0m3.128s
user 0m2.155s
sys 0m0.183sAfter:
real 0m2.781s
user 0m1.826s
sys 0m0.136sSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com> --- contrib/completion/git-completion.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index e2c4794f3..9f5a6f44e 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -414,8 +414,9 @@ __git_refs () # Try to find a remote branch that matches the completion word # but only output if the branch name is unique __git for-each-ref --format="%(refname:strip=3)" \ + --sort="refname:strip=3" \ "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \ - sort | uniq -u + uniq -u fi return fi
-- 2.11.0.555.g967c1bcb3