Skip to content

Commit 400a755

Browse files
szedergitster
authored andcommitted
completion: let 'for-each-ref' sort remote branches for 'checkout' DWIMery
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.060s After: real 0m1.550s user 0m1.512s sys 0m0.060s On Windows, before: real 0m3.128s user 0m2.155s sys 0m0.183s After: real 0m2.781s user 0m1.826s sys 0m0.136s Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 824388d commit 400a755

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

contrib/completion/git-completion.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,9 @@ __git_refs ()
423423
# Try to find a remote branch that matches the completion word
424424
# but only output if the branch name is unique
425425
__git for-each-ref --format="%(refname:strip=3)" \
426+
--sort="refname:strip=3" \
426427
"refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
427-
sort | uniq -u
428+
uniq -u
428429
fi
429430
return
430431
fi

0 commit comments

Comments
 (0)