pub fn attribute(
repo: &Path,
history: &[Commit],
targets: &BTreeSet<String>,
) -> Result<Attribution, String>Expand description
Places every target in targets on the mainline history.
A target already on the mainline maps to itself. Otherwise it arrived through some merge’s second parent, and the mainline commit that introduced it is the oldest one having it as an ancestor.
Found by binary search, not a scan: ancestry is monotone along first-parent order — if a commit is an ancestor of some mainline commit it is an ancestor of every later one — so the predicate flips exactly once. That is ~log2(n) git calls per target instead of n. On rust-lang/rust’s 45,061-commit mainline it is 16 calls, about 0.15 s.
Targets that are not ancestors of the branch tip at all, or whose object is missing from a filtered clone, are recorded as unresolved rather than dropped: how many failed to place is part of reading the result.
§Errors
Git failing in a way that is not a clean answer, which would otherwise be silently miscounted as “not an ancestor”.