Skip to content

Commit

Permalink
more lenient getting of short shas
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Mar 26, 2020
1 parent 569ec59 commit 37acc17
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions pkg/commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ type Commit struct {
Author string
Date string
}

func (c *Commit) ShortSha() string {
if len(c.Sha) < 8 {
return c.Sha
}
return c.Sha[:8]
}
2 changes: 1 addition & 1 deletion pkg/commands/commit_list_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *CommitListBuilder) GetCommits(limit bool) ([]*Commit, error) {
// now we can split it up and turn it into commits
for _, line := range utils.SplitLines(log) {
commit := c.extractCommitFromLine(line)
_, unpushed := unpushedCommits[commit.Sha[:8]]
_, unpushed := unpushedCommits[commit.ShortSha()]
commit.Status = map[bool]string{true: "unpushed", false: "pushed"}[unpushed]
commits = append(commits, commit)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/presentation/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func getFullDescriptionDisplayStringsForCommit(c *commands.Commit) []string {

truncatedAuthor := utils.TruncateWithEllipsis(c.Author, 17)

return []string{shaColor.Sprint(c.Sha[:8]), secondColumnString, yellow.Sprint(truncatedAuthor), tagString + defaultColor.Sprint(c.Name)}
return []string{shaColor.Sprint(c.ShortSha()), secondColumnString, yellow.Sprint(truncatedAuthor), tagString + defaultColor.Sprint(c.Name)}
}

func getDisplayStringsForCommit(c *commands.Commit) []string {
Expand Down Expand Up @@ -122,5 +122,5 @@ func getDisplayStringsForCommit(c *commands.Commit) []string {
tagString = utils.ColoredStringDirect(strings.Join(c.Tags, " "), tagColor) + " "
}

return []string{shaColor.Sprint(c.Sha[:8]), actionString + tagString + defaultColor.Sprint(c.Name)}
return []string{shaColor.Sprint(c.ShortSha()), actionString + tagString + defaultColor.Sprint(c.Name)}
}
4 changes: 2 additions & 2 deletions pkg/gui/presentation/reflog_commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func GetReflogCommitListDisplayStrings(commits []*commands.Commit, fullDescripti
func getFullDescriptionDisplayStringsForReflogCommit(c *commands.Commit) []string {
defaultColor := color.New(theme.DefaultTextColor)

return []string{utils.ColoredString(c.Sha[:8], color.FgBlue), utils.ColoredString(c.Date, color.FgMagenta), defaultColor.Sprint(c.Name)}
return []string{utils.ColoredString(c.ShortSha(), color.FgBlue), utils.ColoredString(c.Date, color.FgMagenta), defaultColor.Sprint(c.Name)}
}

func getDisplayStringsForReflogCommit(c *commands.Commit) []string {
defaultColor := color.New(theme.DefaultTextColor)

return []string{utils.ColoredString(c.Sha[:8], color.FgBlue), defaultColor.Sprint(c.Name)}
return []string{utils.ColoredString(c.ShortSha(), color.FgBlue), defaultColor.Sprint(c.Name)}
}

0 comments on commit 37acc17

Please sign in to comment.