diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-26 15:42:06 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-26 16:52:20 +1100 |
commit | 5e9cfab2835c19994ba35413fc57bdcd9e11bfcc (patch) | |
tree | 3ad10446ebe6eb2e0cf890ec1d325c1e4c0a3ac9 | |
parent | ca7cfc32322f016a430ecbf87e3e638d1a02cfc1 (diff) |
better rendering of bisect markets in commits panel
-rw-r--r-- | pkg/gui/list_context.go | 2 | ||||
-rw-r--r-- | pkg/gui/presentation/commits.go | 62 |
2 files changed, 43 insertions, 21 deletions
diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index 445b0f3d0..9f0d86372 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -77,7 +77,7 @@ func (self *ListContext) FocusLine() { view.FocusPoint(view.OriginX(), self.GetPanelState().GetSelectedLineIdx()) if self.RenderSelection { _, originY := view.Origin() - displayStrings := self.GetDisplayStrings(originY, view.InnerHeight()) + displayStrings := self.GetDisplayStrings(originY, view.InnerHeight()+1) self.Gui.renderDisplayStringsAtPos(view, originY, displayStrings) } view.Footer = formatListFooter(self.GetPanelState().GetSelectedLineIdx(), self.GetItemsLength()) diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index 99ab96750..59feaba78 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -22,13 +22,10 @@ type pipeSetCacheKey struct { var pipeSetCache = make(map[pipeSetCacheKey][][]*graph.Pipe) var mutex sync.Mutex -type BisectProgress int - -const ( - BeforeNewCommit BisectProgress = iota - InbetweenCommits - AfterOldCommit -) +type bisectBounds struct { + newIndex int + oldIndex int +} func GetCommitListDisplayStrings( commits []*models.Commit, @@ -60,6 +57,8 @@ func GetCommitListDisplayStrings( filteredCommits := commits[startIdx:end] + bisectBounds := getbisectBounds(commits, bisectInfo) + // function expects to be passed the index of the commit in terms of the `commits` slice var getGraphLine func(int) string if showGraph { @@ -88,16 +87,16 @@ func GetCommitListDisplayStrings( } lines := make([][]string, 0, len(filteredCommits)) - bisectProgress := BeforeNewCommit var bisectStatus BisectStatus for i, commit := range filteredCommits { - bisectStatus, bisectProgress = getBisectStatus(commit.Sha, bisectInfo, bisectProgress) + unfilteredIdx := i + startIdx + bisectStatus = getBisectStatus(unfilteredIdx, commit.Sha, bisectInfo, bisectBounds) lines = append(lines, displayCommit( commit, cherryPickedCommitShaMap, diffName, parseEmoji, - getGraphLine(i+startIdx), + getGraphLine(unfilteredIdx), fullDescription, bisectStatus, bisectInfo, @@ -106,6 +105,29 @@ func GetCommitListDisplayStrings( return lines } +func getbisectBounds(commits []*models.Commit, bisectInfo *git_commands.BisectInfo) *bisectBounds { + if !bisectInfo.Bisecting() { + return nil + } + + bisectBounds := &bisectBounds{} + + for i, commit := range commits { + if commit.Sha == bisectInfo.GetNewSha() { + bisectBounds.newIndex = i + } + + status, ok := bisectInfo.Status(commit.Sha) + if ok && status == git_commands.BisectStatusOld { + bisectBounds.oldIndex = i + return bisectBounds + } + } + + // shouldn't land here + return nil +} + // precondition: slice is not empty func indexOfFirstNonTODOCommit(commits []*models.Commit) int { for i, commit := range commits { @@ -155,35 +177,35 @@ const ( BisectStatusCurrent ) -func getBisectStatus(commitSha string, bisectInfo *git_commands.BisectInfo, bisectProgress BisectProgress) (BisectStatus, BisectProgress) { +func getBisectStatus(index int, commitSha string, bisectInfo *git_commands.BisectInfo, bisectBounds *bisectBounds) BisectStatus { if !bisectInfo.Started() { - return BisectStatusNone, bisectProgress + return BisectStatusNone } if bisectInfo.GetCurrentSha() == commitSha { - return BisectStatusCurrent, bisectProgress + return BisectStatusCurrent } status, ok := bisectInfo.Status(commitSha) if ok { switch status { case git_commands.BisectStatusNew: - return BisectStatusNew, InbetweenCommits + return BisectStatusNew case git_commands.BisectStatusOld: - return BisectStatusOld, AfterOldCommit + return BisectStatusOld case git_commands.BisectStatusSkipped: - return BisectStatusSkipped, bisectProgress + return BisectStatusSkipped } } else { - if bisectProgress == InbetweenCommits && bisectInfo.Bisecting() { - return BisectStatusCandidate, bisectProgress + if bisectBounds != nil && index >= bisectBounds.newIndex && index <= bisectBounds.oldIndex { + return BisectStatusCandidate } else { - return BisectStatusNone, bisectProgress + return BisectStatusNone } } // should never land here - return BisectStatusNone, bisectProgress + return BisectStatusNone } func getBisectStatusText(bisectStatus BisectStatus, bisectInfo *git_commands.BisectInfo) string { |