From 28fe8a5f18a33a5d87c30f7bbdd10087a234b16f Mon Sep 17 00:00:00 2001 From: "Duc Hoa, Nguyen" Date: Fri, 6 Sep 2019 16:34:14 +0800 Subject: [PATCH 1/2] Speed up git dirty Idea and implementation is from https://github.com/oh-my-fish/oh-my-fish/pull/706 Modified to ignore submodules git commands that can exit early. In large repos, this can be faster by a factor of 15 or so. --- functions/_pure_prompt_git_dirty.fish | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/functions/_pure_prompt_git_dirty.fish b/functions/_pure_prompt_git_dirty.fish index 247d7453..e19da74e 100644 --- a/functions/_pure_prompt_git_dirty.fish +++ b/functions/_pure_prompt_git_dirty.fish @@ -2,7 +2,10 @@ function _pure_prompt_git_dirty set --local git_dirty_symbol set --local git_dirty_color - set --local is_git_dirty (command git status --porcelain --ignore-submodules 2>/dev/null) + set --local is_git_dirty ( + not command git diff-index --ignore-submodules --cached --quiet HEAD -- >/dev/null 2>&1 + or not command git diff --ignore-submodules --no-ext-diff --quiet --exit-code >/dev/null 2>&1 + ) if test -n "$is_git_dirty" # untracked or un-commited files set git_dirty_symbol "$pure_symbol_git_dirty" set git_dirty_color "$pure_color_git_dirty" From d6031652c911568a803a4984e370f5f651cdb5ef Mon Sep 17 00:00:00 2001 From: "Duc Hoa, Nguyen" Date: Fri, 6 Sep 2019 17:37:50 +0800 Subject: [PATCH 2/2] Fix conditions for prompt git dirty --- functions/_pure_prompt_git_dirty.fish | 3 +++ 1 file changed, 3 insertions(+) diff --git a/functions/_pure_prompt_git_dirty.fish b/functions/_pure_prompt_git_dirty.fish index e19da74e..a134ed8b 100644 --- a/functions/_pure_prompt_git_dirty.fish +++ b/functions/_pure_prompt_git_dirty.fish @@ -3,8 +3,11 @@ function _pure_prompt_git_dirty set --local git_dirty_color set --local is_git_dirty ( + # The first checks for staged changes, the second for unstaged ones. + # We put them in this order because checking staged changes is *fast*. not command git diff-index --ignore-submodules --cached --quiet HEAD -- >/dev/null 2>&1 or not command git diff --ignore-submodules --no-ext-diff --quiet --exit-code >/dev/null 2>&1 + and echo "true" ) if test -n "$is_git_dirty" # untracked or un-commited files set git_dirty_symbol "$pure_symbol_git_dirty"