From 1897f4791a4217ec8966f3eef3cfa4652b02233f Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Wed, 26 Jun 2024 15:24:13 -0700 Subject: [PATCH] conflicts: Have materialize_merge_result take the object instead of a reference --- cli/src/commands/file/show.rs | 2 +- cli/src/diff_util.rs | 4 ++-- cli/src/merge_tools/builtin.rs | 2 +- cli/src/merge_tools/external.rs | 2 +- lib/src/conflicts.rs | 6 +++--- lib/src/default_index/revset_engine.rs | 2 +- lib/src/local_working_copy.rs | 2 +- lib/tests/test_conflicts.rs | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cli/src/commands/file/show.rs b/cli/src/commands/file/show.rs index 14482bc3df..8093fc4bca 100644 --- a/cli/src/commands/file/show.rs +++ b/cli/src/commands/file/show.rs @@ -121,7 +121,7 @@ fn write_tree_entries>( io::copy(&mut reader, &mut ui.stdout_formatter().as_mut())?; } MaterializedTreeValue::FileConflict { contents, .. } => { - materialize_merge_result(&contents, &mut ui.stdout_formatter())?; + materialize_merge_result(contents, &mut ui.stdout_formatter())?; } MaterializedTreeValue::OtherConflict { id } => { ui.stdout_formatter().write_all(id.describe().as_bytes())?; diff --git a/cli/src/diff_util.rs b/cli/src/diff_util.rs index f7579ca8b5..df57f98100 100644 --- a/cli/src/diff_util.rs +++ b/cli/src/diff_util.rs @@ -857,7 +857,7 @@ fn diff_content(path: &RepoPath, value: MaterializedTreeValue) -> io::Result { let mut data = vec![]; - materialize_merge_result(&contents, &mut data) + materialize_merge_result(contents, &mut data) .expect("Failed to materialize conflict to in-memory buffer"); Ok(FileContent { is_binary: false, @@ -1173,7 +1173,7 @@ fn git_diff_part( mode = if executable { "100755" } else { "100644" }; hash = DUMMY_HASH.to_owned(); let mut data = vec![]; - materialize_merge_result(&contents, &mut data) + materialize_merge_result(contents, &mut data) .expect("Failed to materialize conflict to in-memory buffer"); content = FileContent { is_binary: false, // TODO: are we sure this is never binary? diff --git a/cli/src/merge_tools/builtin.rs b/cli/src/merge_tools/builtin.rs index 8631a567ca..853a14636a 100644 --- a/cli/src/merge_tools/builtin.rs +++ b/cli/src/merge_tools/builtin.rs @@ -212,7 +212,7 @@ fn read_file_contents( executable: _, } => { let mut buf = Vec::new(); - materialize_merge_result(&contents, &mut buf) + materialize_merge_result(contents, &mut buf) .expect("Failed to materialize conflict to in-memory buffer"); // TODO: Render the ID somehow? let contents = buf_to_file_contents(None, buf); diff --git a/cli/src/merge_tools/external.rs b/cli/src/merge_tools/external.rs index a01187b189..ef852e0917 100644 --- a/cli/src/merge_tools/external.rs +++ b/cli/src/merge_tools/external.rs @@ -159,7 +159,7 @@ pub fn run_mergetool_external( ) -> Result { let initial_output_content: Vec = if editor.merge_tool_edits_conflict_markers { let mut materialized_conflict = vec![]; - materialize_merge_result(&content, &mut materialized_conflict) + materialize_merge_result(content.clone(), &mut materialized_conflict) .expect("Writing to an in-memory buffer should never fail"); materialized_conflict } else { diff --git a/lib/src/conflicts.rs b/lib/src/conflicts.rs index 3c81ae3974..71306ac381 100644 --- a/lib/src/conflicts.rs +++ b/lib/src/conflicts.rs @@ -232,10 +232,10 @@ async fn materialize_tree_value_no_access_denied( } pub fn materialize_merge_result( - single_hunk: &Merge, + single_hunk: Merge, output: &mut dyn Write, ) -> std::io::Result<()> { - let merge_result = files::merge(single_hunk); + let merge_result = files::merge(&single_hunk); match merge_result { MergeResult::Resolved(content) => { output.write_all(&content)?; @@ -526,7 +526,7 @@ pub async fn update_from_content( // copy. let mut old_content = Vec::with_capacity(content.len()); let merge_hunk = extract_as_single_hunk(simplified_file_ids, store, path).await?; - materialize_merge_result(&merge_hunk, &mut old_content).unwrap(); + materialize_merge_result(merge_hunk, &mut old_content).unwrap(); if content == old_content { return Ok(file_ids.clone()); } diff --git a/lib/src/default_index/revset_engine.rs b/lib/src/default_index/revset_engine.rs index d84c48a333..4c6d5f4bc5 100644 --- a/lib/src/default_index/revset_engine.rs +++ b/lib/src/default_index/revset_engine.rs @@ -1272,7 +1272,7 @@ fn to_file_content(path: &RepoPath, value: MaterializedTreeValue) -> BackendResu MaterializedTreeValue::GitSubmodule(_) => Ok(vec![]), MaterializedTreeValue::FileConflict { contents, .. } => { let mut content = vec![]; - materialize_merge_result(&contents, &mut content) + materialize_merge_result(contents, &mut content) .expect("Failed to materialize conflict to in-memory buffer"); Ok(content) } diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index da2f550814..f7c5296f89 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -1475,7 +1475,7 @@ impl TreeState { executable, } => { let mut data = vec![]; - materialize_merge_result(&contents, &mut data) + materialize_merge_result(contents, &mut data) .expect("Failed to materialize conflict to in-memory buffer"); self.write_conflict(&disk_path, data, executable)? } diff --git a/lib/tests/test_conflicts.rs b/lib/tests/test_conflicts.rs index 284774455f..71d7018702 100644 --- a/lib/tests/test_conflicts.rs +++ b/lib/tests/test_conflicts.rs @@ -1023,6 +1023,6 @@ fn materialize_conflict_string( let contents = extract_as_single_hunk(conflict, store, path) .block_on() .unwrap(); - materialize_merge_result(&contents, &mut result).unwrap(); + materialize_merge_result(contents, &mut result).unwrap(); String::from_utf8(result).unwrap() }