From f3f2d2d191de65dd226681c8e8f8f1e7f44cd32c Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 25 Apr 2018 23:04:45 +0200 Subject: [PATCH] [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. --- share/completions/git.fish | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/share/completions/git.fish b/share/completions/git.fish index 368bc0655..5f0dcc653 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -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