Skip to content

Commit 754c78f

Browse files
authored
Merge pull request #159 from vmarkovtsev/master
Fix the corrupted merge bug in hibernation mode
2 parents 36058d7 + 017d8be commit 754c78f

File tree

5 files changed

+55
-16
lines changed

5 files changed

+55
-16
lines changed

internal/core/forks.go

-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,6 @@ func insertHibernateBoot(plan []runAction, hibernationDistance int) []runAction
743743
Items: hibernates,
744744
})
745745
}
746-
747746
}
748747
return newPlan
749748
}

internal/core/pipeline.go

+35-8
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,38 @@ func (pipeline *Pipeline) Run(commits []*object.Commit) (map[LeafPipelineItem]in
679679
var newestTime int64
680680
runTimePerItem := map[string]float64{}
681681

682+
isMerge := func(index int, commit plumbing.Hash) bool {
683+
match := false
684+
// look for the same hash backward
685+
for i := index - 1; i > 0; i-- {
686+
switch plan[i].Action {
687+
case runActionHibernate, runActionBoot:
688+
continue
689+
case runActionCommit:
690+
match = plan[i].Commit.Hash == commit
691+
fallthrough
692+
default:
693+
i = 0
694+
}
695+
}
696+
if match {
697+
return true
698+
}
699+
// look for the same hash forward
700+
for i := index + 1; i < len(plan); i++ {
701+
switch plan[i].Action {
702+
case runActionHibernate, runActionBoot:
703+
continue
704+
case runActionCommit:
705+
match = plan[i].Commit.Hash == commit
706+
fallthrough
707+
default:
708+
i = len(plan)
709+
}
710+
}
711+
return match
712+
}
713+
682714
commitIndex := 0
683715
for index, step := range plan {
684716
onProgress(index+1, progressSteps)
@@ -692,14 +724,9 @@ func (pipeline *Pipeline) Run(commits []*object.Commit) (map[LeafPipelineItem]in
692724
switch step.Action {
693725
case runActionCommit:
694726
state := map[string]interface{}{
695-
DependencyCommit: step.Commit,
696-
DependencyIndex: commitIndex,
697-
DependencyIsMerge: (index > 0 &&
698-
plan[index-1].Action == runActionCommit &&
699-
plan[index-1].Commit.Hash == step.Commit.Hash) ||
700-
(index < (len(plan)-1) &&
701-
plan[index+1].Action == runActionCommit &&
702-
plan[index+1].Commit.Hash == step.Commit.Hash),
727+
DependencyCommit: step.Commit,
728+
DependencyIndex: commitIndex,
729+
DependencyIsMerge: isMerge(index, step.Commit.Hash),
703730
}
704731
for _, item := range branches[firstItem] {
705732
startTime := time.Now()

internal/rbtree/rbtree.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ func (allocator Allocator) Used() int {
5353
}
5454

5555
// Clone copies an existing RBTree allocator.
56-
func (allocator *Allocator) Clone() *Allocator {
56+
func (allocator Allocator) Clone() *Allocator {
5757
if allocator.storage == nil {
5858
panic("cannot clone a hibernated allocator")
5959
}
6060
newAllocator := &Allocator{
61-
storage: make([]node, len(allocator.storage), cap(allocator.storage)),
62-
gaps: map[uint32]bool{},
61+
HibernationThreshold: allocator.HibernationThreshold,
62+
storage: make([]node, len(allocator.storage), cap(allocator.storage)),
63+
gaps: map[uint32]bool{},
6364
}
6465
copy(newAllocator.storage, allocator.storage)
6566
for key, val := range allocator.gaps {

internal/rbtree/rbtree_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ func TestAllocatorHibernateBootThreshold(t *testing.T) {
443443
alloc := NewAllocator()
444444
alloc.malloc()
445445
alloc.HibernationThreshold = 3
446+
assert.Equal(t, 3, alloc.Clone().HibernationThreshold)
446447
alloc.Hibernate()
447448
assert.Equal(t, alloc.hibernatedStorageLen, 0)
448449
alloc.Boot()

leaves/burndown.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -447,17 +447,28 @@ func (analyser *BurndownAnalysis) Hibernate() error {
447447
return err
448448
}
449449
analyser.hibernatedFileName = file.Name()
450-
file.Close()
451-
analyser.fileAllocator.Serialize(analyser.hibernatedFileName)
450+
err = file.Close()
451+
if err != nil {
452+
analyser.hibernatedFileName = ""
453+
return err
454+
}
455+
err = analyser.fileAllocator.Serialize(analyser.hibernatedFileName)
456+
if err != nil {
457+
analyser.hibernatedFileName = ""
458+
return err
459+
}
452460
}
453461
return nil
454462
}
455463

456464
// Boot decompresses the bound RBTree memory with the files.
457465
func (analyser *BurndownAnalysis) Boot() error {
458466
if analyser.hibernatedFileName != "" {
459-
analyser.fileAllocator.Deserialize(analyser.hibernatedFileName)
460-
err := os.Remove(analyser.hibernatedFileName)
467+
err := analyser.fileAllocator.Deserialize(analyser.hibernatedFileName)
468+
if err != nil {
469+
return err
470+
}
471+
err = os.Remove(analyser.hibernatedFileName)
461472
if err != nil {
462473
return err
463474
}

0 commit comments

Comments
 (0)