forked from mirrors/jj
conflicts: make describe() simply return string
I'll add more callers of id.describe(), and the output size wouldn't be large enough to avoid allocation by using Write API.
This commit is contained in:
parent
1ba581b37c
commit
0c14a0a9ca
3 changed files with 10 additions and 21 deletions
|
@ -296,14 +296,8 @@ impl MergeEditor {
|
|||
Ok(None) => return Err(ConflictResolveError::PathNotFound(repo_path.to_owned())),
|
||||
};
|
||||
let file_merge = conflict.to_file_merge().ok_or_else(|| {
|
||||
let mut summary_bytes: Vec<u8> = vec![];
|
||||
conflict
|
||||
.describe(&mut summary_bytes)
|
||||
.expect("Writing to an in-memory buffer should never fail");
|
||||
ConflictResolveError::NotNormalFiles(
|
||||
repo_path.to_owned(),
|
||||
String::from_utf8_lossy(summary_bytes.as_slice()).to_string(),
|
||||
)
|
||||
let summary = conflict.describe();
|
||||
ConflictResolveError::NotNormalFiles(repo_path.to_owned(), summary)
|
||||
})?;
|
||||
let simplified_file_merge = file_merge.clone().simplify();
|
||||
// We only support conflicts with 2 sides (3-way conflicts)
|
||||
|
|
|
@ -213,9 +213,7 @@ async fn materialize_tree_value_no_access_denied(
|
|||
} 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");
|
||||
contents = conflict.describe().into_bytes();
|
||||
}
|
||||
let executable = if let Some(merge) = conflict.to_executable_merge() {
|
||||
merge.resolve_trivial().copied().unwrap_or_default()
|
||||
|
|
|
@ -19,8 +19,8 @@ use std::borrow::Borrow;
|
|||
use std::collections::HashMap;
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::Formatter;
|
||||
use std::fmt::Write as _;
|
||||
use std::hash::Hash;
|
||||
use std::io::Write;
|
||||
use std::iter::zip;
|
||||
use std::slice;
|
||||
use std::sync::Arc;
|
||||
|
@ -640,19 +640,16 @@ where
|
|||
}
|
||||
|
||||
/// Give a summary description of the conflict's "removes" and "adds"
|
||||
pub fn describe(&self, file: &mut dyn Write) -> std::io::Result<()> {
|
||||
file.write_all(b"Conflict:\n")?;
|
||||
pub fn describe(&self) -> String {
|
||||
let mut buf = String::new();
|
||||
writeln!(buf, "Conflict:").unwrap();
|
||||
for term in self.removes().flatten() {
|
||||
file.write_all(
|
||||
format!(" Removing {}\n", describe_conflict_term(term.borrow())).as_bytes(),
|
||||
)?;
|
||||
writeln!(buf, " Removing {}", describe_conflict_term(term.borrow())).unwrap();
|
||||
}
|
||||
for term in self.adds().flatten() {
|
||||
file.write_all(
|
||||
format!(" Adding {}\n", describe_conflict_term(term.borrow())).as_bytes(),
|
||||
)?;
|
||||
writeln!(buf, " Adding {}", describe_conflict_term(term.borrow())).unwrap();
|
||||
}
|
||||
Ok(())
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue