@@ -66,6 +66,7 @@ type GetCommitsOptions struct {
66
66
// If non-empty, show divergence from this ref (left-right log)
67
67
RefToShowDivergenceFrom string
68
68
MainBranches * MainBranches
69
+ HashPool * utils.StringPool
69
70
}
70
71
71
72
// GetCommits obtains the commits of the current branch
@@ -74,7 +75,7 @@ func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit,
74
75
75
76
if opts .IncludeRebaseCommits && opts .FilterPath == "" {
76
77
var err error
77
- commits , err = self .MergeRebasingCommits (commits )
78
+ commits , err = self .MergeRebasingCommits (opts . HashPool , commits )
78
79
if err != nil {
79
80
return nil , err
80
81
}
@@ -89,7 +90,7 @@ func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit,
89
90
defer wg .Done ()
90
91
91
92
logErr = self .getLogCmd (opts ).RunAndProcessLines (func (line string ) (bool , error ) {
92
- commit := self .extractCommitFromLine (line , opts .RefToShowDivergenceFrom != "" )
93
+ commit := self .extractCommitFromLine (opts . HashPool , line , opts .RefToShowDivergenceFrom != "" )
93
94
commits = append (commits , commit )
94
95
return false , nil
95
96
})
@@ -121,7 +122,7 @@ func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit,
121
122
}
122
123
123
124
for _ , commit := range commits {
124
- if commit .Hash == firstPushedCommit {
125
+ if commit .Hash () == firstPushedCommit {
125
126
passedFirstPushedCommit = true
126
127
}
127
128
if ! commit .IsTODO () {
@@ -159,7 +160,7 @@ func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit,
159
160
return commits , nil
160
161
}
161
162
162
- func (self * CommitLoader ) MergeRebasingCommits (commits []* models.Commit ) ([]* models.Commit , error ) {
163
+ func (self * CommitLoader ) MergeRebasingCommits (hashPool * utils. StringPool , commits []* models.Commit ) ([]* models.Commit , error ) {
163
164
// chances are we have as many commits as last time so we'll set the capacity to be the old length
164
165
result := make ([]* models.Commit , 0 , len (commits ))
165
166
for i , commit := range commits {
@@ -172,7 +173,7 @@ func (self *CommitLoader) MergeRebasingCommits(commits []*models.Commit) ([]*mod
172
173
workingTreeState := self .getWorkingTreeState ()
173
174
addConflictedRebasingCommit := true
174
175
if workingTreeState .CherryPicking || workingTreeState .Reverting {
175
- sequencerCommits , err := self .getHydratedSequencerCommits (workingTreeState )
176
+ sequencerCommits , err := self .getHydratedSequencerCommits (hashPool , workingTreeState )
176
177
if err != nil {
177
178
return nil , err
178
179
}
@@ -181,7 +182,7 @@ func (self *CommitLoader) MergeRebasingCommits(commits []*models.Commit) ([]*mod
181
182
}
182
183
183
184
if workingTreeState .Rebasing {
184
- rebasingCommits , err := self .getHydratedRebasingCommits (addConflictedRebasingCommit )
185
+ rebasingCommits , err := self .getHydratedRebasingCommits (hashPool , addConflictedRebasingCommit )
185
186
if err != nil {
186
187
return nil , err
187
188
}
@@ -196,7 +197,7 @@ func (self *CommitLoader) MergeRebasingCommits(commits []*models.Commit) ([]*mod
196
197
// then puts them into a commit object
197
198
// example input:
198
199
// 8ad01fe32fcc20f07bc6693f87aa4977c327f1e1|10 hours ago|Jesse Duffield| (HEAD -> master, tag: v0.15.2)|refresh commits when adding a tag
199
- func (self * CommitLoader ) extractCommitFromLine (line string , showDivergence bool ) * models.Commit {
200
+ func (self * CommitLoader ) extractCommitFromLine (hashPool * utils. StringPool , line string , showDivergence bool ) * models.Commit {
200
201
split := strings .SplitN (line , "\x00 " , 8 )
201
202
202
203
hash := split [0 ]
@@ -234,7 +235,7 @@ func (self *CommitLoader) extractCommitFromLine(line string, showDivergence bool
234
235
parents = strings .Split (parentHashes , " " )
235
236
}
236
237
237
- return & models.Commit {
238
+ return models .NewCommit ( hashPool , models. NewCommitOpts {
238
239
Hash : hash ,
239
240
Name : message ,
240
241
Tags : tags ,
@@ -244,16 +245,16 @@ func (self *CommitLoader) extractCommitFromLine(line string, showDivergence bool
244
245
AuthorEmail : authorEmail ,
245
246
Parents : parents ,
246
247
Divergence : divergence ,
247
- }
248
+ })
248
249
}
249
250
250
- func (self * CommitLoader ) getHydratedRebasingCommits (addConflictingCommit bool ) ([]* models.Commit , error ) {
251
+ func (self * CommitLoader ) getHydratedRebasingCommits (hashPool * utils. StringPool , addConflictingCommit bool ) ([]* models.Commit , error ) {
251
252
todoFileHasShortHashes := self .version .IsOlderThan (2 , 25 , 2 )
252
- return self .getHydratedTodoCommits (self .getRebasingCommits (addConflictingCommit ), todoFileHasShortHashes )
253
+ return self .getHydratedTodoCommits (hashPool , self .getRebasingCommits (hashPool , addConflictingCommit ), todoFileHasShortHashes )
253
254
}
254
255
255
- func (self * CommitLoader ) getHydratedSequencerCommits (workingTreeState models.WorkingTreeState ) ([]* models.Commit , error ) {
256
- commits := self .getSequencerCommits ()
256
+ func (self * CommitLoader ) getHydratedSequencerCommits (hashPool * utils. StringPool , workingTreeState models.WorkingTreeState ) ([]* models.Commit , error ) {
257
+ commits := self .getSequencerCommits (hashPool )
257
258
if len (commits ) > 0 {
258
259
// If we have any commits in .git/sequencer/todo, then the last one of
259
260
// those is the conflicting one.
@@ -262,22 +263,22 @@ func (self *CommitLoader) getHydratedSequencerCommits(workingTreeState models.Wo
262
263
// For single-commit cherry-picks and reverts, git apparently doesn't
263
264
// use the sequencer; in that case, CHERRY_PICK_HEAD or REVERT_HEAD is
264
265
// our conflicting commit, so synthesize it here.
265
- conflicedCommit := self .getConflictedSequencerCommit (workingTreeState )
266
+ conflicedCommit := self .getConflictedSequencerCommit (hashPool , workingTreeState )
266
267
if conflicedCommit != nil {
267
268
commits = append (commits , conflicedCommit )
268
269
}
269
270
}
270
271
271
- return self .getHydratedTodoCommits (commits , true )
272
+ return self .getHydratedTodoCommits (hashPool , commits , true )
272
273
}
273
274
274
- func (self * CommitLoader ) getHydratedTodoCommits (todoCommits []* models.Commit , todoFileHasShortHashes bool ) ([]* models.Commit , error ) {
275
+ func (self * CommitLoader ) getHydratedTodoCommits (hashPool * utils. StringPool , todoCommits []* models.Commit , todoFileHasShortHashes bool ) ([]* models.Commit , error ) {
275
276
if len (todoCommits ) == 0 {
276
277
return nil , nil
277
278
}
278
279
279
280
commitHashes := lo .FilterMap (todoCommits , func (commit * models.Commit , _ int ) (string , bool ) {
280
- return commit .Hash , commit .Hash != ""
281
+ return commit .Hash () , commit .Hash () != ""
281
282
})
282
283
283
284
// note that we're not filtering these as we do non-rebasing commits just because
@@ -292,8 +293,8 @@ func (self *CommitLoader) getHydratedTodoCommits(todoCommits []*models.Commit, t
292
293
293
294
fullCommits := map [string ]* models.Commit {}
294
295
err := cmdObj .RunAndProcessLines (func (line string ) (bool , error ) {
295
- commit := self .extractCommitFromLine (line , false )
296
- fullCommits [commit .Hash ] = commit
296
+ commit := self .extractCommitFromLine (hashPool , line , false )
297
+ fullCommits [commit .Hash () ] = commit
297
298
return false , nil
298
299
})
299
300
if err != nil {
@@ -315,9 +316,9 @@ func (self *CommitLoader) getHydratedTodoCommits(todoCommits []*models.Commit, t
315
316
316
317
hydratedCommits := make ([]* models.Commit , 0 , len (todoCommits ))
317
318
for _ , rebasingCommit := range todoCommits {
318
- if rebasingCommit .Hash == "" {
319
+ if rebasingCommit .Hash () == "" {
319
320
hydratedCommits = append (hydratedCommits , rebasingCommit )
320
- } else if commit := findFullCommit (rebasingCommit .Hash ); commit != nil {
321
+ } else if commit := findFullCommit (rebasingCommit .Hash () ); commit != nil {
321
322
commit .Action = rebasingCommit .Action
322
323
commit .Status = rebasingCommit .Status
323
324
hydratedCommits = append (hydratedCommits , commit )
@@ -331,7 +332,7 @@ func (self *CommitLoader) getHydratedTodoCommits(todoCommits []*models.Commit, t
331
332
// git-rebase-todo example:
332
333
// pick ac446ae94ee560bdb8d1d057278657b251aaef17 ac446ae
333
334
// pick afb893148791a2fbd8091aeb81deba4930c73031 afb8931
334
- func (self * CommitLoader ) getRebasingCommits (addConflictingCommit bool ) []* models.Commit {
335
+ func (self * CommitLoader ) getRebasingCommits (hashPool * utils. StringPool , addConflictingCommit bool ) []* models.Commit {
335
336
bytesContent , err := self .readFile (filepath .Join (self .repoPaths .WorktreeGitDirPath (), "rebase-merge/git-rebase-todo" ))
336
337
if err != nil {
337
338
self .Log .Error (fmt .Sprintf ("error occurred reading git-rebase-todo: %s" , err .Error ()))
@@ -350,7 +351,7 @@ func (self *CommitLoader) getRebasingCommits(addConflictingCommit bool) []*model
350
351
// See if the current commit couldn't be applied because it conflicted; if
351
352
// so, add a fake entry for it
352
353
if addConflictingCommit {
353
- if conflictedCommit := self .getConflictedCommit (todos ); conflictedCommit != nil {
354
+ if conflictedCommit := self .getConflictedCommit (hashPool , todos ); conflictedCommit != nil {
354
355
commits = append (commits , conflictedCommit )
355
356
}
356
357
}
@@ -364,18 +365,18 @@ func (self *CommitLoader) getRebasingCommits(addConflictingCommit bool) []*model
364
365
// Command does not have a commit associated, skip
365
366
continue
366
367
}
367
- commits = utils .Prepend (commits , & models.Commit {
368
+ commits = utils .Prepend (commits , models .NewCommit ( hashPool , models. NewCommitOpts {
368
369
Hash : t .Commit ,
369
370
Name : t .Msg ,
370
371
Status : models .StatusRebasing ,
371
372
Action : t .Command ,
372
- })
373
+ }))
373
374
}
374
375
375
376
return commits
376
377
}
377
378
378
- func (self * CommitLoader ) getConflictedCommit (todos []todo.Todo ) * models.Commit {
379
+ func (self * CommitLoader ) getConflictedCommit (hashPool * utils. StringPool , todos []todo.Todo ) * models.Commit {
379
380
bytesContent , err := self .readFile (filepath .Join (self .repoPaths .WorktreeGitDirPath (), "rebase-merge/done" ))
380
381
if err != nil {
381
382
self .Log .Error (fmt .Sprintf ("error occurred reading rebase-merge/done: %s" , err .Error ()))
@@ -391,10 +392,10 @@ func (self *CommitLoader) getConflictedCommit(todos []todo.Todo) *models.Commit
391
392
amendFileExists , _ := self .os .FileExists (filepath .Join (self .repoPaths .WorktreeGitDirPath (), "rebase-merge/amend" ))
392
393
messageFileExists , _ := self .os .FileExists (filepath .Join (self .repoPaths .WorktreeGitDirPath (), "rebase-merge/message" ))
393
394
394
- return self .getConflictedCommitImpl (todos , doneTodos , amendFileExists , messageFileExists )
395
+ return self .getConflictedCommitImpl (hashPool , todos , doneTodos , amendFileExists , messageFileExists )
395
396
}
396
397
397
- func (self * CommitLoader ) getConflictedCommitImpl (todos []todo.Todo , doneTodos []todo.Todo , amendFileExists bool , messageFileExists bool ) * models.Commit {
398
+ func (self * CommitLoader ) getConflictedCommitImpl (hashPool * utils. StringPool , todos []todo.Todo , doneTodos []todo.Todo , amendFileExists bool , messageFileExists bool ) * models.Commit {
398
399
// Should never be possible, but just to be safe:
399
400
if len (doneTodos ) == 0 {
400
401
self .Log .Error ("no done entries in rebase-merge/done file" )
@@ -465,14 +466,14 @@ func (self *CommitLoader) getConflictedCommitImpl(todos []todo.Todo, doneTodos [
465
466
466
467
// Any other todo that has a commit associated with it must have failed with
467
468
// a conflict, otherwise we wouldn't have stopped the rebase:
468
- return & models.Commit {
469
+ return models .NewCommit ( hashPool , models. NewCommitOpts {
469
470
Hash : lastTodo .Commit ,
470
471
Action : lastTodo .Command ,
471
472
Status : models .StatusConflicted ,
472
- }
473
+ })
473
474
}
474
475
475
- func (self * CommitLoader ) getSequencerCommits () []* models.Commit {
476
+ func (self * CommitLoader ) getSequencerCommits (hashPool * utils. StringPool ) []* models.Commit {
476
477
bytesContent , err := self .readFile (filepath .Join (self .repoPaths .WorktreeGitDirPath (), "sequencer/todo" ))
477
478
if err != nil {
478
479
self .Log .Error (fmt .Sprintf ("error occurred reading sequencer/todo: %s" , err .Error ()))
@@ -493,18 +494,18 @@ func (self *CommitLoader) getSequencerCommits() []*models.Commit {
493
494
// Command does not have a commit associated, skip
494
495
continue
495
496
}
496
- commits = utils .Prepend (commits , & models.Commit {
497
+ commits = utils .Prepend (commits , models .NewCommit ( hashPool , models. NewCommitOpts {
497
498
Hash : t .Commit ,
498
499
Name : t .Msg ,
499
500
Status : models .StatusCherryPickingOrReverting ,
500
501
Action : t .Command ,
501
- })
502
+ }))
502
503
}
503
504
504
505
return commits
505
506
}
506
507
507
- func (self * CommitLoader ) getConflictedSequencerCommit (workingTreeState models.WorkingTreeState ) * models.Commit {
508
+ func (self * CommitLoader ) getConflictedSequencerCommit (hashPool * utils. StringPool , workingTreeState models.WorkingTreeState ) * models.Commit {
508
509
var shaFile string
509
510
var action todo.TodoCommand
510
511
if workingTreeState .CherryPicking {
@@ -526,11 +527,11 @@ func (self *CommitLoader) getConflictedSequencerCommit(workingTreeState models.W
526
527
if len (lines ) == 0 {
527
528
return nil
528
529
}
529
- return & models.Commit {
530
+ return models .NewCommit ( hashPool , models. NewCommitOpts {
530
531
Hash : lines [0 ],
531
532
Status : models .StatusConflicted ,
532
533
Action : action ,
533
- }
534
+ })
534
535
}
535
536
536
537
func setCommitMergedStatuses (ancestor string , commits []* models.Commit ) {
@@ -541,7 +542,7 @@ func setCommitMergedStatuses(ancestor string, commits []*models.Commit) {
541
542
passedAncestor := false
542
543
for i , commit := range commits {
543
544
// some commits aren't really commits and don't have hashes, such as the update-ref todo
544
- if commit .Hash != "" && strings .HasPrefix (ancestor , commit .Hash ) {
545
+ if commit .Hash () != "" && strings .HasPrefix (ancestor , commit .Hash () ) {
545
546
passedAncestor = true
546
547
}
547
548
if commit .Status != models .StatusPushed && commit .Status != models .StatusUnpushed {
@@ -609,4 +610,4 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
609
610
return self .cmd .New (cmdArgs ).DontLog ()
610
611
}
611
612
612
- 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`
0 commit comments