[git completions] Speed up branch completion

Using `git for-each-ref` both simplifies the code (no need to deal
with detached heads anymore) and speeds it up.

With 1600 branches, the time goes from ~48ms to ~16ms.
This commit is contained in:
Fabian Homborg 2018-04-25 23:04:45 +02:00
parent 0b0e65a8a4
commit f3f2d2d191

View file

@ -17,12 +17,11 @@ function __fish_git_recent_commits
end
function __fish_git_branches
command git branch --no-color -a $argv 2>/dev/null \
# Filter out detached heads and such ("(HEAD detached at SOMESHA)", localized).
| string match -v '\* (*)' | string match -r -v ' -> ' | string trim -c "* " \
# We assume anything that's not remote is a local branch.
| string replace -r '^(?!remotes/)(.*)' '$1\tLocal Branch' \
| string replace -r "^remotes/(.*)" '$1\tRemote Branch'
# This is much faster than using `git branch`,
# and avoids having to deal with localized "detached HEAD" messages.
command git for-each-ref --format='%(refname)' refs/heads/ refs/remotes/ \
| string replace -r '^refs/heads/(.*)$' '$1\tLocal Branch' \
| string replace -r '^refs/remotes/(.*)$' '$1\tRemote Branch'
end
function __fish_git_tags