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>
impl<T> Merge<T>
Sourcepub fn from_vec(values: impl Into<SmallVec<[T; 1]>>) -> Self
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.
Sourcepub fn from_removes_adds(
removes: impl IntoIterator<Item = T>,
adds: impl IntoIterator<Item = T>,
) -> Self
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.
Sourcepub fn from_legacy_form(
removes: impl IntoIterator<Item = T>,
adds: impl IntoIterator<Item = T>,
) -> Merge<Option<T>>
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.
Sourcepub fn removes(&self) -> impl ExactSizeIterator<Item = &T>
pub fn removes(&self) -> impl ExactSizeIterator<Item = &T>
The removed values, also called negative terms.
Sourcepub fn adds(&self) -> impl ExactSizeIterator<Item = &T>
pub fn adds(&self) -> impl ExactSizeIterator<Item = &T>
The added values, also called positive terms.
Sourcepub fn get_remove(&self, index: usize) -> Option<&T>
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.
Sourcepub fn get_add(&self, index: usize) -> Option<&T>
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.
Sourcepub fn swap_remove(&mut self, remove_index: usize, add_index: usize) -> (T, T)
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.
Sourcepub fn is_resolved(&self) -> bool
pub fn is_resolved(&self) -> bool
Whether this merge is resolved. Does not resolve trivial merges.
Sourcepub fn as_resolved(&self) -> Option<&T>
pub fn as_resolved(&self) -> Option<&T>
Returns the resolved value, if this merge is resolved. Does not resolve trivial merges.
Sourcepub fn into_resolved(self) -> Result<T, Self>
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.
Sourcepub fn simplify(&self) -> Self
pub fn simplify(&self) -> Self
Simplify the merge by joining diffs like A->B and B->C into A->C. Also drops trivial diffs like A->A.
Sourcepub fn update_from_simplified(self, simplified: Self) -> Selfwhere
T: PartialEq,
pub fn update_from_simplified(self, simplified: Self) -> Selfwhere
T: PartialEq,
Updates the merge based on the given simplified merge.
Sourcepub fn resolve_trivial(&self, same_change: SameChange) -> Option<&T>
pub fn resolve_trivial(&self, same_change: SameChange) -> Option<&T>
If this merge can be trivially resolved, returns the value it resolves to.
Sourcepub fn pad_to(&mut self, num_sides: usize, value: &T)where
T: Clone,
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.
Sourcepub fn as_slice(&self) -> &[T]
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).
Sourcepub fn iter(&self) -> Iter<'_, T>
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).
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
A version of Merge::iter() that iterates over mutable references.
Sourcepub fn map<'a, U>(&'a self, f: impl FnMut(&'a T) -> U) -> Merge<U>
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.
Sourcepub fn try_map<'a, U, E>(
&'a self,
f: impl FnMut(&'a T) -> Result<U, E>,
) -> Result<Merge<U>, E>
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§impl<T> Merge<Option<T>>
impl<T> Merge<Option<T>>
Sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
The opposite of is_absent().
Sourcepub fn as_normal(&self) -> Option<&T>
pub fn as_normal(&self) -> Option<&T>
Returns the value if this is present and non-conflicting.
Sourcepub fn into_legacy_form(self) -> (Vec<T>, Vec<T>)
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> Merge<Option<T>>
impl<T> Merge<Option<T>>
Sourcepub fn is_tree(&self) -> bool
pub fn is_tree(&self) -> bool
Whether this merge should be recursed into when doing directory walks.
Sourcepub fn is_file_like(&self) -> bool
pub fn is_file_like(&self) -> bool
Whether this merge is present and not a tree
Sourcepub fn to_file_merge(&self) -> Option<Merge<Option<FileId>>>
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.
Sourcepub fn to_executable_merge(&self) -> Option<Merge<Option<bool>>>
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.
Sourcepub fn to_copy_id_merge(&self) -> Option<Merge<Option<CopyId>>>
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.
Sourcepub async fn to_tree_merge(
&self,
store: &Arc<Store>,
dir: &RepoPath,
) -> BackendResult<Option<Merge<Tree>>>
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.
Sourcepub fn with_new_file_ids(
&self,
file_ids: &Merge<Option<FileId>>,
) -> Merge<Option<TreeValue>>
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§impl Merge<Tree>
impl Merge<Tree>
Sourcepub fn value(&self, basename: &RepoPathComponent) -> MergedTreeVal<'_>
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.
Sourcepub async fn sub_tree(
&self,
name: &RepoPathComponent,
) -> BackendResult<Option<Self>>
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.
Sourcepub async fn sub_tree_recursive(
&self,
path: &RepoPath,
) -> BackendResult<Option<Self>>
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: ContentHash> ContentHash for Merge<T>
impl<T: ContentHash> ContentHash for Merge<T>
Source§fn hash(&self, state: &mut impl DigestUpdate)
fn hash(&self, state: &mut impl DigestUpdate)
Source§impl<T> IntoIterator for Merge<T>
impl<T> IntoIterator for Merge<T>
impl<T: Eq> Eq for Merge<T>
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>where
T: RefUnwindSafe + UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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