浏览代码

Add runActionEmerge and make Pipeline support multiple roots

Vadim Markovtsev 6 年之前
父节点
当前提交
802bda1998
共有 2 个文件被更改,包括 18 次插入1 次删除
  1. 9 0
      internal/core/forks.go
  2. 9 1
      internal/core/pipeline.go

+ 9 - 0
internal/core/forks.go

@@ -77,6 +77,8 @@ const (
 	runActionFork = iota
 	// runActionMerge merges several branches together
 	runActionMerge = iota
+	// runActionEmerge starts a root branch
+	runActionEmerge = iota
 	// runActionDelete removes the branch as it is no longer needed
 	runActionDelete = iota
 )
@@ -485,6 +487,11 @@ func generatePlan(
 		commit := hashes[name]
 		if numParents(commit) == 0 {
 			branches[commit.Hash] = counter
+			plan = append(plan, runAction{
+				Action: runActionEmerge,
+				Commit: commit,
+				Items: []int{counter},
+			})
 			counter++
 		}
 		var branch int
@@ -682,6 +689,8 @@ func optimizePlan(plan []runAction) []runAction {
 						Items:  newBranches,
 					})
 				}
+			case runActionEmerge:
+				optimizedPlan = append(optimizedPlan, p)
 			}
 		}
 		if pair[1] >= 0 {

+ 9 - 1
internal/core/pipeline.go

@@ -553,7 +553,9 @@ func (pipeline *Pipeline) Run(commits []*object.Commit) (map[LeafPipelineItem]in
 	}
 	plan := prepareRunPlan(commits)
 	progressSteps := len(plan) + 2
-	branches := map[int][]PipelineItem{0: pipeline.items}
+	branches := map[int][]PipelineItem{}
+	// we will need rootClone if there is more than one root branch
+	rootClone := cloneItems(pipeline.items, 1)[0]
 	var newestTime int64
 
 	for index, step := range plan {
@@ -594,6 +596,12 @@ func (pipeline *Pipeline) Run(commits []*object.Commit) (map[LeafPipelineItem]in
 				merged[i] = branches[b]
 			}
 			mergeItems(merged)
+		case runActionEmerge:
+			if firstItem == 0 {
+				branches[firstItem] = pipeline.items
+			} else {
+				branches[firstItem] = cloneItems(rootClone, 1)[0]
+			}
 		case runActionDelete:
 			delete(branches, firstItem)
 		}