forked from mirrors/jj
files: relax requirement of merge() inputs
Most callers have Merge<ContentHunk> or Merge<Vec<u8>>.
This commit is contained in:
parent
e5b49c7d52
commit
1a387489d9
4 changed files with 13 additions and 10 deletions
|
@ -601,8 +601,7 @@ pub fn edit_merge_builtin(
|
|||
path: &RepoPath,
|
||||
content: Merge<ContentHunk>,
|
||||
) -> Result<MergedTreeId, BuiltinToolError> {
|
||||
let slices = content.map(|ContentHunk(v)| v.as_slice());
|
||||
let merge_result = files::merge(&slices);
|
||||
let merge_result = files::merge(&content);
|
||||
let sections = make_merge_sections(merge_result)?;
|
||||
let mut input = scm_record::helpers::CrosstermInput;
|
||||
let recorder = scm_record::Recorder::new(
|
||||
|
@ -1014,8 +1013,7 @@ mod tests {
|
|||
let content = extract_as_single_hunk(&merge, store, path)
|
||||
.block_on()
|
||||
.unwrap();
|
||||
let slices = content.map(|ContentHunk(buf)| buf.as_slice());
|
||||
let merge_result = files::merge(&slices);
|
||||
let merge_result = files::merge(&content);
|
||||
let sections = make_merge_sections(merge_result).unwrap();
|
||||
insta::assert_debug_snapshot!(sections, @r###"
|
||||
[
|
||||
|
|
|
@ -219,8 +219,7 @@ pub fn materialize_merge_result(
|
|||
single_hunk: &Merge<ContentHunk>,
|
||||
output: &mut dyn Write,
|
||||
) -> std::io::Result<()> {
|
||||
let slices = single_hunk.map(|content| content.0.as_slice());
|
||||
let merge_result = files::merge(&slices);
|
||||
let merge_result = files::merge(single_hunk);
|
||||
match merge_result {
|
||||
MergeResult::Resolved(content) => {
|
||||
output.write_all(&content.0)?;
|
||||
|
|
|
@ -141,9 +141,16 @@ impl<'a> Iterator for DiffLineIterator<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Maybe ContentHunk can be replaced with BString?
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct ContentHunk(pub Vec<u8>);
|
||||
|
||||
impl AsRef<[u8]> for ContentHunk {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
self.0.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for ContentHunk {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
||||
String::from_utf8_lossy(&self.0).fmt(f)
|
||||
|
@ -156,7 +163,7 @@ pub enum MergeResult {
|
|||
Conflict(Vec<Merge<ContentHunk>>),
|
||||
}
|
||||
|
||||
pub fn merge(slices: &Merge<&[u8]>) -> MergeResult {
|
||||
pub fn merge<T: AsRef<[u8]>>(slices: &Merge<T>) -> MergeResult {
|
||||
// TODO: Using the first remove as base (first in the inputs) is how it's
|
||||
// usually done for 3-way conflicts. Are there better heuristics when there are
|
||||
// more than 3 parts?
|
||||
|
@ -213,7 +220,7 @@ mod tests {
|
|||
}
|
||||
|
||||
fn merge(removes: &[&[u8]], adds: &[&[u8]]) -> MergeResult {
|
||||
super::merge(&Merge::from_removes_adds(removes.to_vec(), adds.to_vec()))
|
||||
super::merge(&Merge::from_removes_adds(removes, adds))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -454,8 +454,7 @@ pub fn try_resolve_file_conflict(
|
|||
})?;
|
||||
Ok(content)
|
||||
})?;
|
||||
let slices = contents.map(|content| content.as_slice());
|
||||
let merge_result = files::merge(&slices);
|
||||
let merge_result = files::merge(&contents);
|
||||
match merge_result {
|
||||
MergeResult::Resolved(merged_content) => {
|
||||
let id = store.write_file(filename, &mut merged_content.0.as_slice())?;
|
||||
|
|
Loading…
Reference in a new issue