Skip to content

Commit 722cc85

Browse files
committed
Store Commit.Parents in the pool too
We need to pass %P instead of %p in the format string of the git log command, so that the parent hashes have the full length and can be shared with the real hashes.
1 parent 0f1f455 commit 722cc85

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

pkg/commands/git_commands/commit_loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,4 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
610610
return self.cmd.New(cmdArgs).DontLog()
611611
}
612612

613-
const prettyFormat = `--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s`
613+
const prettyFormat = `--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%P%x00%m%x00%s`

pkg/commands/git_commands/commit_loader_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestGetCommits(t *testing.T) {
4444
opts: GetCommitsOptions{RefName: "HEAD", RefForPushedStatus: "mybranch", IncludeRebaseCommits: false},
4545
runner: oscommands.NewFakeRunner(t).
4646
ExpectGitArgs([]string{"merge-base", "mybranch", "mybranch@{u}"}, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil).
47-
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
47+
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%P%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
4848

4949
expectedCommitOpts: []models.NewCommitOpts{},
5050
expectedError: nil,
@@ -55,7 +55,7 @@ func TestGetCommits(t *testing.T) {
5555
opts: GetCommitsOptions{RefName: "refs/heads/mybranch", RefForPushedStatus: "refs/heads/mybranch", IncludeRebaseCommits: false},
5656
runner: oscommands.NewFakeRunner(t).
5757
ExpectGitArgs([]string{"merge-base", "refs/heads/mybranch", "mybranch@{u}"}, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil).
58-
ExpectGitArgs([]string{"log", "refs/heads/mybranch", "--topo-order", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
58+
ExpectGitArgs([]string{"log", "refs/heads/mybranch", "--topo-order", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%P%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
5959

6060
expectedCommitOpts: []models.NewCommitOpts{},
6161
expectedError: nil,
@@ -69,7 +69,7 @@ func TestGetCommits(t *testing.T) {
6969
// here it's seeing which commits are yet to be pushed
7070
ExpectGitArgs([]string{"merge-base", "mybranch", "mybranch@{u}"}, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil).
7171
// here it's actually getting all the commits in a formatted form, one per line
72-
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, commitsOutput, nil).
72+
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%P%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, commitsOutput, nil).
7373
// here it's testing which of the configured main branches have an upstream
7474
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "master@{u}"}, "refs/remotes/origin/master", nil). // this one does
7575
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "main@{u}"}, "", errors.New("error")). // this one doesn't, so it checks origin instead
@@ -205,7 +205,7 @@ func TestGetCommits(t *testing.T) {
205205
// here it's seeing which commits are yet to be pushed
206206
ExpectGitArgs([]string{"merge-base", "mybranch", "mybranch@{u}"}, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil).
207207
// here it's actually getting all the commits in a formatted form, one per line
208-
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, singleCommitOutput, nil).
208+
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%P%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, singleCommitOutput, nil).
209209
// here it's testing which of the configured main branches exist; neither does
210210
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "master@{u}"}, "", errors.New("error")).
211211
ExpectGitArgs([]string{"rev-parse", "--verify", "--quiet", "refs/remotes/origin/master"}, "", errors.New("error")).
@@ -241,7 +241,7 @@ func TestGetCommits(t *testing.T) {
241241
// here it's seeing which commits are yet to be pushed
242242
ExpectGitArgs([]string{"merge-base", "mybranch", "mybranch@{u}"}, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil).
243243
// here it's actually getting all the commits in a formatted form, one per line
244-
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, singleCommitOutput, nil).
244+
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%P%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, singleCommitOutput, nil).
245245
// here it's testing which of the configured main branches exist
246246
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "master@{u}"}, "refs/remotes/origin/master", nil).
247247
ExpectGitArgs([]string{"rev-parse", "--symbolic-full-name", "main@{u}"}, "", errors.New("error")).
@@ -276,7 +276,7 @@ func TestGetCommits(t *testing.T) {
276276
opts: GetCommitsOptions{RefName: "HEAD", RefForPushedStatus: "mybranch", IncludeRebaseCommits: false},
277277
runner: oscommands.NewFakeRunner(t).
278278
ExpectGitArgs([]string{"merge-base", "mybranch", "mybranch@{u}"}, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil).
279-
ExpectGitArgs([]string{"log", "HEAD", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
279+
ExpectGitArgs([]string{"log", "HEAD", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%P%x00%m%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
280280

281281
expectedCommitOpts: []models.NewCommitOpts{},
282282
expectedError: nil,
@@ -287,7 +287,7 @@ func TestGetCommits(t *testing.T) {
287287
opts: GetCommitsOptions{RefName: "HEAD", RefForPushedStatus: "mybranch", FilterPath: "src"},
288288
runner: oscommands.NewFakeRunner(t).
289289
ExpectGitArgs([]string{"merge-base", "mybranch", "mybranch@{u}"}, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil).
290-
ExpectGitArgs([]string{"log", "HEAD", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s", "--abbrev=40", "--follow", "--no-show-signature", "--", "src"}, "", nil),
290+
ExpectGitArgs([]string{"log", "HEAD", "--oneline", "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%P%x00%m%x00%s", "--abbrev=40", "--follow", "--no-show-signature", "--", "src"}, "", nil),
291291

292292
expectedCommitOpts: []models.NewCommitOpts{},
293293
expectedError: nil,

pkg/commands/git_commands/reflog_commit_loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (self *ReflogCommitLoader) GetReflogCommits(hashPool *utils.StringPool, las
3131
Config("log.showSignature=false").
3232
Arg("-g").
3333
Arg("--abbrev=40").
34-
Arg("--format=%h%x00%ct%x00%gs%x00%p").
34+
Arg("--format=%h%x00%ct%x00%gs%x00%P").
3535
ArgIf(filterAuthor != "", "--author="+filterAuthor).
3636
ArgIf(filterPath != "", "--follow", "--", filterPath).
3737
ToArgv()

pkg/commands/git_commands/reflog_commit_loader_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestGetReflogCommits(t *testing.T) {
3838
{
3939
testName: "no reflog entries",
4040
runner: oscommands.NewFakeRunner(t).
41-
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p"}, "", nil),
41+
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%P"}, "", nil),
4242

4343
lastReflogCommit: nil,
4444
expectedCommitOpts: []models.NewCommitOpts{},
@@ -48,7 +48,7 @@ func TestGetReflogCommits(t *testing.T) {
4848
{
4949
testName: "some reflog entries",
5050
runner: oscommands.NewFakeRunner(t).
51-
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p"}, reflogOutput, nil),
51+
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%P"}, reflogOutput, nil),
5252

5353
lastReflogCommit: nil,
5454
expectedCommitOpts: []models.NewCommitOpts{
@@ -94,7 +94,7 @@ func TestGetReflogCommits(t *testing.T) {
9494
{
9595
testName: "some reflog entries where last commit is given",
9696
runner: oscommands.NewFakeRunner(t).
97-
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p"}, reflogOutput, nil),
97+
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%P"}, reflogOutput, nil),
9898

9999
lastReflogCommit: models.NewCommit(hashPool, models.NewCommitOpts{
100100
Hash: "c3c4b66b64c97ffeecde",
@@ -118,7 +118,7 @@ func TestGetReflogCommits(t *testing.T) {
118118
{
119119
testName: "when passing filterPath",
120120
runner: oscommands.NewFakeRunner(t).
121-
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p", "--follow", "--", "path"}, reflogOutput, nil),
121+
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%P", "--follow", "--", "path"}, reflogOutput, nil),
122122

123123
lastReflogCommit: models.NewCommit(hashPool, models.NewCommitOpts{
124124
Hash: "c3c4b66b64c97ffeecde",
@@ -143,7 +143,7 @@ func TestGetReflogCommits(t *testing.T) {
143143
{
144144
testName: "when passing filterAuthor",
145145
runner: oscommands.NewFakeRunner(t).
146-
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p", "--author=John Doe <[email protected]>"}, reflogOutput, nil),
146+
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%P", "--author=John Doe <[email protected]>"}, reflogOutput, nil),
147147

148148
lastReflogCommit: models.NewCommit(hashPool, models.NewCommitOpts{
149149
Hash: "c3c4b66b64c97ffeecde",
@@ -168,7 +168,7 @@ func TestGetReflogCommits(t *testing.T) {
168168
{
169169
testName: "when command returns error",
170170
runner: oscommands.NewFakeRunner(t).
171-
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%p"}, "", errors.New("haha")),
171+
ExpectGitArgs([]string{"-c", "log.showSignature=false", "log", "-g", "--abbrev=40", "--format=%h%x00%ct%x00%gs%x00%P"}, "", errors.New("haha")),
172172

173173
lastReflogCommit: nil,
174174
filterPath: "",

pkg/commands/models/commit.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/jesseduffield/lazygit/pkg/utils"
7+
"github.com/samber/lo"
78
"github.com/stefanhaller/git-todo-parser/todo"
89
)
910

@@ -54,7 +55,7 @@ type Commit struct {
5455
Divergence Divergence // set to DivergenceNone unless we are showing the divergence view
5556

5657
// Hashes of parent commits (will be multiple if it's a merge commit)
57-
parents []string
58+
parents []*string
5859
}
5960

6061
type NewCommitOpts struct {
@@ -83,7 +84,7 @@ func NewCommit(hashPool *utils.StringPool, opts NewCommitOpts) *Commit {
8384
AuthorEmail: opts.AuthorEmail,
8485
UnixTimestamp: opts.UnixTimestamp,
8586
Divergence: opts.Divergence,
86-
parents: opts.Parents,
87+
parents: lo.Map(opts.Parents, func(s string, _ int) *string { return hashPool.Add(s) }),
8788
}
8889
}
8990

@@ -115,7 +116,7 @@ func (c *Commit) ParentRefName() string {
115116
}
116117

117118
func (c *Commit) Parents() []string {
118-
return c.parents
119+
return lo.Map(c.parents, func(s *string, _ int) string { return *s })
119120
}
120121

121122
func (c *Commit) IsFirstCommit() bool {

0 commit comments

Comments
 (0)