mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-04 05:28:02 +00:00
conflicts: move conversion to FileId
conflict to callers
This simplifies a bit, in particular by removing the error case from `extract_file_conflict_as_single_hunk()`.
This commit is contained in:
parent
ad667d6bb5
commit
de71df2447
2 changed files with 19 additions and 19 deletions
|
@ -150,7 +150,9 @@ pub fn describe_conflict(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn to_file_conflict(conflict: &Conflict<Option<TreeValue>>) -> Option<Conflict<Option<FileId>>> {
|
||||
pub fn to_file_conflict(
|
||||
conflict: &Conflict<Option<TreeValue>>,
|
||||
) -> Option<Conflict<Option<FileId>>> {
|
||||
fn collect_file_terms(terms: &[Option<TreeValue>]) -> Option<Vec<Option<FileId>>> {
|
||||
let mut file_terms = vec![];
|
||||
for term in terms {
|
||||
|
@ -223,38 +225,36 @@ pub fn materialize_conflict(
|
|||
conflict: &Conflict<Option<TreeValue>>,
|
||||
output: &mut dyn Write,
|
||||
) -> std::io::Result<()> {
|
||||
match extract_file_conflict_as_single_hunk(store, path, conflict) {
|
||||
None => {
|
||||
// Unless all terms are regular files, we can't do much better than to try to
|
||||
// describe the conflict.
|
||||
describe_conflict(conflict, output)
|
||||
}
|
||||
Some(content) => materialize_merge_result(&content, output),
|
||||
if let Some(file_conflict) = to_file_conflict(conflict) {
|
||||
let content = extract_file_conflict_as_single_hunk(store, path, &file_conflict);
|
||||
materialize_merge_result(&content, output)
|
||||
} else {
|
||||
// Unless all terms are regular files, we can't do much better than to try to
|
||||
// describe the conflict.
|
||||
describe_conflict(conflict, output)
|
||||
}
|
||||
}
|
||||
|
||||
/// Only works if all terms of the conflict are regular, non-executable files
|
||||
pub fn extract_file_conflict_as_single_hunk(
|
||||
store: &Store,
|
||||
path: &RepoPath,
|
||||
conflict: &Conflict<Option<TreeValue>>,
|
||||
) -> Option<ConflictHunk> {
|
||||
let file_conflict = to_file_conflict(conflict)?;
|
||||
let removes_content = file_conflict
|
||||
conflict: &Conflict<Option<FileId>>,
|
||||
) -> ConflictHunk {
|
||||
let removes_content = conflict
|
||||
.removes()
|
||||
.iter()
|
||||
.map(|term| get_file_contents(store, path, term))
|
||||
.collect_vec();
|
||||
let adds_content = file_conflict
|
||||
let adds_content = conflict
|
||||
.adds()
|
||||
.iter()
|
||||
.map(|term| get_file_contents(store, path, term))
|
||||
.collect_vec();
|
||||
|
||||
Some(ConflictHunk {
|
||||
ConflictHunk {
|
||||
removes: removes_content,
|
||||
adds: adds_content,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn materialize_merge_result(
|
||||
|
|
|
@ -24,7 +24,7 @@ use itertools::Itertools;
|
|||
use jujutsu_lib::backend::{TreeId, TreeValue};
|
||||
use jujutsu_lib::conflicts::{
|
||||
describe_conflict, extract_file_conflict_as_single_hunk, materialize_merge_result,
|
||||
update_conflict_from_content,
|
||||
to_file_conflict, update_conflict_from_content,
|
||||
};
|
||||
use jujutsu_lib::gitignore::GitIgnoreFile;
|
||||
use jujutsu_lib::matchers::EverythingMatcher;
|
||||
|
@ -161,8 +161,7 @@ pub fn run_mergetool(
|
|||
None => return Err(ConflictResolveError::PathNotFoundError(repo_path.clone())),
|
||||
};
|
||||
let conflict = tree.store().read_conflict(repo_path, &conflict_id)?;
|
||||
let mut content = match extract_file_conflict_as_single_hunk(tree.store(), repo_path, &conflict)
|
||||
{
|
||||
let file_conflict = match to_file_conflict(&conflict) {
|
||||
Some(c) => c,
|
||||
_ => {
|
||||
let mut summary_bytes: Vec<u8> = vec![];
|
||||
|
@ -174,6 +173,7 @@ pub fn run_mergetool(
|
|||
));
|
||||
}
|
||||
};
|
||||
let mut content = extract_file_conflict_as_single_hunk(tree.store(), repo_path, &file_conflict);
|
||||
// We only support conflicts with 2 sides (3-way conflicts)
|
||||
if content.adds.len() > 2 {
|
||||
return Err(ConflictResolveError::ConflictTooComplicatedError {
|
||||
|
|
Loading…
Reference in a new issue