shithub: furgit

Download patch

ref: 236a666b716cac51872edf93f14ffe6b553f259b
parent: 9d08dc994d51298e2d8e75d8ed4ee477312ec53a
author: Runxi Yu <me@runxiyu.org>
date: Sat Mar 7 11:42:48 EST 2026

internal/commitquery: paintDown only paints, don't collect

--- a/internal/commitquery/ancestor.go
+++ b/internal/commitquery/ancestor.go
@@ -21,7 +21,7 @@
 		minGeneration = ancestorGeneration
 	}
 
-	_, err := paintDownToCommon(ctx, ancestor, []NodeIndex{descendant}, minGeneration)
+	err := paintDownToCommon(ctx, ancestor, []NodeIndex{descendant}, minGeneration)
 	if err != nil {
 		return false, err
 	}
--- a/internal/commitquery/merge_bases.go
+++ b/internal/commitquery/merge_bases.go
@@ -8,11 +8,13 @@
 		return []NodeIndex{left}, nil
 	}
 
-	candidates, err := paintDownToCommon(ctx, left, []NodeIndex{right}, 0)
+	err := paintDownToCommon(ctx, left, []NodeIndex{right}, 0)
 	if err != nil {
 		return nil, err
 	}
 
+	candidates := collectMarkedResults(ctx)
+
 	if len(candidates) <= 1 {
 		slices.SortFunc(candidates, ctx.Compare)
 
@@ -31,13 +33,15 @@
 	return reduced, nil
 }
 
-func paintDownToCommon(ctx *Context, left NodeIndex, rights []NodeIndex, minGeneration uint64) ([]NodeIndex, error) {
+func paintDownToCommon(ctx *Context, left NodeIndex, rights []NodeIndex, minGeneration uint64) error {
 	ctx.BeginMarkPhase()
 
 	ctx.SetMarks(left, markLeft)
 
 	if len(rights) == 0 {
-		return []NodeIndex{left}, nil
+		ctx.SetMarks(left, markResult)
+
+		return nil
 	}
 
 	queue := NewPriorityQueue(ctx)
@@ -49,7 +53,6 @@
 	}
 
 	lastGeneration := generationInfinity
-	results := make([]NodeIndex, 0, 4)
 
 	for queueHasNonStale(ctx, queue) {
 		idx := queue.PopNode()
@@ -56,7 +59,7 @@
 
 		generation := ctx.EffectiveGeneration(idx)
 		if generation > lastGeneration {
-			return nil, errBadGenerationOrder
+			return errBadGenerationOrder
 		}
 
 		lastGeneration = generation
@@ -66,10 +69,7 @@
 
 		flags := ctx.Marks(idx) & (markLeft | markRight | markStale)
 		if flags == (markLeft | markRight) {
-			if !ctx.HasAnyMarks(idx, markResult) {
-				ctx.SetMarks(idx, markResult)
-				results = append(results, idx)
-			}
+			ctx.SetMarks(idx, markResult)
 
 			flags |= markStale
 		}
@@ -84,14 +84,7 @@
 		}
 	}
 
-	out := results[:0]
-	for _, idx := range results {
-		if !ctx.HasAnyMarks(idx, markStale) {
-			out = append(out, idx)
-		}
-	}
-
-	return out, nil
+	return nil
 }
 
 func queueHasNonStale(ctx *Context, queue *PriorityQueue) bool {
@@ -102,4 +95,22 @@
 	}
 
 	return false
+}
+
+func collectMarkedResults(ctx *Context) []NodeIndex {
+	out := make([]NodeIndex, 0, 4)
+
+	for _, idx := range ctx.touched {
+		if !ctx.HasAnyMarks(idx, markResult) {
+			continue
+		}
+
+		if ctx.HasAnyMarks(idx, markStale) {
+			continue
+		}
+
+		out = append(out, idx)
+	}
+
+	return out
 }
--- a/internal/commitquery/reduce.go
+++ b/internal/commitquery/reduce.go
@@ -44,7 +44,7 @@
 			}
 		}
 
-		_, err := paintDownToCommon(ctx, candidate, work, minGeneration)
+		err := paintDownToCommon(ctx, candidate, work, minGeneration)
 		if err != nil {
 			return nil, err
 		}
--