Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conflicts: add "ui.conflict-marker-style" config #4897

Merged
merged 8 commits into from
Nov 23, 2024

Conversation

scott2000
Copy link
Contributor

@scott2000 scott2000 commented Nov 17, 2024

Resolves #823.

Adds support for "diff" (current default), "snapshot", and "git-diff3" (falls back to "diff" if more than 2 sides) options.

Example of "diff"

<<<<<<< Conflict 1 of 1
+++++++ Contents of side #1
fn example(word: String) {
    println!("word is {word}");
%%%%%%% Changes from base to side #2
-fn example(w: String) {
+fn example(w: &str) {
     println!("word is {w}");
>>>>>>> Conflict 1 of 1 ends
}

Example of "snapshot"

<<<<<<< Conflict 1 of 1
+++++++ Contents of side #1
fn example(word: String) {
    println!("word is {word}");
------- Contents of base
fn example(w: String) {
    println!("word is {w}");
+++++++ Contents of side #2
fn example(w: &str) {
    println!("word is {w}");
>>>>>>> Conflict 1 of 1 ends
}

Example of "git"

<<<<<<< Side #1 (Conflict 1 of 1)
fn example(word: String) {
    println!("word is {word}");
||||||| Base
fn example(w: String) {
    println!("word is {w}");
=======
fn example(w: &str) {
    println!("word is {w}");
>>>>>>> Side #2 (Conflict 1 of 1 ends)
}

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@scott2000 scott2000 force-pushed the conflict-marker-style branch 4 times, most recently from 6bb9f91 to 3588eac Compare November 17, 2024 16:26
@tim-janik
Copy link
Contributor

Example of "snapshot"

+1 for supporting the "snapshot" markers.

@scott2000 scott2000 force-pushed the conflict-marker-style branch from 3588eac to 381aba9 Compare November 17, 2024 17:22
Copy link
Member

@martinvonz martinvonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't reviewd the last two commits, but I've read the commit message for them and it sounds like you didn't miss anything (in particular, it would have been easy to miss that we want support for parsing either style regardless of configured style).

lib/src/conflicts.rs Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
lib/src/conflicts.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@scott2000 scott2000 force-pushed the conflict-marker-style branch 2 times, most recently from 6aed3c0 to bfdf68b Compare November 17, 2024 21:38
@martinvonz
Copy link
Member

Let me know when this is ready for review. (I don't think I get a notification when a PR is marked ready.)

@scott2000 scott2000 force-pushed the conflict-marker-style branch from bfdf68b to c0181bd Compare November 18, 2024 03:15
cli/src/diff_util.rs Outdated Show resolved Hide resolved
@scott2000 scott2000 force-pushed the conflict-marker-style branch 4 times, most recently from 4a03751 to c1207f8 Compare November 20, 2024 01:28
@scott2000 scott2000 marked this pull request as ready for review November 20, 2024 01:34
@scott2000
Copy link
Contributor Author

Ok, I think it's ready for review now! Let me know if I should split some of these commits into separate PRs.

Copy link
Contributor

@ilyagr ilyagr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a clever approach, it's simpler than what I was thinking (allowing other conflict styles only in a jj file edit command). I was worried for a bit that this would make #3975 worse, but I currently think that it's probably manageable and might be worth the complexity. I wrote down some related thoughts in case they spark anybody else's thinking.

cli/src/config-schema.json Show resolved Hide resolved
cli/src/config-schema.json Show resolved Hide resolved
cli/src/config-schema.json Outdated Show resolved Hide resolved
cli/src/config-schema.json Show resolved Hide resolved
lib/src/local_working_copy.rs Outdated Show resolved Hide resolved
lib/src/conflicts.rs Show resolved Hide resolved
lib/src/conflicts.rs Outdated Show resolved Hide resolved
@scott2000 scott2000 force-pushed the conflict-marker-style branch 2 times, most recently from da58564 to bb19e68 Compare November 21, 2024 04:00
lib/src/conflicts.rs Outdated Show resolved Hide resolved
@scott2000 scott2000 force-pushed the conflict-marker-style branch 2 times, most recently from 323b1e0 to 7213011 Compare November 22, 2024 04:36
Copy link
Member

@martinvonz martinvonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this PR! I know a lot of people want this feature.

CHANGELOG.md Outdated Show resolved Hide resolved
lib/tests/test_conflicts.rs Outdated Show resolved Hide resolved
lib/tests/test_conflicts.rs Show resolved Hide resolved
lib/src/conflicts.rs Outdated Show resolved Hide resolved
cli/src/config/merge_tools.toml Outdated Show resolved Hide resolved
docs/conflicts.md Outdated Show resolved Hide resolved
docs/conflicts.md Outdated Show resolved Hide resolved
lib/src/annotate.rs Outdated Show resolved Hide resolved
lib/src/default_index/revset_engine.rs Outdated Show resolved Hide resolved
lib/src/settings.rs Outdated Show resolved Hide resolved
lib/src/local_working_copy.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@yuja yuja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split the merge-tools patches to separate PR because this PR is getting bigger.

lib/src/conflicts.rs Outdated Show resolved Hide resolved
lib/src/conflicts.rs Outdated Show resolved Hide resolved
lib/src/conflicts.rs Show resolved Hide resolved
cli/tests/test_config_command.rs Outdated Show resolved Hide resolved
lib/src/conflicts.rs Show resolved Hide resolved
@scott2000 scott2000 force-pushed the conflict-marker-style branch from 7213011 to 6d643ce Compare November 22, 2024 23:20
@scott2000 scott2000 force-pushed the conflict-marker-style branch 3 times, most recently from 45280c7 to ceb25d7 Compare November 23, 2024 00:49
@scott2000 scott2000 force-pushed the conflict-marker-style branch from ceb25d7 to 362d6f4 Compare November 23, 2024 01:32
lib/src/conflicts.rs Show resolved Hide resolved
lib/src/conflicts.rs Show resolved Hide resolved
Adds a new "ui.conflict-marker-style" config option. The "diff" option
is the default jj-style conflict markers with a snapshot and a series of
diffs to apply to the snapshot. New conflict marker style options will
be added in later commits.

The majority of the changes in this commit are from passing the config
option down to the code that materializes the conflicts.

Example of "diff" conflict markers:

```
<<<<<<< Conflict 1 of 1
+++++++ Contents of side jj-vcs#1
fn example(word: String) {
    println!("word is {word}");
%%%%%%% Changes from base to side jj-vcs#2
-fn example(w: String) {
+fn example(w: &str) {
     println!("word is {w}");
>>>>>>> Conflict 1 of 1 ends
}
```
This makes the code a bit easier to follow in my opinion.
This will make it easier to add separate logic for "snapshot" style
conflict markers in the next commit.
Adds a new "snapshot" conflict marker style which returns a series of
snapshots, similar to Git's "diff3" conflict style. The "snapshot"
option uses a subset of the conflict hunk headers as the "diff" option
(it just doesn't use "%%%%%%%"), meaning that the two options are
trivially compatible with each other (i.e. a file materialized with
"snapshot" can be parsed with "diff" and vice versa).

Example of "snapshot" conflict markers:

```
<<<<<<< Conflict 1 of 1
+++++++ Contents of side jj-vcs#1
fn example(word: String) {
    println!("word is {word}");
------- Contents of base
fn example(w: String) {
    println!("word is {w}");
+++++++ Contents of side jj-vcs#2
fn example(w: &str) {
    println!("word is {w}");
>>>>>>> Conflict 1 of 1 ends
}
```
This will make it easier to add a second code path for Git-style
conflicts in a later commit.
This was already possible using `merge.iter().as_slice()`, but I think
this is cleaner.
Adds a new "git" conflict marker style option. This option matches Git's
"diff3" conflict style, allowing these conflicts to be parsed by some
external tools that don't support JJ-style conflicts. If a conflict has
more than 2 sides, then it falls back to the similar "snapshot" conflict
marker style.

The conflict parsing code now supports parsing Git-style conflict
markers in addition to the normal JJ-style conflict markers, regardless
of the conflict marker style setting. This has the benefit of allowing
the user to switch the conflict marker style while they already have
conflicts checked out, and their old conflicts will still be parsed
correctly.

Example of "git" conflict markers:

```
<<<<<<< Side jj-vcs#1 (Conflict 1 of 1)
fn example(word: String) {
    println!("word is {word}");
||||||| Base
fn example(w: String) {
    println!("word is {w}");
=======
fn example(w: &str) {
    println!("word is {w}");
>>>>>>> Side jj-vcs#2 (Conflict 1 of 1 ends)
}
```
The current docs for conflict markers start out by introducing Git
"diff3" conflict markers, and then discussing how Jujutsu's conflict
markers are different from Git's. I don't think this is the best way to
explain it, because it requires the reader to first understand Git's
conflict markers before they go on to learn Jujutsu's conflict markers.
Instead, I think it's better to explain the conflict markers from
scratch with a more detailed example so that we don't assume any
particular knowledge of Git.

This structure also works better with the new config option, since we
can talk about the default option first, and then go on to explain
alternatives later.
@scott2000 scott2000 force-pushed the conflict-marker-style branch from 362d6f4 to 9f69077 Compare November 23, 2024 14:07
@scott2000 scott2000 merged commit 472fd35 into jj-vcs:main Nov 23, 2024
18 checks passed
@scott2000 scott2000 deleted the conflict-marker-style branch November 23, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow conflicts to be materialized in Git style
5 participants