Skip to content

Commit

Permalink
Merge pull request #289 from scop/git-stash-stats
Browse files Browse the repository at this point in the history
Avoid a git rev-list if stash stats are disabled
  • Loading branch information
justjanne authored Feb 27, 2021
2 parents f4d042c + 6e3dd8c commit 27899e1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions segment-git.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,14 @@ func segmentGit(p *powerline) []pwl.Segment {
background = p.theme.RepoCleanBg
}

out, err = runGitCommand("git", "rev-list", "-g", "refs/stash")
if err == nil && len(out) > 0 {
stats.stashed = strings.Count(out, "\n")
}

segments := []pwl.Segment{{
Name: "git-branch",
Content: branch,
Foreground: foreground,
Background: background,
}}

stashEnabled := true
for _, stat := range p.cfg.GitDisableStats {
// "ahead, behind, staged, notStaged, untracked, conflicted, stashed"
switch stat {
Expand All @@ -254,6 +250,14 @@ func segmentGit(p *powerline) []pwl.Segment {
stats.conflicted = 0
case "stashed":
stats.stashed = 0
stashEnabled = false
}
}

if stashEnabled {
out, err = runGitCommand("git", "rev-list", "-g", "refs/stash")
if err == nil {
stats.stashed = strings.Count(out, "\n")
}
}

Expand Down

0 comments on commit 27899e1

Please sign in to comment.