@@ -25,13 +25,17 @@ const (
2525type Pipe struct {
2626 fromPos int
2727 toPos int
28- fromHash string
29- toHash string
28+ fromHash * string
29+ toHash * string
3030 kind PipeKind
3131 style style.TextStyle
3232}
3333
34- var highlightStyle = style .FgLightWhite .SetBold ()
34+ var (
35+ highlightStyle = style .FgLightWhite .SetBold ()
36+ EmptyTreeCommitHash = models .EmptyTreeCommitHash
37+ StartCommitHash = "START"
38+ )
3539
3640func (self Pipe ) left () int {
3741 return min (self .fromPos , self .toPos )
@@ -41,13 +45,13 @@ func (self Pipe) right() int {
4145 return max (self .fromPos , self .toPos )
4246}
4347
44- 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 {
4549 pipeSets := GetPipeSets (commits , getStyle )
4650 if len (pipeSets ) == 0 {
4751 return nil
4852 }
4953
50- lines := RenderAux (pipeSets , commits , selectedCommitHash )
54+ lines := RenderAux (pipeSets , commits , selectedCommitHashPtr )
5155
5256 return lines
5357}
@@ -57,15 +61,15 @@ func GetPipeSets(commits []*models.Commit, getStyle func(c *models.Commit) style
5761 return nil
5862 }
5963
60- pipes := []* Pipe {{fromPos : 0 , toPos : 0 , fromHash : "START" , toHash : commits [0 ].Hash (), kind : STARTS , style : style .FgDefault }}
64+ pipes := []* Pipe {{fromPos : 0 , toPos : 0 , fromHash : & StartCommitHash , toHash : commits [0 ].HashPtr (), kind : STARTS , style : style .FgDefault }}
6165
6266 return lo .Map (commits , func (commit * models.Commit , _ int ) []* Pipe {
6367 pipes = getNextPipes (pipes , commit , getStyle )
6468 return pipes
6569 })
6670}
6771
68- func RenderAux (pipeSets [][]* Pipe , commits []* models.Commit , selectedCommitHash string ) []string {
72+ func RenderAux (pipeSets [][]* Pipe , commits []* models.Commit , selectedCommitHashPtr * string ) []string {
6973 maxProcs := runtime .GOMAXPROCS (0 )
7074
7175 // splitting up the rendering of the graph into multiple goroutines allows us to render the graph in parallel
@@ -89,7 +93,7 @@ func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitHash
8993 if k > 0 {
9094 prevCommit = commits [k - 1 ]
9195 }
92- line := renderPipeSet (pipeSet , selectedCommitHash , prevCommit )
96+ line := renderPipeSet (pipeSet , selectedCommitHashPtr , prevCommit )
9397 innerLines = append (innerLines , line )
9498 }
9599 chunks [i ] = innerLines
@@ -116,12 +120,12 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
116120 return pipe .kind != TERMINATES
117121 })
118122
119- newPipes := make ([]* Pipe , 0 , len (currentPipes )+ len (commit .Parents ()))
123+ newPipes := make ([]* Pipe , 0 , len (currentPipes )+ len (commit .ParentPtrs ()))
120124 // start by assuming that we've got a brand new commit not related to any preceding commit.
121125 // (this only happens when we're doing `git log --all`). These will be tacked onto the far end.
122126 pos := maxPos + 1
123127 for _ , pipe := range currentPipes {
124- if equalHashes (pipe .toHash , commit .Hash ()) {
128+ if equalHashes (pipe .toHash , commit .HashPtr ()) {
125129 // turns out this commit does have a descendant so we'll place it right under the first instance
126130 pos = pipe .toPos
127131 break
@@ -133,24 +137,24 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
133137 // a traversed spot is one where a current pipe is starting on, ending on, or passing through
134138 traversedSpots := set .New [int ]()
135139
136- var toHash string
140+ var toHash * string
137141 if commit .IsFirstCommit () {
138- toHash = models . EmptyTreeCommitHash
142+ toHash = & EmptyTreeCommitHash
139143 } else {
140- toHash = commit .Parents ()[0 ]
144+ toHash = commit .ParentPtrs ()[0 ]
141145 }
142146 newPipes = append (newPipes , & Pipe {
143147 fromPos : pos ,
144148 toPos : pos ,
145- fromHash : commit .Hash (),
149+ fromHash : commit .HashPtr (),
146150 toHash : toHash ,
147151 kind : STARTS ,
148152 style : getStyle (commit ),
149153 })
150154
151155 traversedSpotsForContinuingPipes := set .New [int ]()
152156 for _ , pipe := range currentPipes {
153- if ! equalHashes (pipe .toHash , commit .Hash ()) {
157+ if ! equalHashes (pipe .toHash , commit .HashPtr ()) {
154158 traversedSpotsForContinuingPipes .Add (pipe .toPos )
155159 }
156160 }
@@ -189,7 +193,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
189193 }
190194
191195 for _ , pipe := range currentPipes {
192- if equalHashes (pipe .toHash , commit .Hash ()) {
196+ if equalHashes (pipe .toHash , commit .HashPtr ()) {
193197 // terminating here
194198 newPipes = append (newPipes , & Pipe {
195199 fromPos : pipe .toPos ,
@@ -216,13 +220,13 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
216220 }
217221
218222 if commit .IsMerge () {
219- for _ , parent := range commit .Parents ()[1 :] {
223+ for _ , parent := range commit .ParentPtrs ()[1 :] {
220224 availablePos := getNextAvailablePosForNewPipe ()
221225 // need to act as if continuing pipes are going to continue on the same line.
222226 newPipes = append (newPipes , & Pipe {
223227 fromPos : pos ,
224228 toPos : availablePos ,
225- fromHash : commit .Hash (),
229+ fromHash : commit .HashPtr (),
226230 toHash : parent ,
227231 kind : STARTS ,
228232 style : getStyle (commit ),
@@ -233,7 +237,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
233237 }
234238
235239 for _ , pipe := range currentPipes {
236- if ! equalHashes (pipe .toHash , commit .Hash ()) && pipe .toPos > pos {
240+ if ! equalHashes (pipe .toHash , commit .HashPtr ()) && pipe .toPos > pos {
237241 // continuing on, potentially moving left to fill in a blank spot
238242 last := pipe .toPos
239243 for i := pipe .toPos ; i > pos ; i -- {
@@ -268,7 +272,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
268272
269273func renderPipeSet (
270274 pipes []* Pipe ,
271- selectedCommitHash string ,
275+ selectedCommitHashPtr * string ,
272276 prevCommit * models.Commit ,
273277) string {
274278 maxPos := 0
@@ -315,10 +319,10 @@ func renderPipeSet(
315319 // we don't want to highlight two commits if they're contiguous. We only want
316320 // to highlight multiple things if there's an actual visible pipe involved.
317321 highlight := true
318- if prevCommit != nil && equalHashes (prevCommit .Hash (), selectedCommitHash ) {
322+ if prevCommit != nil && equalHashes (prevCommit .HashPtr (), selectedCommitHashPtr ) {
319323 highlight = false
320324 for _ , pipe := range pipes {
321- 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 ) {
322326 highlight = true
323327 }
324328 }
@@ -327,7 +331,7 @@ func renderPipeSet(
327331 // so we have our commit pos again, now it's time to build the cells.
328332 // we'll handle the one that's sourced from our selected commit last so that it can override the other cells.
329333 selectedPipes , nonSelectedPipes := utils .Partition (pipes , func (pipe * Pipe ) bool {
330- return highlight && equalHashes (pipe .fromHash , selectedCommitHash )
334+ return highlight && equalHashes (pipe .fromHash , selectedCommitHashPtr )
331335 })
332336
333337 for _ , pipe := range nonSelectedPipes {
@@ -370,13 +374,13 @@ func renderPipeSet(
370374 return writer .String ()
371375}
372376
373- func equalHashes (a , b string ) bool {
374- // if our selectedCommitHash is an empty string we treat that as meaning there is no selected commit hash
375- if a == "" || b == "" {
377+ func equalHashes (a , b * string ) bool {
378+ // if our selectedCommitHashPtr is nil, there is no selected commit
379+ if a == nil || b == nil {
376380 return false
377381 }
378382
379- length := min (len (a ), len (b ))
383+ length := min (len (* a ), len (* b ))
380384 // parent hashes are only stored up to 20 characters for some reason so we'll truncate to that for comparison
381- return a [:length ] == b [:length ]
385+ return ( * a ) [:length ] == ( * b ) [:length ]
382386}
0 commit comments