Skip to content

Commit 0f1f455

Browse files
committed
Make Commit.Parents a getter for an unexported parents field
This is exactly the same as what we did for Hash earlier. And for the same reason: we want to turn the parents field into a slice of pointers.
1 parent e27bc15 commit 0f1f455

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

pkg/commands/models/commit.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type Commit struct {
5454
Divergence Divergence // set to DivergenceNone unless we are showing the divergence view
5555

5656
// Hashes of parent commits (will be multiple if it's a merge commit)
57-
Parents []string
57+
parents []string
5858
}
5959

6060
type NewCommitOpts struct {
@@ -83,7 +83,7 @@ func NewCommit(hashPool *utils.StringPool, opts NewCommitOpts) *Commit {
8383
AuthorEmail: opts.AuthorEmail,
8484
UnixTimestamp: opts.UnixTimestamp,
8585
Divergence: opts.Divergence,
86-
Parents: opts.Parents,
86+
parents: opts.Parents,
8787
}
8888
}
8989

@@ -114,8 +114,12 @@ func (c *Commit) ParentRefName() string {
114114
return c.RefName() + "^"
115115
}
116116

117+
func (c *Commit) Parents() []string {
118+
return c.parents
119+
}
120+
117121
func (c *Commit) IsFirstCommit() bool {
118-
return len(c.Parents) == 0
122+
return len(c.parents) == 0
119123
}
120124

121125
func (c *Commit) ID() string {
@@ -127,7 +131,7 @@ func (c *Commit) Description() string {
127131
}
128132

129133
func (c *Commit) IsMerge() bool {
130-
return len(c.Parents) > 1
134+
return len(c.parents) > 1
131135
}
132136

133137
// returns true if this commit is not actually in the git log but instead

pkg/gui/presentation/graph/graph.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
116116
return pipe.kind != TERMINATES
117117
})
118118

119-
newPipes := make([]*Pipe, 0, len(currentPipes)+len(commit.Parents))
119+
newPipes := make([]*Pipe, 0, len(currentPipes)+len(commit.Parents()))
120120
// start by assuming that we've got a brand new commit not related to any preceding commit.
121121
// (this only happens when we're doing `git log --all`). These will be tacked onto the far end.
122122
pos := maxPos + 1
@@ -137,7 +137,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
137137
if commit.IsFirstCommit() {
138138
toHash = models.EmptyTreeCommitHash
139139
} else {
140-
toHash = commit.Parents[0]
140+
toHash = commit.Parents()[0]
141141
}
142142
newPipes = append(newPipes, &Pipe{
143143
fromPos: pos,
@@ -216,7 +216,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
216216
}
217217

218218
if commit.IsMerge() {
219-
for _, parent := range commit.Parents[1:] {
219+
for _, parent := range commit.Parents()[1:] {
220220
availablePos := getNextAvailablePosForNewPipe()
221221
// need to act as if continuing pipes are going to continue on the same line.
222222
newPipes = append(newPipes, &Pipe{

pkg/gui/presentation/graph/graph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func generateCommits(count int) []*models.Commit {
576576
// I need to pick a random number of parents to add
577577
parentCount := rnd.Intn(2) + 1
578578

579-
parentHashes := currentCommit.Parents
579+
parentHashes := currentCommit.Parents()
580580
for j := 0; j < parentCount; j++ {
581581
reuseParent := rnd.Intn(6) != 1 && j <= len(pool)-1 && j != 0
582582
var newParent *models.Commit

pkg/gui/services/custom_commands/session_state_loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func commitShimFromModelCommit(commit *models.Commit) *Commit {
3737
AuthorEmail: commit.AuthorEmail,
3838
UnixTimestamp: commit.UnixTimestamp,
3939
Divergence: commit.Divergence,
40-
Parents: commit.Parents,
40+
Parents: commit.Parents(),
4141
}
4242
}
4343

0 commit comments

Comments
 (0)