shithub: furgit

ref: dc634ee5daef8268203b26c1b14ab59c11f7f59c
dir: /internal/commitquery/ancestor.go/

View raw version
package commitquery

// IsAncestor reports whether ancestor is reachable from descendant through
// commit parent edges.
func IsAncestor(ctx *Context, ancestor, descendant NodeIndex) (bool, error) {
	if ancestor == descendant {
		return true, nil
	}

	ancestorGeneration := ctx.EffectiveGeneration(ancestor)
	descendantGeneration := ctx.EffectiveGeneration(descendant)

	if ancestorGeneration != generationInfinity &&
		descendantGeneration != generationInfinity &&
		ancestorGeneration > descendantGeneration {
		return false, nil
	}

	minGeneration := uint64(0)
	if ancestorGeneration != generationInfinity {
		minGeneration = ancestorGeneration
	}

	err := paintDownToCommon(ctx, ancestor, []NodeIndex{descendant}, minGeneration)
	if err != nil {
		return false, err
	}

	return ctx.HasAnyMarks(ancestor, markRight), nil
}