pub struct CandidateComposer<'a> { /* private fields */ }Expand description
In-memory, HEAD-preserving merge composition.
Wraps a borrowed git2::Repository and exposes the small surface needed
to compose sequential merge candidates without mutating HEAD or the working
tree. Obtain a &Repository via the existing escape hatch
(RepositoryHandle::open_repo) and
construct a composer over it:
let composer = CandidateComposer::new(repo);
let mb = composer.merge_base(oid_a, oid_b)?;Implementations§
Source§impl<'a> CandidateComposer<'a>
impl<'a> CandidateComposer<'a>
Sourcepub fn new(repo: &'a Repository) -> Self
pub fn new(repo: &'a Repository) -> Self
Wrap a borrowed repository.
Sourcepub fn merge_base(&self, one: Oid, two: Oid) -> Git2DBResult<Oid>
pub fn merge_base(&self, one: Oid, two: Oid) -> Git2DBResult<Oid>
Compute the best common ancestor of two commits (git merge-base).
Thin, pure-read wrapper over git2::Repository::merge_base. Returns
Git2DBError::InvalidOperation when the two commits share no history
(libgit2’s NotFound), matching the “no common ancestor” semantics of
merge_bases.
Sourcepub fn merge_bases(&self, one: Oid, two: Oid) -> Git2DBResult<Vec<Oid>>
pub fn merge_bases(&self, one: Oid, two: Oid) -> Git2DBResult<Vec<Oid>>
Compute all merge bases of two commits (git merge-base --all).
Thin, pure-read wrapper over git2::Repository::merge_bases. Returns
an empty Vec when the commits share no history (libgit2’s NotFound
is mapped to the empty set, since “no common ancestor” is a well-defined
answer rather than an error here).
Sourcepub fn merge_trees(
&self,
ancestor: &Tree<'_>,
ours: &Tree<'_>,
theirs: &Tree<'_>,
) -> Git2DBResult<MergeTreesResult>
pub fn merge_trees( &self, ancestor: &Tree<'_>, ours: &Tree<'_>, theirs: &Tree<'_>, ) -> Git2DBResult<MergeTreesResult>
Three-way merge of trees, fully in memory.
Wraps git2::Repository::merge_trees → git2::Index → tree OID.
On conflict, tree is None and conflicts carries a structured
ConflictReport (path + side), replacing the legacy string-only
"Merge conflicts detected" error.
Neither HEAD nor the working tree is touched.
Sourcepub fn compose_candidate(
&self,
base: Oid,
heads: &[Oid],
message: &str,
) -> Git2DBResult<Candidate>
pub fn compose_candidate( &self, base: Oid, heads: &[Oid], message: &str, ) -> Git2DBResult<Candidate>
Deterministically compose a sequential candidate from base + heads.
Performs an octopus-style cumulative merge: starting from base’s tree
as the accumulator, each head is folded in with a three-way
merge_trees step whose ancestor is the merge base of the
accumulator and the head — merge_base(current_tip, head) — not
merge_base(base, head). Folding against the evolving accumulator
(not a fixed base) is what keeps a stacked head (one built on top of
an earlier head) from producing a false add/add conflict, and keeps a
revert head from silently losing its revert: the ancestor reflects
what the head actually diverged from given everything folded so far.
To give git a commit to resolve merge_base against mid-fold, each
step anchors an unreachable intermediate commit (no ref) over the
accumulated tree; the next iteration resolves its merge base from that
tip. The returned candidate is the final octopus commit with
parents [base, ...heads] — the intermediates are scaffolding only.
Because each merge_trees step is a pure function of its three trees,
the resulting tree OID is stable across reruns for the same inputs.
§Errors
Returns Git2DBError::MergeConflictReport if any step conflicts,
carrying the structured ConflictReport for that step. Returns
Git2DBError::InvalidOperation if heads is empty, if base
appears in heads, or if a head shares no merge base with the
accumulator (unrelated history).
§Garbage collection
Each fold step writes an unreachable intermediate commit, and the returned candidate is detached (referenced by no ref). All become GC-eligible under git’s default prune window unless the caller lands the candidate onto a ref.
§Duplicate heads
Folding the same head twice is harmless: the second fold’s
merge_base(current_tip, head) resolves to head (already absorbed),
so merge_trees is a no-op. Callers need not deduplicate.
Auto Trait Implementations§
impl<'a> Freeze for CandidateComposer<'a>
impl<'a> RefUnwindSafe for CandidateComposer<'a>
impl<'a> !Send for CandidateComposer<'a>
impl<'a> !Sync for CandidateComposer<'a>
impl<'a> Unpin for CandidateComposer<'a>
impl<'a> UnsafeUnpin for CandidateComposer<'a>
impl<'a> UnwindSafe for CandidateComposer<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more