Skip to content

Commit

Permalink
merge: add helper function to match Option<impl Borrow<TreeValue>>
Browse files Browse the repository at this point in the history
More callers will be added by the next commit.
  • Loading branch information
yuja committed Aug 12, 2024
1 parent accd1e3 commit 8268af9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,10 @@ where
store: &Arc<Store>,
dir: &RepoPath,
) -> BackendResult<Option<Merge<Tree>>> {
let tree_id_merge = self.maybe_map(|term| match term {
let tree_id_merge = self.maybe_map(|term| match borrow_tree_value(term.as_ref()) {
None => Some(None),
Some(value) => {
if let TreeValue::Tree(id) = value.borrow() {
Some(Some(id))
} else {
None
}
}
Some(TreeValue::Tree(id)) => Some(Some(id)),
Some(_) => None,
});
if let Some(tree_id_merge) = tree_id_merge {
let get_tree = |id: &Option<&TreeId>| -> BackendResult<Tree> {
Expand All @@ -642,6 +637,10 @@ where
}
}

fn borrow_tree_value<T: Borrow<TreeValue> + ?Sized>(term: Option<&T>) -> Option<&TreeValue> {
term.map(|value| value.borrow())
}

fn describe_conflict_term(value: &TreeValue) -> String {
match value {
TreeValue::File {
Expand Down

0 comments on commit 8268af9

Please sign in to comment.