aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/__fish_git_prompt.fish
diff options
context:
space:
mode:
authorGravatar Brian Gernhardt <brian@gernhardtsoftware.com>2013-07-03 01:29:16 -0400
committerGravatar Brian Gernhardt <brian@gernhardtsoftware.com>2013-07-26 22:05:07 -0400
commitd534b0ba81f81ef23868878fdfa822f1bcee91b2 (patch)
tree3351974dd146e2c59cefa88c43e136b662bc9e16 /share/functions/__fish_git_prompt.fish
parent87a0363ba7d2011842cec12e3144548219b2e7e1 (diff)
git_prompt: Call `git rev-parse` less often
The code invoked `git rev-parse` several times when the required information could be collected all at once. This is based on the following commits from git.git: efaa0c1: bash prompt: combine 'git rev-parse' executions in the main code path e3e0b93: bash prompt: combine 'git rev-parse' for detached head 0f37c12: bash prompt: use bash builtins to check for unborn branch for dirty state dd0b72c: bash prompt: use bash builtins to check stash state
Diffstat (limited to 'share/functions/__fish_git_prompt.fish')
-rw-r--r--share/functions/__fish_git_prompt.fish45
1 files changed, 32 insertions, 13 deletions
diff --git a/share/functions/__fish_git_prompt.fish b/share/functions/__fish_git_prompt.fish
index 948135cf..2a44765c 100644
--- a/share/functions/__fish_git_prompt.fish
+++ b/share/functions/__fish_git_prompt.fish
@@ -281,11 +281,19 @@ function __fish_git_prompt_show_upstream --description "Helper function for __fi
end
function __fish_git_prompt --description "Prompt function for Git"
- set -l git_dir (git rev-parse --git-dir ^/dev/null)
+ set -l repo_info (git rev-parse --git-dir --is-inside-git-dir --is-bare-repository --is-inside-work-tree --short HEAD ^/dev/null)
+ test -n "$repo_info"; or return
- test -n "$git_dir"; or return
+ set -l git_dir $repo_info[1]
+ set -l inside_gitdir $repo_info[2]
+ set -l bare_repo $repo_info[3]
+ set -l inside_worktree $repo_info[4]
+ set -l short_sha
+ if test (count $repo_info) = 5
+ set short_sha $repo_info[5]
+ end
- set -l rbc (__fish_git_prompt_operation_branch_bare $git_dir)
+ set -l rbc (__fish_git_prompt_operation_branch_bare $repo_info)
set -l r $rbc[1] # current operation
set -l b $rbc[2] # current branch
set -l detached $rbc[3]
@@ -299,7 +307,7 @@ function __fish_git_prompt --description "Prompt function for Git"
__fish_git_prompt_validate_chars
- if test "true" = (git rev-parse --is-inside-work-tree ^/dev/null)
+ if test "true" = $inside_worktree
if test -n "$__fish_git_prompt_show_informative_status"
set informative_status "|"(__fish_git_prompt_informative_status)
else
@@ -307,12 +315,12 @@ function __fish_git_prompt --description "Prompt function for Git"
set -l config (git config --bool bash.showDirtyState)
if test "$config" != "false"
set w (__fish_git_prompt_dirty)
- set i (__fish_git_prompt_staged)
+ set i (__fish_git_prompt_staged $short_sha)
end
end
- if test -n "$__fish_git_prompt_showstashstate"
- git rev-parse --verify refs/stash >/dev/null ^&1; and set s $___fish_git_prompt_char_stashstate
+ if test -n "$__fish_git_prompt_showstashstate" -a -r $git_dir/refs/stash
+ set s $___fish_git_prompt_char_stashstate
end
if test -n "$__fish_git_prompt_showuntrackedfiles"
@@ -384,9 +392,11 @@ end
### helper functions
function __fish_git_prompt_staged --description "__fish_git_prompt helper, tells whether or not the current branch has staged files"
+ set -l short_sha $argv[1]
+
set -l staged
- if git rev-parse --quiet --verify HEAD >/dev/null
+ if test -n "$short_sha"
git diff-index --cached --quiet HEAD --; or set staged $___fish_git_prompt_char_stagedstate
else
set staged $___fish_git_prompt_char_invalidstate
@@ -448,7 +458,15 @@ end
# Keeping these together avoids many duplicated checks
function __fish_git_prompt_operation_branch_bare --description "__fish_git_prompt helper, returns the current Git operation and branch"
- set -l git_dir $argv[1]
+ # This function is passed the full repo_info array
+ set -l git_dir $argv[1]
+ set -l inside_gitdir $argv[2]
+ set -l bare_repo $argv[3]
+ set -l short_sha
+ if test (count $argv) = 5
+ set short_sha $argv[5]
+ end
+
set -l branch
set -l operation
set -l detached no
@@ -508,8 +526,9 @@ function __fish_git_prompt_operation_branch_bare --description "__fish_git_promp
git describe --tags --exact-match HEAD
end ^/dev/null; set os $status)
if test $os -ne 0
- set branch (git rev-parse --short HEAD ^/dev/null; set os $status)...
- if test $os -ne 0
+ if test -n "$short_sha"
+ set branch $short_sha...
+ else
set branch unknown
end
end
@@ -517,8 +536,8 @@ function __fish_git_prompt_operation_branch_bare --description "__fish_git_promp
end
end
- if test "true" = (git rev-parse --is-inside-git-dir ^/dev/null)
- if test "true" = (git rev-parse --is-bare-repository ^/dev/null)
+ if test "true" = $inside_gitdir
+ if test "true" = $bare_repo
set bare "BARE:"
else
# Let user know they're inside the git dir of a non-bare repo