Skip to content

Commit

Permalink
conflicts: inline materialize()
Browse files Browse the repository at this point in the history
The function has no callers outside the module anymore (probably since
`MaterializeTreeValue` but I haven't checked). Inlining it will help
keep error handling simple in the next commit. Otherwise we'd need to
have it return an error type wrapping both `BackendError` and
`io::Error`.
  • Loading branch information
martinvonz committed Jun 17, 2024
1 parent ca1f197 commit 66e45a7
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions lib/src/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,6 @@ pub async fn extract_as_single_hunk(
builder.build()
}

pub async fn materialize(
conflict: &MergedTreeValue,
store: &Store,
path: &RepoPath,
output: &mut dyn Write,
) -> std::io::Result<()> {
if let Some(file_merge) = conflict.to_file_merge() {
let file_merge = file_merge.simplify();
let content = extract_as_single_hunk(&file_merge, store, path).await;
materialize_merge_result(&content, output)
} else {
// Unless all terms are regular files, we can't do much better than to try to
// describe the merge.
conflict.describe(output)
}
}

/// A type similar to `MergedTreeValue` but with associated data to include in
/// e.g. the working copy or in a diff.
pub enum MaterializedTreeValue {
Expand Down Expand Up @@ -198,9 +181,18 @@ async fn materialize_tree_value_no_access_denied(
}
Err(conflict) => {
let mut contents = vec![];
materialize(&conflict, store, path, &mut contents)
.await
.expect("Failed to materialize conflict to in-memory buffer");
if let Some(file_merge) = conflict.to_file_merge() {
let file_merge = file_merge.simplify();
let content = extract_as_single_hunk(&file_merge, store, path).await;
materialize_merge_result(&content, &mut contents)
.expect("Failed to materialize conflict to in-memory buffer");
} else {
// Unless all terms are regular files, we can't do much better than to try to
// describe the merge.
conflict
.describe(&mut contents)
.expect("Failed to materialize conflict to in-memory buffer");
}
let executable = if let Some(merge) = conflict.to_executable_merge() {
merge.resolve_trivial().copied().unwrap_or_default()
} else {
Expand Down

0 comments on commit 66e45a7

Please sign in to comment.