Explorar o código

Properly survive tensorflow/tensorflow

Signed-off-by: Vadim Markovtsev <vadim@sourced.tech>
Vadim Markovtsev %!s(int64=6) %!d(string=hai) anos
pai
achega
3918d7e12c
Modificáronse 3 ficheiros con 28 adicións e 21 borrados
  1. 21 14
      internal/core/forks.go
  2. 1 1
      internal/core/pipeline.go
  3. 6 6
      internal/core/pipeline_test.go

+ 21 - 14
internal/core/forks.go

@@ -81,6 +81,9 @@ const (
 	runActionEmerge = iota
 	// runActionDelete removes the branch as it is no longer needed
 	runActionDelete = iota
+
+	// rootBranchIndex is the minimum branch index in the plan
+	rootBranchIndex = 1
 )
 
 type runAction struct {
@@ -421,7 +424,18 @@ func collapseFastForwards(
 		if len(toRemove) == 0 {
 			continue
 		}
+		// update dag
 		var newVals []*object.Commit
+		node := mergedSeq[key][len(mergedSeq[key])-1].Hash
+		for _, child := range dag[node] {
+			if !toRemove[child.Hash] {
+				newVals = append(newVals, child)
+			}
+		}
+		dag[node] = newVals
+
+		// update mergedDag
+		newVals = []*object.Commit{}
 		for _, child := range vals {
 			if !toRemove[child.Hash] {
 				newVals = append(newVals, child)
@@ -450,16 +464,7 @@ func collapseFastForwards(
 		}
 		if !merged {
 			mergedDag[key] = newVals
-		}
-		newVals = []*object.Commit{}
-		node := mergedSeq[key][len(mergedSeq[key])-1].Hash
-		for _, child := range dag[node] {
-			if !toRemove[child.Hash] {
-				newVals = append(newVals, child)
-			}
-		}
-		dag[node] = newVals
-		if merged {
+		} else {
 			goto repeat
 		}
 	}
@@ -474,7 +479,7 @@ func generatePlan(
 	var plan []runAction
 	branches := map[plumbing.Hash]int{}
 	branchers := map[plumbing.Hash]map[plumbing.Hash]int{}
-	counter := 0
+	counter := rootBranchIndex
 	for _, name := range orderNodes(false, true) {
 		commit := hashes[name]
 		if len(parents[commit.Hash]) == 0 {
@@ -496,12 +501,14 @@ func generatePlan(
 		}
 		branchExists := func() bool { return branch >= 0 }
 		appendCommit := func(c *object.Commit, branch int) {
+			if branch == 0 {
+				log.Panicf("setting a zero branch for %s", c.Hash.String())
+			}
 			plan = append(plan, runAction{
 				Action: runActionCommit,
 				Commit: c,
 				Items: []int{branch},
 			})
-
 		}
 		appendMergeIfNeeded := func() {
 			if len(parents[commit.Hash]) < 2 {
@@ -519,7 +526,7 @@ func generatePlan(
 				}
 				if parentBranch == -1 {
 					parentBranch = branches[parent]
-					if parentBranch == -1 {
+					if parentBranch <= 0 {
 						log.Panicf("parent %s > %s does not have a branch assigned",
 							parent.String(), commit.Hash.String())
 					}
@@ -581,7 +588,7 @@ func generatePlan(
 			}
 			plan = append(plan, runAction{
 				Action: runActionFork,
-				Commit: nil,
+				Commit: hashes[head.String()],
 				Items:  children,
 			})
 		}

+ 1 - 1
internal/core/pipeline.go

@@ -645,7 +645,7 @@ func (pipeline *Pipeline) Run(commits []*object.Commit) (map[LeafPipelineItem]in
 			}
 			mergeItems(merged)
 		case runActionEmerge:
-			if firstItem == 0 {
+			if firstItem == rootBranchIndex {
 				branches[firstItem] = pipeline.items
 			} else {
 				branches[firstItem] = cloneItems(rootClone, 1)[0]

+ 6 - 6
internal/core/pipeline_test.go

@@ -451,10 +451,10 @@ func TestPrepareRunPlanTiny(t *testing.T) {
 	plan := prepareRunPlan([]*object.Commit{rootCommit})
 	assert.Len(t, plan, 2)
 	assert.Equal(t, runActionEmerge, plan[0].Action)
-	assert.Equal(t, 0, plan[0].Items[0])
+	assert.Equal(t, rootBranchIndex, plan[0].Items[0])
 	assert.Equal(t, "cce947b98a050c6d356bc6ba95030254914027b1", plan[0].Commit.Hash.String())
 	assert.Equal(t, runActionCommit, plan[1].Action)
-	assert.Equal(t, 0, plan[1].Items[0])
+	assert.Equal(t, rootBranchIndex, plan[1].Items[0])
 	assert.Equal(t, "cce947b98a050c6d356bc6ba95030254914027b1", plan[1].Commit.Hash.String())
 }
 
@@ -487,15 +487,15 @@ func TestPrepareRunPlanSmall(t *testing.T) {
 	assert.Len(t, plan, len(commits) + 1)
 	assert.Equal(t, runActionEmerge, plan[0].Action)
 	assert.Equal(t, "cce947b98a050c6d356bc6ba95030254914027b1", plan[0].Commit.Hash.String())
-	assert.Equal(t, 0, plan[0].Items[0])
+	assert.Equal(t, rootBranchIndex, plan[0].Items[0])
 	assert.Equal(t, runActionCommit, plan[1].Action)
-	assert.Equal(t, 0, plan[1].Items[0])
+	assert.Equal(t, rootBranchIndex, plan[1].Items[0])
 	assert.Equal(t, "cce947b98a050c6d356bc6ba95030254914027b1", plan[1].Commit.Hash.String())
 	assert.Equal(t, runActionCommit, plan[2].Action)
-	assert.Equal(t, 0, plan[2].Items[0])
+	assert.Equal(t, rootBranchIndex, plan[2].Items[0])
 	assert.Equal(t, "a3ee37f91f0d705ec9c41ae88426f0ae44b2fbc3", plan[2].Commit.Hash.String())
 	assert.Equal(t, runActionCommit, plan[10].Action)
-	assert.Equal(t, 0, plan[10].Items[0])
+	assert.Equal(t, rootBranchIndex, plan[10].Items[0])
 	assert.Equal(t, "a28e9064c70618dc9d68e1401b889975e0680d11", plan[10].Commit.Hash.String())
 }