Added a check for stash before executing git stash list for performance #158
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
I noticed that when in Git repositories the prompt would delay for roughly a half a second before returning.
Running WSL1 on the Windows 1909 release, other version details:
Also somewhat discussed in issue #129 - Latency
Investigation
I walked
segment-git.go
and tried out the commands it would issue. That is where I found thatgit stash list
takes considerably longer.Diving into the source for Git (for the 2.17 release) I found that git stash would call a shell script that added overhead. I also found the script provides a quick method to check if a stash existed, see https://github.com/git/git/blob/6e9e91e9cae74cd7feb9300563d40361b2b17dd2/git-stash.sh#L379
Changes
I simply added the check for a stash. The command raises an error if there is no stash.
This also means that if a stash exists, performance will regress