mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-20 11:25:34 +00:00
merge: add .cloned() method that maps inner Option<&T> to Option<T>
MergedTreeVal::to_merge() will be replaced with this.
This commit is contained in:
parent
e2ab6d4f42
commit
accd1e337a
2 changed files with 10 additions and 3 deletions
|
@ -464,6 +464,13 @@ impl<T> Merge<Option<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Clone> Merge<Option<&T>> {
|
||||
/// Creates a new merge by cloning inner `Option<&T>`s.
|
||||
pub fn cloned(&self) -> Merge<Option<T>> {
|
||||
self.map(|value| value.cloned())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Merge<Merge<T>> {
|
||||
/// Flattens a nested merge into a regular merge.
|
||||
///
|
||||
|
|
|
@ -381,7 +381,7 @@ fn all_tree_entries(
|
|||
let iter = all_merged_tree_entries(trees).map(|(name, values)| {
|
||||
let value = match values.resolve_trivial() {
|
||||
Some(resolved) => MergedTreeVal::Resolved(*resolved),
|
||||
None => MergedTreeVal::Conflict(values.map(|value| value.cloned())),
|
||||
None => MergedTreeVal::Conflict(values.cloned()),
|
||||
};
|
||||
(name, value)
|
||||
});
|
||||
|
@ -441,7 +441,7 @@ fn trees_value<'a>(trees: &'a Merge<Tree>, basename: &RepoPathComponent) -> Merg
|
|||
if let Some(resolved) = value.resolve_trivial() {
|
||||
return MergedTreeVal::Resolved(*resolved);
|
||||
}
|
||||
MergedTreeVal::Conflict(value.map(|x| x.cloned()))
|
||||
MergedTreeVal::Conflict(value.cloned())
|
||||
}
|
||||
|
||||
/// The returned conflict will either be resolved or have the same number of
|
||||
|
@ -522,7 +522,7 @@ fn merge_tree_values(
|
|||
Ok(Merge::normal(resolved))
|
||||
} else {
|
||||
// Failed to merge the files, or the paths are not files
|
||||
Ok(values.map(|value| value.cloned()))
|
||||
Ok(values.cloned())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue