conflicts: change diff line marker to %%%%%%%

I feel the original -------/+++++++ pair is slightly confusing because
each half can be a separator by itself. I don't know what character other
than '-'/'+' is preferred, but let's pick '%' (for "mod") per @martinvonz
suggestion.
This commit is contained in:
Yuya Nishihara 2022-09-20 12:31:20 +09:00
parent 6e8f822901
commit 16f2b82feb
8 changed files with 46 additions and 46 deletions

View file

@ -87,8 +87,7 @@ how that would look for the same example as above:
``` ```
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
apple apple
-grape -grape
+grapefruit +grapefruit
@ -101,9 +100,8 @@ ORANGE
``` ```
As in Git, the `<<<<<<<` and `>>>>>>>` lines mark the start and end of the As in Git, the `<<<<<<<` and `>>>>>>>` lines mark the start and end of the
conflict. The `-------` followed by `+++++++` indicates the start of a diff conflict. The `%%%%%%%` line indicates the start of a diff. The `+++++++`
(there is never content between the two header lines). A header consisting of line indicates the start of a snapshot (not a diff).
only `+++++++` indicates the start of a snapshot (not a diff).
There is another reason for this format (in addition to helping you spot the There is another reason for this format (in addition to helping you spot the
differences): The format supports more complex conflicts involving more than 3 differences): The format supports more complex conflicts involving more than 3

View file

@ -234,8 +234,7 @@ There are unresolved conflicts at these paths:
file1 file1
$ cat file1 $ cat file1
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
-b1 -b1
+a +a
+++++++ +++++++

View file

@ -25,6 +25,7 @@ use crate::store::Store;
const CONFLICT_START_LINE: &[u8] = b"<<<<<<<\n"; const CONFLICT_START_LINE: &[u8] = b"<<<<<<<\n";
const CONFLICT_END_LINE: &[u8] = b">>>>>>>\n"; const CONFLICT_END_LINE: &[u8] = b">>>>>>>\n";
const CONFLICT_DIFF_LINE: &[u8] = b"%%%%%%%\n";
const CONFLICT_MINUS_LINE: &[u8] = b"-------\n"; const CONFLICT_MINUS_LINE: &[u8] = b"-------\n";
const CONFLICT_PLUS_LINE: &[u8] = b"+++++++\n"; const CONFLICT_PLUS_LINE: &[u8] = b"+++++++\n";
@ -181,8 +182,7 @@ pub fn materialize_conflict(
.iter() .iter()
.position_min_by_key(|diff| diff_size(diff)) .position_min_by_key(|diff| diff_size(diff))
.unwrap(); .unwrap();
output.write_all(CONFLICT_MINUS_LINE)?; output.write_all(CONFLICT_DIFF_LINE)?;
output.write_all(CONFLICT_PLUS_LINE)?;
write_diff_hunks(&diffs[min_diff_index], output)?; write_diff_hunks(&diffs[min_diff_index], output)?;
removes.remove(0); removes.remove(0);
adds.remove(min_diff_index); adds.remove(min_diff_index);
@ -278,15 +278,26 @@ pub fn parse_conflict(input: &[u8], num_removes: usize, num_adds: usize) -> Opti
} }
fn parse_conflict_hunk(input: &[u8]) -> MergeHunk { fn parse_conflict_hunk(input: &[u8]) -> MergeHunk {
let mut diff_seen = false;
let mut minus_seen = false; let mut minus_seen = false;
let mut plus_seen = false; let mut plus_seen = false;
let mut body_seen = false; let mut body_seen = false;
let mut removes = vec![]; let mut removes = vec![];
let mut adds = vec![]; let mut adds = vec![];
for line in input.split_inclusive(|b| *b == b'\n') { for line in input.split_inclusive(|b| *b == b'\n') {
if line == CONFLICT_MINUS_LINE { if line == CONFLICT_DIFF_LINE {
diff_seen = true;
if body_seen {
minus_seen = false;
plus_seen = false;
body_seen = false;
}
removes.push(vec![]);
adds.push(vec![]);
} else if line == CONFLICT_MINUS_LINE {
minus_seen = true; minus_seen = true;
if body_seen { if body_seen {
diff_seen = false;
plus_seen = false; plus_seen = false;
body_seen = false; body_seen = false;
} }
@ -294,11 +305,12 @@ fn parse_conflict_hunk(input: &[u8]) -> MergeHunk {
} else if line == CONFLICT_PLUS_LINE { } else if line == CONFLICT_PLUS_LINE {
plus_seen = true; plus_seen = true;
if body_seen { if body_seen {
diff_seen = false;
minus_seen = false; minus_seen = false;
body_seen = false; body_seen = false;
} }
adds.push(vec![]); adds.push(vec![]);
} else if minus_seen && plus_seen { } else if diff_seen {
body_seen = true; body_seen = true;
if let Some(rest) = line.strip_prefix(b"-") { if let Some(rest) = line.strip_prefix(b"-") {
removes.last_mut().unwrap().extend_from_slice(rest); removes.last_mut().unwrap().extend_from_slice(rest);

View file

@ -87,8 +87,7 @@ line 5
line 1 line 1
line 2 line 2
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
-line 3 -line 3
+right 3.1 +right 3.1
+++++++ +++++++
@ -108,8 +107,7 @@ line 5
line 1 line 1
line 2 line 2
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
-line 3 -line 3
+right 3.1 +right 3.1
+++++++ +++++++
@ -185,8 +183,7 @@ line 5
line 1 line 1
line 2 line 2
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
-line 3 -line 3
+++++++ +++++++
left left
@ -262,8 +259,7 @@ line 5
line 1 line 1
line 2 line 2
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
-line 3 -line 3
+++++++ +++++++
right right
@ -297,8 +293,7 @@ fn test_parse_conflict_simple() {
parse_conflict( parse_conflict(
b"line 1 b"line 1
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
line 2 line 2
-line 3 -line 3
+left +left
@ -328,16 +323,14 @@ fn test_parse_conflict_multi_way() {
parse_conflict( parse_conflict(
b"line 1 b"line 1
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
line 2 line 2
-line 3 -line 3
+left +left
line 4 line 4
+++++++ +++++++
right right
------- %%%%%%%
+++++++
line 2 line 2
+forward +forward
line 3 line 3
@ -372,8 +365,7 @@ fn test_parse_conflict_different_wrong_arity() {
parse_conflict( parse_conflict(
b"line 1 b"line 1
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
line 2 line 2
-line 3 -line 3
+left +left
@ -392,8 +384,7 @@ line 5
#[test] #[test]
fn test_parse_conflict_malformed_marker() { fn test_parse_conflict_malformed_marker() {
// The conflict marker is missing `-------` and `+++++++` (it needs at least one // The conflict marker is missing `%%%%%%%`
// of them)
assert_eq!( assert_eq!(
parse_conflict( parse_conflict(
b"line 1 b"line 1
@ -421,8 +412,7 @@ fn test_parse_conflict_malformed_diff() {
parse_conflict( parse_conflict(
b"line 1 b"line 1
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
line 2 line 2
-line 3 -line 3
+left +left
@ -490,7 +480,13 @@ fn test_update_conflict_from_content() {
assert_eq!(result, None); assert_eq!(result, None);
// If the conflict is partially resolved, we get a new conflict back. // If the conflict is partially resolved, we get a new conflict back.
let result = update_conflict_from_content(store, &path, &conflict_id, b"resolved 1\nline 2\n<<<<<<<\n-------\n+++++++\n-line 3\n+left 3\n+++++++\nright 3\n>>>>>>>\n").unwrap(); let result = update_conflict_from_content(
store,
&path,
&conflict_id,
b"resolved 1\nline 2\n<<<<<<<\n%%%%%%%\n-line 3\n+left 3\n+++++++\nright 3\n>>>>>>>\n",
)
.unwrap();
assert_ne!(result, None); assert_ne!(result, None);
assert_ne!(result, Some(conflict_id)); assert_ne!(result, Some(conflict_id));
let new_conflict = store.read_conflict(&path, &result.unwrap()).unwrap(); let new_conflict = store.read_conflict(&path, &result.unwrap()).unwrap();

View file

@ -154,10 +154,9 @@ fn test_interdiff_conflicting() {
index f845ab93f0...24c5735c3e 100644 index f845ab93f0...24c5735c3e 100644
--- a/file --- a/file
+++ b/file +++ b/file
@@ -1,8 +1,1 @@ @@ -1,7 +1,1 @@
-<<<<<<< -<<<<<<<
-------- -%%%%%%%
-+++++++
--foo --foo
-+abc -+abc
-+++++++ -+++++++

View file

@ -52,10 +52,9 @@ fn test_obslog_with_or_without_diff() {
| my description | my description
| Resolved conflict in file1: | Resolved conflict in file1:
| 1 1: <<<<<<<resolved | 1 1: <<<<<<<resolved
| 2 : ------- | 2 : %%%%%%%
| 3 : +++++++ | 3 : +bar
| 4 : +bar | 4 : >>>>>>>
| 5 : >>>>>>>
o 813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict o 813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict
| my description | my description
o 8f02f5470c55 test.user@example.com 2001-02-03 04:05:08.000 +07:00 o 8f02f5470c55 test.user@example.com 2001-02-03 04:05:08.000 +07:00
@ -91,10 +90,9 @@ fn test_obslog_with_or_without_diff() {
index e155302a24...2ab19ae607 100644 index e155302a24...2ab19ae607 100644
--- a/file1 --- a/file1
+++ b/file1 +++ b/file1
@@ -1,5 +1,1 @@ @@ -1,4 +1,1 @@
-<<<<<<< -<<<<<<<
-------- -%%%%%%%
-+++++++
-+bar -+bar
->>>>>>> ->>>>>>>
+resolved +resolved

View file

@ -61,8 +61,7 @@ fn test_print() {
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]); let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
-b -b
+a +a
+++++++ +++++++

View file

@ -140,8 +140,7 @@ fn test_touchup_merge() {
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]); let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
<<<<<<< <<<<<<<
------- %%%%%%%
+++++++
-a -a
+c +c
+++++++ +++++++