Skip to content

Commit b438e07

Browse files
committed
fixup! Store fromHash/toHash in Pipe struct as pointers
1 parent a2d9ddd commit b438e07

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

pkg/gui/context/local_commits_context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
3232
)
3333

3434
getDisplayStrings := func(startIdx int, endIdx int) [][]string {
35-
var selectedCommitHash *string
35+
var selectedCommitHashPtr *string
3636

3737
if c.Context().Current().GetKey() == LOCAL_COMMITS_CONTEXT_KEY {
3838
selectedCommit := viewModel.GetSelected()
3939
if selectedCommit != nil {
40-
selectedCommitHash = selectedCommit.HashPtr()
40+
selectedCommitHashPtr = selectedCommit.HashPtr()
4141
}
4242
}
4343

@@ -57,7 +57,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
5757
c.UserConfig().Gui.ShortTimeFormat,
5858
time.Now(),
5959
c.UserConfig().Git.ParseEmoji,
60-
selectedCommitHash,
60+
selectedCommitHashPtr,
6161
startIdx,
6262
endIdx,
6363
shouldShowGraph(c),

pkg/gui/context/sub_commits_context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ func NewSubCommitsContext(
4646
return [][]string{}
4747
}
4848

49-
var selectedCommitHash *string
49+
var selectedCommitHashPtr *string
5050
if c.Context().Current().GetKey() == SUB_COMMITS_CONTEXT_KEY {
5151
selectedCommit := viewModel.GetSelected()
5252
if selectedCommit != nil {
53-
selectedCommitHash = selectedCommit.HashPtr()
53+
selectedCommitHashPtr = selectedCommit.HashPtr()
5454
}
5555
}
5656
branches := []*models.Branch{}
@@ -72,7 +72,7 @@ func NewSubCommitsContext(
7272
c.UserConfig().Gui.ShortTimeFormat,
7373
time.Now(),
7474
c.UserConfig().Git.ParseEmoji,
75-
selectedCommitHash,
75+
selectedCommitHashPtr,
7676
startIdx,
7777
endIdx,
7878
shouldShowGraph(c),

pkg/gui/presentation/commits.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func GetCommitListDisplayStrings(
5151
shortTimeFormat string,
5252
now time.Time,
5353
parseEmoji bool,
54-
selectedCommitHash *string,
54+
selectedCommitHashPtr *string,
5555
startIdx int,
5656
endIdx int,
5757
showGraph bool,
@@ -102,7 +102,7 @@ func GetCommitListDisplayStrings(
102102
graphLines := graph.RenderAux(
103103
graphPipeSets,
104104
graphCommits,
105-
selectedCommitHash,
105+
selectedCommitHashPtr,
106106
)
107107
allGraphLines = append(allGraphLines, graphLines...)
108108
}
@@ -119,7 +119,7 @@ func GetCommitListDisplayStrings(
119119
graphLines := graph.RenderAux(
120120
graphPipeSets,
121121
graphCommits,
122-
selectedCommitHash,
122+
selectedCommitHashPtr,
123123
)
124124
allGraphLines = append(allGraphLines, graphLines...)
125125
}
@@ -140,7 +140,7 @@ func GetCommitListDisplayStrings(
140140
graphLines := graph.RenderAux(
141141
graphPipeSets,
142142
graphCommits,
143-
selectedCommitHash,
143+
selectedCommitHashPtr,
144144
)
145145
getGraphLine = func(idx int) string {
146146
if idx >= graphOffset {

pkg/gui/presentation/commits_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
3636
shortTimeFormat string
3737
now time.Time
3838
parseEmoji bool
39-
selectedCommitHash *string
39+
selectedCommitHashPtr *string
4040
startIdx int
4141
endIdx int
4242
showGraph bool
@@ -563,7 +563,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
563563
s.shortTimeFormat,
564564
s.now,
565565
s.parseEmoji,
566-
s.selectedCommitHash,
566+
s.selectedCommitHashPtr,
567567
s.startIdx,
568568
s.endIdx,
569569
s.showGraph,

pkg/gui/presentation/graph/graph.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ func (self Pipe) right() int {
4545
return max(self.fromPos, self.toPos)
4646
}
4747

48-
func RenderCommitGraph(commits []*models.Commit, selectedCommitHash *string, getStyle func(c *models.Commit) style.TextStyle) []string {
48+
func RenderCommitGraph(commits []*models.Commit, selectedCommitHashPtr *string, getStyle func(c *models.Commit) style.TextStyle) []string {
4949
pipeSets := GetPipeSets(commits, getStyle)
5050
if len(pipeSets) == 0 {
5151
return nil
5252
}
5353

54-
lines := RenderAux(pipeSets, commits, selectedCommitHash)
54+
lines := RenderAux(pipeSets, commits, selectedCommitHashPtr)
5555

5656
return lines
5757
}
@@ -69,7 +69,7 @@ func GetPipeSets(commits []*models.Commit, getStyle func(c *models.Commit) style
6969
})
7070
}
7171

72-
func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitHash *string) []string {
72+
func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitHashPtr *string) []string {
7373
maxProcs := runtime.GOMAXPROCS(0)
7474

7575
// splitting up the rendering of the graph into multiple goroutines allows us to render the graph in parallel
@@ -93,7 +93,7 @@ func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitHash
9393
if k > 0 {
9494
prevCommit = commits[k-1]
9595
}
96-
line := renderPipeSet(pipeSet, selectedCommitHash, prevCommit)
96+
line := renderPipeSet(pipeSet, selectedCommitHashPtr, prevCommit)
9797
innerLines = append(innerLines, line)
9898
}
9999
chunks[i] = innerLines
@@ -272,7 +272,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
272272

273273
func renderPipeSet(
274274
pipes []*Pipe,
275-
selectedCommitHash *string,
275+
selectedCommitHashPtr *string,
276276
prevCommit *models.Commit,
277277
) string {
278278
maxPos := 0
@@ -319,10 +319,10 @@ func renderPipeSet(
319319
// we don't want to highlight two commits if they're contiguous. We only want
320320
// to highlight multiple things if there's an actual visible pipe involved.
321321
highlight := true
322-
if prevCommit != nil && equalHashes(prevCommit.HashPtr(), selectedCommitHash) {
322+
if prevCommit != nil && equalHashes(prevCommit.HashPtr(), selectedCommitHashPtr) {
323323
highlight = false
324324
for _, pipe := range pipes {
325-
if equalHashes(pipe.fromHash, selectedCommitHash) && (pipe.kind != TERMINATES || pipe.fromPos != pipe.toPos) {
325+
if equalHashes(pipe.fromHash, selectedCommitHashPtr) && (pipe.kind != TERMINATES || pipe.fromPos != pipe.toPos) {
326326
highlight = true
327327
}
328328
}
@@ -331,7 +331,7 @@ func renderPipeSet(
331331
// so we have our commit pos again, now it's time to build the cells.
332332
// we'll handle the one that's sourced from our selected commit last so that it can override the other cells.
333333
selectedPipes, nonSelectedPipes := utils.Partition(pipes, func(pipe *Pipe) bool {
334-
return highlight && equalHashes(pipe.fromHash, selectedCommitHash)
334+
return highlight && equalHashes(pipe.fromHash, selectedCommitHashPtr)
335335
})
336336

337337
for _, pipe := range nonSelectedPipes {
@@ -375,7 +375,7 @@ func renderPipeSet(
375375
}
376376

377377
func equalHashes(a, b *string) bool {
378-
// if our selectedCommitHash is nil, there is no selected commit
378+
// if our selectedCommitHashPtr is nil, there is no selected commit
379379
if a == nil || b == nil {
380380
return false
381381
}

0 commit comments

Comments
 (0)