chris-marsh / pureline

A Pure Bash Powerline PS1 Command Prompt
MIT License
507 stars 95 forks source link

Git Segment - too many external calls to the git command #55

Closed chris-marsh closed 3 years ago

chris-marsh commented 3 years ago

Need to improve the performance of the git segment.

git_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
number_stash=$(git stash list 2>/dev/null
number_behind_ahead=$(git rev-list --count --left-right '@{upstream}...HEAD')
number_staged=$(git diff --staged --name-only --diff-filter=AM)
number_conflicts=$(git diff --name-only --diff-filter=U)
number_modified=$(git diff --name-only --diff-filter=M)
number_untracked=$(git ls-files --other --exclude-standard)
git status --porcelain # to determine dirty status

8 calls to git (plus wc and tr for those calls). Most of this could be reduced to a single call to git status ---porcelain --branch and parsing the result.

chris-marsh commented 3 years ago

Mostly resolved in dev branch commit https://github.com/chris-marsh/pureline/commit/74cc57bdb488d091c0f46719b08219bb2a259628.

This reduces git calls to 3 and much improves performance.

chris-marsh commented 3 years ago

Commit https://github.com/chris-marsh/pureline/commit/baf76dff37136649be63429be99c00c2ee30125b removes grep and tr from git stash list. Not much difference in performance since still making a git call, but it feels right using a bash loop to count the result.

chris-marsh commented 3 years ago

Reduced from initial 8 calls to 3;

branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
while...done <<< "$(git status -b --porcelain 2> /dev/null)"
while...done <<< "$(git stash list 2> /dev/null)"

Good enough for now.