ref: 9053c85456bd9b4457b588610eeef1b8dfff2b89
dir: /internal/commitquery/ancestor.go/
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
}