From 6e6ca16fd4aade973c1ae6952e7c4668a7d3b0be Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 12 Jun 2023 13:16:45 -0700 Subject: [PATCH] tree: make `try_resolve_file_conflict()` write resolved file to store The function takes a `&Conflict>` argument so it seems it should return an `Option` for symmetry. --- lib/src/tree.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/src/tree.rs b/lib/src/tree.rs index e39d59f75..5de239178 100644 --- a/lib/src/tree.rs +++ b/lib/src/tree.rs @@ -633,11 +633,8 @@ fn merge_tree_value( // A single add means that the current state is that state. return Ok(conflict.adds()[0].clone()); } - if let Some((merged_content, executable)) = - try_resolve_file_conflict(store, &filename, &conflict)? - { - let id = store.write_file(&filename, &mut merged_content.as_slice())?; - Some(TreeValue::File { id, executable }) + if let Some(tree_value) = try_resolve_file_conflict(store, &filename, &conflict)? { + Some(tree_value) } else { let conflict_id = store.write_conflict(&filename, &conflict)?; Some(TreeValue::Conflict(conflict_id)) @@ -650,7 +647,7 @@ fn try_resolve_file_conflict( store: &Store, filename: &RepoPath, conflict: &Conflict>, -) -> Result, bool)>, TreeMergeError> { +) -> Result, TreeMergeError> { // If there are any non-file or any missing parts in the conflict, we can't // merge it. We check early so we don't waste time reading file contents if // we can't merge them anyway. At the same time we determine whether the @@ -717,7 +714,13 @@ fn try_resolve_file_conflict( &added_contents.iter().map(Vec::as_slice).collect_vec(), ); match merge_result { - MergeResult::Resolved(merged_content) => Ok(Some((merged_content, *executable))), + MergeResult::Resolved(merged_content) => { + let id = store.write_file(filename, &mut merged_content.as_slice())?; + Ok(Some(TreeValue::File { + id, + executable: *executable, + })) + } MergeResult::Conflict(_) => Ok(None), } }