Skip to main content

CandidateComposer

Struct CandidateComposer 

Source
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>

Source

pub fn new(repo: &'a Repository) -> Self

Wrap a borrowed repository.

Source

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.

Source

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).

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

impl<T> Identity for T
where T: ?Sized,

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,