forked from mirrors/jj
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:
parent
6e8f822901
commit
16f2b82feb
8 changed files with 46 additions and 46 deletions
|
@ -87,8 +87,7 @@ how that would look for the same example as above:
|
|||
|
||||
```
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
apple
|
||||
-grape
|
||||
+grapefruit
|
||||
|
@ -101,9 +100,8 @@ ORANGE
|
|||
```
|
||||
|
||||
As in Git, the `<<<<<<<` and `>>>>>>>` lines mark the start and end of the
|
||||
conflict. The `-------` followed by `+++++++` indicates the start of a diff
|
||||
(there is never content between the two header lines). A header consisting of
|
||||
only `+++++++` indicates the start of a snapshot (not a diff).
|
||||
conflict. The `%%%%%%%` line indicates the start of a diff. The `+++++++`
|
||||
line indicates the start of a snapshot (not a diff).
|
||||
|
||||
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
|
||||
|
|
|
@ -234,8 +234,7 @@ There are unresolved conflicts at these paths:
|
|||
file1
|
||||
$ cat file1
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
-b1
|
||||
+a
|
||||
+++++++
|
||||
|
|
|
@ -25,6 +25,7 @@ use crate::store::Store;
|
|||
|
||||
const CONFLICT_START_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_PLUS_LINE: &[u8] = b"+++++++\n";
|
||||
|
||||
|
@ -181,8 +182,7 @@ pub fn materialize_conflict(
|
|||
.iter()
|
||||
.position_min_by_key(|diff| diff_size(diff))
|
||||
.unwrap();
|
||||
output.write_all(CONFLICT_MINUS_LINE)?;
|
||||
output.write_all(CONFLICT_PLUS_LINE)?;
|
||||
output.write_all(CONFLICT_DIFF_LINE)?;
|
||||
write_diff_hunks(&diffs[min_diff_index], output)?;
|
||||
removes.remove(0);
|
||||
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 {
|
||||
let mut diff_seen = false;
|
||||
let mut minus_seen = false;
|
||||
let mut plus_seen = false;
|
||||
let mut body_seen = false;
|
||||
let mut removes = vec![];
|
||||
let mut adds = vec![];
|
||||
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;
|
||||
if body_seen {
|
||||
diff_seen = false;
|
||||
plus_seen = false;
|
||||
body_seen = false;
|
||||
}
|
||||
|
@ -294,11 +305,12 @@ fn parse_conflict_hunk(input: &[u8]) -> MergeHunk {
|
|||
} else if line == CONFLICT_PLUS_LINE {
|
||||
plus_seen = true;
|
||||
if body_seen {
|
||||
diff_seen = false;
|
||||
minus_seen = false;
|
||||
body_seen = false;
|
||||
}
|
||||
adds.push(vec![]);
|
||||
} else if minus_seen && plus_seen {
|
||||
} else if diff_seen {
|
||||
body_seen = true;
|
||||
if let Some(rest) = line.strip_prefix(b"-") {
|
||||
removes.last_mut().unwrap().extend_from_slice(rest);
|
||||
|
|
|
@ -87,8 +87,7 @@ line 5
|
|||
line 1
|
||||
line 2
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
-line 3
|
||||
+right 3.1
|
||||
+++++++
|
||||
|
@ -108,8 +107,7 @@ line 5
|
|||
line 1
|
||||
line 2
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
-line 3
|
||||
+right 3.1
|
||||
+++++++
|
||||
|
@ -185,8 +183,7 @@ line 5
|
|||
line 1
|
||||
line 2
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
-line 3
|
||||
+++++++
|
||||
left
|
||||
|
@ -262,8 +259,7 @@ line 5
|
|||
line 1
|
||||
line 2
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
-line 3
|
||||
+++++++
|
||||
right
|
||||
|
@ -297,8 +293,7 @@ fn test_parse_conflict_simple() {
|
|||
parse_conflict(
|
||||
b"line 1
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
line 2
|
||||
-line 3
|
||||
+left
|
||||
|
@ -328,16 +323,14 @@ fn test_parse_conflict_multi_way() {
|
|||
parse_conflict(
|
||||
b"line 1
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
line 2
|
||||
-line 3
|
||||
+left
|
||||
line 4
|
||||
+++++++
|
||||
right
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
line 2
|
||||
+forward
|
||||
line 3
|
||||
|
@ -372,8 +365,7 @@ fn test_parse_conflict_different_wrong_arity() {
|
|||
parse_conflict(
|
||||
b"line 1
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
line 2
|
||||
-line 3
|
||||
+left
|
||||
|
@ -392,8 +384,7 @@ line 5
|
|||
|
||||
#[test]
|
||||
fn test_parse_conflict_malformed_marker() {
|
||||
// The conflict marker is missing `-------` and `+++++++` (it needs at least one
|
||||
// of them)
|
||||
// The conflict marker is missing `%%%%%%%`
|
||||
assert_eq!(
|
||||
parse_conflict(
|
||||
b"line 1
|
||||
|
@ -421,8 +412,7 @@ fn test_parse_conflict_malformed_diff() {
|
|||
parse_conflict(
|
||||
b"line 1
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
line 2
|
||||
-line 3
|
||||
+left
|
||||
|
@ -490,7 +480,13 @@ fn test_update_conflict_from_content() {
|
|||
assert_eq!(result, None);
|
||||
|
||||
// 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, Some(conflict_id));
|
||||
let new_conflict = store.read_conflict(&path, &result.unwrap()).unwrap();
|
||||
|
|
|
@ -154,10 +154,9 @@ fn test_interdiff_conflicting() {
|
|||
index f845ab93f0...24c5735c3e 100644
|
||||
--- a/file
|
||||
+++ b/file
|
||||
@@ -1,8 +1,1 @@
|
||||
@@ -1,7 +1,1 @@
|
||||
-<<<<<<<
|
||||
--------
|
||||
-+++++++
|
||||
-%%%%%%%
|
||||
--foo
|
||||
-+abc
|
||||
-+++++++
|
||||
|
|
|
@ -52,10 +52,9 @@ fn test_obslog_with_or_without_diff() {
|
|||
| my description
|
||||
| Resolved conflict in file1:
|
||||
| 1 1: <<<<<<<resolved
|
||||
| 2 : -------
|
||||
| 3 : +++++++
|
||||
| 4 : +bar
|
||||
| 5 : >>>>>>>
|
||||
| 2 : %%%%%%%
|
||||
| 3 : +bar
|
||||
| 4 : >>>>>>>
|
||||
o 813918f7b4e6 test.user@example.com 2001-02-03 04:05:08.000 +07:00 conflict
|
||||
| my description
|
||||
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
|
||||
--- a/file1
|
||||
+++ b/file1
|
||||
@@ -1,5 +1,1 @@
|
||||
@@ -1,4 +1,1 @@
|
||||
-<<<<<<<
|
||||
--------
|
||||
-+++++++
|
||||
-%%%%%%%
|
||||
-+bar
|
||||
->>>>>>>
|
||||
+resolved
|
||||
|
|
|
@ -61,8 +61,7 @@ fn test_print() {
|
|||
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
-b
|
||||
+a
|
||||
+++++++
|
||||
|
|
|
@ -140,8 +140,7 @@ fn test_touchup_merge() {
|
|||
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
<<<<<<<
|
||||
-------
|
||||
+++++++
|
||||
%%%%%%%
|
||||
-a
|
||||
+c
|
||||
+++++++
|
||||
|
|
Loading…
Reference in a new issue