mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-19 22:23:14 +00:00
conflicts: check earlier for edited absent part in conflict markers
With the new `Merge::iter()`, we can simplify the code a bit by combining that with `zip`. I'll simplify the last part of `update_from_content()` next.
This commit is contained in:
parent
01ac97f999
commit
f45b8052e1
@ -15,6 +15,7 @@
|
|||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::iter::zip;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
@ -336,47 +337,46 @@ pub fn update_from_content(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let contents = Merge::new(removed_content, added_content);
|
||||||
|
|
||||||
|
// If the user edited the empty placeholder for an absent side, we consider the
|
||||||
|
// conflict resolved.
|
||||||
|
if zip(contents.iter(), file_ids.iter())
|
||||||
|
.any(|(content, file_id)| file_id.is_none() && !content.is_empty())
|
||||||
|
{
|
||||||
|
let file_id = store.write_file(path, &mut &content[..])?;
|
||||||
|
return Ok(Merge::normal(file_id));
|
||||||
|
}
|
||||||
|
|
||||||
// Now write the new files contents we found by parsing the file
|
// Now write the new files contents we found by parsing the file
|
||||||
// with conflict markers. Update the Merge object with the new
|
// with conflict markers. Update the Merge object with the new
|
||||||
// FileIds.
|
// FileIds.
|
||||||
let mut new_removes = vec![];
|
let mut new_removes = vec![];
|
||||||
for (i, buf) in removed_content.iter().enumerate() {
|
for (i, buf) in contents.removes().iter().enumerate() {
|
||||||
match &file_ids.removes()[i] {
|
match &file_ids.removes()[i] {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
let file_id = store.write_file(path, &mut buf.as_slice())?;
|
let file_id = store.write_file(path, &mut buf.as_slice())?;
|
||||||
new_removes.push(Some(file_id));
|
new_removes.push(Some(file_id));
|
||||||
}
|
}
|
||||||
None if buf.is_empty() => {
|
None => {
|
||||||
// The missing side of a conflict is still represented by
|
// The missing side of a conflict is still represented by
|
||||||
// the empty string we materialized it as
|
// the empty string we materialized it as
|
||||||
new_removes.push(None);
|
new_removes.push(None);
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
// The user edited the empty placeholder for an absent side. We consider the
|
|
||||||
// conflict resolved.
|
|
||||||
let file_id = store.write_file(path, &mut &content[..])?;
|
|
||||||
return Ok(Merge::normal(file_id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut new_adds = vec![];
|
let mut new_adds = vec![];
|
||||||
for (i, buf) in added_content.iter().enumerate() {
|
for (i, buf) in contents.adds().iter().enumerate() {
|
||||||
match &file_ids.adds()[i] {
|
match &file_ids.adds()[i] {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
let file_id = store.write_file(path, &mut buf.as_slice())?;
|
let file_id = store.write_file(path, &mut buf.as_slice())?;
|
||||||
new_adds.push(Some(file_id));
|
new_adds.push(Some(file_id));
|
||||||
}
|
}
|
||||||
None if buf.is_empty() => {
|
None => {
|
||||||
// The missing side of a conflict is still represented by
|
// The missing side of a conflict is still represented by
|
||||||
// the empty string we materialized it as => nothing to do
|
// the empty string we materialized it as => nothing to do
|
||||||
new_adds.push(None);
|
new_adds.push(None);
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
// The user edited the empty placeholder for an absent side. We consider the
|
|
||||||
// conflict resolved.
|
|
||||||
let file_id = store.write_file(path, &mut &content[..])?;
|
|
||||||
return Ok(Merge::normal(file_id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Merge::new(new_removes, new_adds))
|
Ok(Merge::new(new_removes, new_adds))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user