Merge

Struct Merge 

Source
pub struct Merge<T> { /* private fields */ }
Expand description

A generic representation of merged values.

There is exactly one more adds() than removes(). When interpreted as a series of diffs, the merge’s (i+1)-st add is matched with the i-th remove. The zeroth add is considered a diff from the non-existent state.

Implementations§

Source§

impl<T> Merge<T>

Source

pub fn from_vec(values: impl Into<SmallVec<[T; 1]>>) -> Self

Creates a Merge from the given values, in which positive and negative terms alternate.

Source

pub fn from_removes_adds( removes: impl IntoIterator<Item = T>, adds: impl IntoIterator<Item = T>, ) -> Self

Creates a new merge object from the given removes and adds.

Source

pub const fn resolved(value: T) -> Self

Creates a Merge with a single resolved value.

Source

pub fn from_legacy_form( removes: impl IntoIterator<Item = T>, adds: impl IntoIterator<Item = T>, ) -> Merge<Option<T>>

Create a Merge from a removes and adds, padding with None to make sure that there is exactly one more adds than removes.

Source

pub fn removes(&self) -> impl ExactSizeIterator<Item = &T>

The removed values, also called negative terms.

Source

pub fn adds(&self) -> impl ExactSizeIterator<Item = &T>

The added values, also called positive terms.

Source

pub fn first(&self) -> &T

Returns the zeroth added value, which is guaranteed to exist.

Source

pub fn get_remove(&self, index: usize) -> Option<&T>

Returns the index-th removed value, which is considered belonging to the index-th diff pair.

Source

pub fn get_add(&self, index: usize) -> Option<&T>

Returns the index-th added value, which is considered belonging to the index-1-th diff pair. The zeroth add is a diff from the non-existent state.

Source

pub fn swap_remove(&mut self, remove_index: usize, add_index: usize) -> (T, T)

Removes the specified “removed”/“added” values. The removed slots are replaced by the last “removed”/“added” values.

Source

pub fn num_sides(&self) -> usize

The number of positive terms in the conflict.

Source

pub fn is_resolved(&self) -> bool

Whether this merge is resolved. Does not resolve trivial merges.

Source

pub fn as_resolved(&self) -> Option<&T>

Returns the resolved value, if this merge is resolved. Does not resolve trivial merges.

Source

pub fn into_resolved(self) -> Result<T, Self>

Returns the resolved value, if this merge is resolved. Otherwise returns the merge itself as an Err. Does not resolve trivial merges.

Source

pub fn simplify(&self) -> Self
where T: PartialEq + Clone,

Simplify the merge by joining diffs like A->B and B->C into A->C. Also drops trivial diffs like A->A.

Source

pub fn update_from_simplified(self, simplified: Self) -> Self
where T: PartialEq,

Updates the merge based on the given simplified merge.

Source

pub fn resolve_trivial(&self, same_change: SameChange) -> Option<&T>
where T: Eq + Hash,

If this merge can be trivially resolved, returns the value it resolves to.

Source

pub fn pad_to(&mut self, num_sides: usize, value: &T)
where T: Clone,

Pads this merge with to the specified number of sides with the specified value. No-op if the requested size is not larger than the current size.

Source

pub fn as_slice(&self) -> &[T]

Returns a slice containing the terms. The items will alternate between positive and negative terms, starting with positive (since there’s one more of those).

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over references to the terms. The items will alternate between positive and negative terms, starting with positive (since there’s one more of those).

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

A version of Merge::iter() that iterates over mutable references.

Source

pub fn map<'a, U>(&'a self, f: impl FnMut(&'a T) -> U) -> Merge<U>

Creates a new merge by applying f to each remove and add.

Source

pub fn try_map<'a, U, E>( &'a self, f: impl FnMut(&'a T) -> Result<U, E>, ) -> Result<Merge<U>, E>

Creates a new merge by applying f to each remove and add, returning Err if freturnsErr` for any of them.

Source

pub async fn try_map_async<'a, F, U, E>( &'a self, f: impl FnMut(&'a T) -> F, ) -> Result<Merge<U>, E>
where F: Future<Output = Result<U, E>>,

Creates a new merge by applying the async function f to each remove and add, running them concurrently, and returning Err if freturnsErr` for any of them.

Source§

impl<T> Merge<Option<T>>

Source

pub fn absent() -> Self

Creates a resolved merge with a value of None.

Source

pub fn normal(value: T) -> Self

Creates a resolved merge with a value of Some(value).

Source

pub fn is_absent(&self) -> bool

Whether this represents a resolved value of None.

Source

pub fn is_present(&self) -> bool

The opposite of is_absent().

Source

pub fn as_normal(&self) -> Option<&T>

Returns the value if this is present and non-conflicting.

Source

pub fn into_legacy_form(self) -> (Vec<T>, Vec<T>)

Creates lists of removes and adds from a Merge by dropping None values. Note that the conversion is lossy: the order of None values is not preserved when converting back to a Merge.

Source§

impl<T: Clone> Merge<Option<&T>>

Source

pub fn cloned(&self) -> Merge<Option<T>>

Creates a new merge by cloning inner Option<&T>s.

Source§

impl<T> Merge<Merge<T>>

Source

pub fn flatten(self) -> Merge<T>

Flattens a nested merge into a regular merge.

Let’s say we have a 3-way merge of 3-way merges like this:

4 5   7 8
 3     6
   1 2
    0

Flattening that results in this 9-way merge:

4 5 0 7 8
 3 2 1 6
Source§

impl<T> Merge<Option<T>>
where T: Borrow<TreeValue>,

Source

pub fn is_tree(&self) -> bool

Whether this merge should be recursed into when doing directory walks.

Source

pub fn is_file_like(&self) -> bool

Whether this merge is present and not a tree

Source

pub fn to_file_merge(&self) -> Option<Merge<Option<FileId>>>

If this merge contains only files or absent entries, returns a merge of the FileIds. The executable bits and copy IDs will be ignored. Use Merge::with_new_file_ids() to produce a new merge with the original executable bits preserved.

Source

pub fn to_executable_merge(&self) -> Option<Merge<Option<bool>>>

If this merge contains only files or absent entries, returns a merge of the files’ executable bits.

Source

pub fn to_copy_id_merge(&self) -> Option<Merge<Option<CopyId>>>

If this merge contains only files or absent entries, returns a merge of the files’ copy IDs.

Source

pub async fn to_tree_merge( &self, store: &Arc<Store>, dir: &RepoPath, ) -> BackendResult<Option<Merge<Tree>>>

If every non-None term of a MergedTreeValue is a TreeValue::Tree, this converts it to a Merge<Tree>, with empty trees instead of any None terms. Otherwise, returns None.

Source

pub fn with_new_file_ids( &self, file_ids: &Merge<Option<FileId>>, ) -> Merge<Option<TreeValue>>

Creates a new merge with the file ids from the given merge. In other words, only the executable bits from self will be preserved.

The given file_ids should have the same shape as self. Only the FileId values may differ.

Source

pub fn describe(&self) -> String

Give a summary description of the conflict’s “removes” and “adds”

Source§

impl Merge<Tree>

Source

pub fn dir(&self) -> &RepoPath

The directory that is shared by all trees in the merge.

Source

pub fn value(&self, basename: &RepoPathComponent) -> MergedTreeVal<'_>

The value at the given basename. The value can be Resolved even if self is conflicted, which happens if the value at the path can be trivially merged. Does not recurse, so if basename refers to a Tree, then a TreeValue::Tree will be returned.

Source

pub async fn sub_tree( &self, name: &RepoPathComponent, ) -> BackendResult<Option<Self>>

Gets the Merge<Tree> in a subdirectory of the current tree. If the path doesn’t correspond to a tree in any of the inputs to the merge, then that entry will be replaced by an empty tree in the result.

Source

pub async fn sub_tree_recursive( &self, path: &RepoPath, ) -> BackendResult<Option<Self>>

Look up the tree at the given path.

Trait Implementations§

Source§

impl<T: Clone> Clone for Merge<T>

Source§

fn clone(&self) -> Merge<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: ContentHash> ContentHash for Merge<T>

Source§

fn hash(&self, state: &mut impl DigestUpdate)

Update the hasher state with this object’s content
Source§

impl<T: Debug> Debug for Merge<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T: Hash> Hash for Merge<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> IntoIterator for Merge<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<[T; 1]>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq> PartialEq for Merge<T>

Source§

fn eq(&self, other: &Merge<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Serialize for Merge<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Eq> Eq for Merge<T>

Source§

impl<T> StructuralPartialEq for Merge<T>

Auto Trait Implementations§

§

impl<T> Freeze for Merge<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Merge<T>
where T: RefUnwindSafe,

§

impl<T> Send for Merge<T>
where T: Send,

§

impl<T> Sync for Merge<T>
where T: Sync,

§

impl<T> Unpin for Merge<T>
where T: Unpin,

§

impl<T> UnwindSafe for Merge<T>

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
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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