mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
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.
This commit is contained in:
@ -54,7 +54,7 @@ type Commit struct {
|
|||||||
Divergence Divergence // set to DivergenceNone unless we are showing the divergence view
|
Divergence Divergence // set to DivergenceNone unless we are showing the divergence view
|
||||||
|
|
||||||
// Hashes of parent commits (will be multiple if it's a merge commit)
|
// Hashes of parent commits (will be multiple if it's a merge commit)
|
||||||
Parents []string
|
parents []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewCommitOpts struct {
|
type NewCommitOpts struct {
|
||||||
@ -83,7 +83,7 @@ func NewCommit(hashPool *utils.StringPool, opts NewCommitOpts) *Commit {
|
|||||||
AuthorEmail: opts.AuthorEmail,
|
AuthorEmail: opts.AuthorEmail,
|
||||||
UnixTimestamp: opts.UnixTimestamp,
|
UnixTimestamp: opts.UnixTimestamp,
|
||||||
Divergence: opts.Divergence,
|
Divergence: opts.Divergence,
|
||||||
Parents: opts.Parents,
|
parents: opts.Parents,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +114,12 @@ func (c *Commit) ParentRefName() string {
|
|||||||
return c.RefName() + "^"
|
return c.RefName() + "^"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Commit) Parents() []string {
|
||||||
|
return c.parents
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Commit) IsFirstCommit() bool {
|
func (c *Commit) IsFirstCommit() bool {
|
||||||
return len(c.Parents) == 0
|
return len(c.parents) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) ID() string {
|
func (c *Commit) ID() string {
|
||||||
@ -127,7 +131,7 @@ func (c *Commit) Description() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) IsMerge() bool {
|
func (c *Commit) IsMerge() bool {
|
||||||
return len(c.Parents) > 1
|
return len(c.parents) > 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if this commit is not actually in the git log but instead
|
// returns true if this commit is not actually in the git log but instead
|
||||||
|
@ -116,7 +116,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
|
|||||||
return pipe.kind != TERMINATES
|
return pipe.kind != TERMINATES
|
||||||
})
|
})
|
||||||
|
|
||||||
newPipes := make([]*Pipe, 0, len(currentPipes)+len(commit.Parents))
|
newPipes := make([]*Pipe, 0, len(currentPipes)+len(commit.Parents()))
|
||||||
// start by assuming that we've got a brand new commit not related to any preceding commit.
|
// start by assuming that we've got a brand new commit not related to any preceding commit.
|
||||||
// (this only happens when we're doing `git log --all`). These will be tacked onto the far end.
|
// (this only happens when we're doing `git log --all`). These will be tacked onto the far end.
|
||||||
pos := maxPos + 1
|
pos := maxPos + 1
|
||||||
@ -137,7 +137,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
|
|||||||
if commit.IsFirstCommit() {
|
if commit.IsFirstCommit() {
|
||||||
toHash = models.EmptyTreeCommitHash
|
toHash = models.EmptyTreeCommitHash
|
||||||
} else {
|
} else {
|
||||||
toHash = commit.Parents[0]
|
toHash = commit.Parents()[0]
|
||||||
}
|
}
|
||||||
newPipes = append(newPipes, &Pipe{
|
newPipes = append(newPipes, &Pipe{
|
||||||
fromPos: pos,
|
fromPos: pos,
|
||||||
@ -216,7 +216,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
if commit.IsMerge() {
|
if commit.IsMerge() {
|
||||||
for _, parent := range commit.Parents[1:] {
|
for _, parent := range commit.Parents()[1:] {
|
||||||
availablePos := getNextAvailablePosForNewPipe()
|
availablePos := getNextAvailablePosForNewPipe()
|
||||||
// need to act as if continuing pipes are going to continue on the same line.
|
// need to act as if continuing pipes are going to continue on the same line.
|
||||||
newPipes = append(newPipes, &Pipe{
|
newPipes = append(newPipes, &Pipe{
|
||||||
|
@ -576,7 +576,7 @@ func generateCommits(count int) []*models.Commit {
|
|||||||
// I need to pick a random number of parents to add
|
// I need to pick a random number of parents to add
|
||||||
parentCount := rnd.Intn(2) + 1
|
parentCount := rnd.Intn(2) + 1
|
||||||
|
|
||||||
parentHashes := currentCommit.Parents
|
parentHashes := currentCommit.Parents()
|
||||||
for j := 0; j < parentCount; j++ {
|
for j := 0; j < parentCount; j++ {
|
||||||
reuseParent := rnd.Intn(6) != 1 && j <= len(pool)-1 && j != 0
|
reuseParent := rnd.Intn(6) != 1 && j <= len(pool)-1 && j != 0
|
||||||
var newParent *models.Commit
|
var newParent *models.Commit
|
||||||
|
@ -37,7 +37,7 @@ func commitShimFromModelCommit(commit *models.Commit) *Commit {
|
|||||||
AuthorEmail: commit.AuthorEmail,
|
AuthorEmail: commit.AuthorEmail,
|
||||||
UnixTimestamp: commit.UnixTimestamp,
|
UnixTimestamp: commit.UnixTimestamp,
|
||||||
Divergence: commit.Divergence,
|
Divergence: commit.Divergence,
|
||||||
Parents: commit.Parents,
|
Parents: commit.Parents(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user