Skip to content

Commit 8f1f404

Browse files
committed
Use $marker_length to correctly parse conflict markers
Since Jujutsu v0.25.0, conflict markers are now allowed to be longer than 7 characters. The new `$marker_length` variable can be used to pass the length of the markers to the merge tool. In order to support longer conflict markers, the `merge-args` setting for jj-diffconflicts needs to be updated to pass the marker length: merge-args = [ "-c", "let g:jj_diffconflicts_marker_length=$marker_length", "-c", "JJDiffConflicts!", "$output", "$base", "$left", "$right" ] But unless long conflict markers are used, jj-diffconflicts should still work without the use of `$marker_length`, or with Jujutsu versions older than v0.25.0. References: - https://jj-vcs.github.io/jj/latest/conflicts/#long-conflict-markers - https://jj-vcs.github.io/jj/v0.25.0/config/#setting-up-a-custom-merge-tool - https://github.com/jj-vcs/jj/releases/tag/v0.25.0
1 parent 2822ed9 commit 8f1f404

File tree

5 files changed

+49
-13
lines changed

5 files changed

+49
-13
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ To configure as a merge tool in Jujutsu, add the following to your [Jujutsu conf
3939
```toml
4040
[merge-tools.diffconflicts]
4141
program = "nvim"
42-
merge-args = ["-c", "JJDiffConflicts!", "$output", "$base", "$left", "$right"]
42+
merge-args = [
43+
"-c", "let g:jj_diffconflicts_marker_length=$marker_length",
44+
"-c", "JJDiffConflicts!", "$output", "$base", "$left", "$right",
45+
]
4346
merge-tool-edits-conflict-markers = true
4447
```
4548

@@ -54,14 +57,17 @@ If you don't want to use the history view, you can instead set `merge-args` to `
5457

5558
## Test repository
5659

57-
The `make-conflicts.sh` script creates a Jujutsu repository in the `testrepo` directory whose working copy has two conflicted files.
60+
The `make-conflicts.sh` script creates a Jujutsu repository in the `testrepo` directory whose working copy has conflicted files.
5861
It can be used to try `jj-diffconflicts` (or any other merge tool).
5962

6063
The first file is `fruits.txt`, which contains the merge conflict described in the [Conflicts][] section of Jujutsu's documentation.
6164

6265
The second file is `poem.txt`, which contains a tricky merge conflict.
6366
When resolving it, one should keep in mind the points from the [merge tools benchmarks][] to judge its effectiveness.
6467

68+
The third file is `long_markers.txt`, which the contains the merge conflict described in the [Long conflict markers][] section of the Jujutsu's documentation.
69+
It can be used to test if the merge tool can handle markers of length higher than the default value.
70+
6571
## Troubleshooting
6672

6773
The plugin includes a health check to detect potential issues that would prevent it from functioning properly.
@@ -97,6 +103,7 @@ _Caveat emptor_
97103
[diffconflicts]: https://github.com/whiteinge/diffconflicts/
98104
[jujutsu configuration]: https://jj-vcs.github.io/jj/latest/config/
99105
[jujutsu]: https://jj-vcs.github.io/jj/
106+
[long conflict markers]: https://jj-vcs.github.io/jj/latest/conflicts/#long-conflict-markers
100107
[merge tools benchmarks]: https://github.com/whiteinge/diffconflicts/blob/master/_utils/README.md#mergetool-benchmarks
101108
[neovim]: https://neovim.io/
102109
[short video]: https://www.youtube.com/watch?v=Pxgl3Wtf78Y

doc/jj-diffconflicts.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ To configure this plugin as a merge tool in Jujutsu, add the following to your
1111
Jujutsu configuration:
1212
>
1313
[merge-tools.diffconflicts]
14-
merge-args = ["-c", "JJDiffConflicts!", "$output", "$base", "$left", "$right"]
15-
merge-tool-edits-conflict-markers = true
1614
program = "nvim"
15+
merge-args = [
16+
"-c", "let g:jj_diffconflicts_marker_length=$marker_length",
17+
"-c", "JJDiffConflicts!", "$output", "$base", "$left", "$right",
18+
]
19+
merge-tool-edits-conflict-markers = true
1720
<
1821
It can then be invoked with `jj resolve --tool diffconflicts`.
1922

@@ -33,6 +36,11 @@ Command ~
3336
files. This requires the `$base`, `$left`, and `$right` files being passed
3437
as arguments when opening Neovim as a merge tool.
3538

39+
If a [count] is given, then it is used as the length of the conflict
40+
markers. This can be useful when running the command directly instead of
41+
invoking it through `jj resolve`. If no [count] is given, then the merge
42+
tool will use the default length of 7 to parse conflict markers.
43+
3644
See also: |g:jj_diffconflicts_no_command|
3745

3846

lua/jj-diffconflicts/init.lua

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ local PATTERNS = nil
1818
-- conflict resolution UI. If the `show_history` argument is true, then it also
1919
-- includes a history view that displays the two sides of the conflict and
2020
-- their ancestor.
21-
M.run = function(show_history)
21+
M.run = function(show_history, marker_length)
2222
local ok, jj_version = pcall(M.get_jj_version)
2323
if not ok then
2424
vim.notify(
@@ -27,7 +27,14 @@ M.run = function(show_history)
2727
)
2828
jj_version = { math.huge, math.huge, math.huge }
2929
end
30-
h.set_patterns(jj_version)
30+
31+
if marker_length == 0 or marker_length == nil then
32+
marker_length = vim.g.jj_diffconflicts_marker_length
33+
if marker_length == "" or marker_length == nil then
34+
marker_length = 7
35+
end
36+
end
37+
h.set_patterns(jj_version, marker_length)
3138

3239
local ok, raw_conflict = pcall(h.extract_conflict)
3340
if not ok then
@@ -74,12 +81,12 @@ end
7481
-- Define regular expression patterns to be used to detect conflict markers. We
7582
-- cannot just define them as constants, since they can vary based on Jujutsu's
7683
-- version.
77-
h.set_patterns = function(jj_version)
84+
h.set_patterns = function(jj_version, marker_length)
7885
local marker = {
79-
top = "<<<<<<<",
80-
bottom = ">>>>>>>",
81-
diff = "%%%%%%%",
82-
snapshot = "+++++++",
86+
top = string.rep("<", marker_length),
87+
bottom = string.rep(">", marker_length),
88+
diff = string.rep("%", marker_length),
89+
snapshot = string.rep("+", marker_length),
8390
}
8491

8592
if vim.version.lt(jj_version, { 0, 18, 0 }) then

make-conflicts.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ apple
3030
grape
3131
orange
3232
EOF
33+
cat <<EOF >long_markers.txt
34+
Heading
35+
=======
36+
EOF
3337
${JJ} bookmark create base
3438
${JJ} commit -m 'Initial revision'
3539

@@ -50,6 +54,10 @@ apple
5054
grapefruit
5155
orange
5256
EOF
57+
cat <<EOF >long_markers.txt
58+
HEADING
59+
=======
60+
EOF
5361
${JJ} bookmark create left
5462
${JJ} describe -m 'Fix syntax mistakes, eat grapefruit'
5563

@@ -71,6 +79,10 @@ APPLE
7179
GRAPE
7280
ORANGE
7381
EOF
82+
cat <<EOF >long_markers.txt
83+
New Heading
84+
===========
85+
EOF
7486
${JJ} bookmark create right
7587
${JJ} describe -m 'Fix syntax mistakes, ALL CAPS fruits'
7688

plugin/jj_diffconflicts.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
if vim.g.jj_diffconflicts_no_command == nil then
22
vim.api.nvim_create_user_command("JJDiffConflicts", function(opts)
33
local show_history = opts.bang
4-
require("jj-diffconflicts").run(show_history)
4+
local marker_length = opts.count
5+
require("jj-diffconflicts").run(show_history, marker_length)
56
end, {
67
desc = "Resolve Jujutsu merge conflicts",
7-
bang = true,
8+
bang = true, -- used to enable "history" view
9+
count = true, -- used to supply marker length
810
})
911
end

0 commit comments

Comments
 (0)