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

🚀 Highlight merge diffs and conflict markers #189

Closed
rygwdn opened this issue May 13, 2020 · 7 comments · Fixed by #812
Closed

🚀 Highlight merge diffs and conflict markers #189

rygwdn opened this issue May 13, 2020 · 7 comments · Fixed by #812

Comments

@rygwdn
Copy link

rygwdn commented May 13, 2020

When showing a patch for a merge with --cc or -c, git will generate patch prefixes that are two characters instead of just one, (e.g. ++ or -). Delta will highlight any lines that have a leading + or - but will not highlight lines with a leading space. I believe Delta should be highlighting the lines the same way git does (e.g. by ignoring the leading space so a - line is red and a + line is green).

Sample input from git show --cc 27d2427484c6efe283671300b48b5aadc7549c8a in this repo:

commit 27d2427484c6efe283671300b48b5aadc7549c8a
Merge: 55703ed 268887c
Author: Dan Davison <dandavison7@gmail.com>
Date:   Thu Apr 16 12:11:21 2020 -0400

    Merge branch 'master' into width-calc-fix

diff --cc Cargo.lock
index 9bd779d,5be85a6..cee10bb
--- a/Cargo.lock
+++ b/Cargo.lock
@@@ -293,11 -358,15 +358,16 @@@ dependencies =
   "regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
   "shell-words 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
   "structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
-  "syntect 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+  "syntect 4.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
   "unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
 + "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
  ]

+ [[package]]
+ name = "glob"
+ version = "0.3.0"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+
  [[package]]
  name = "heck"
  version = "0.3.1"
diff --cc Cargo.toml
index 914197f,cde6620..8e33592
--- a/Cargo.toml
+++ b/Cargo.toml
@@@ -27,9 -27,8 +27,9 @@@ lazy_static = "1.4
  regex = "1.2.1"
  shell-words = "0.1.0"
  structopt = "0.2.18"
- syntect = "3.2.0"
+ syntect = "4.1.0"
  unicode-segmentation = "1.3.0"
 +unicode-width = "0.1.6"

  [dependencies.error-chain]
  version = "0.12.1"

Git native highlighting:
image

Delta highlighting:
image

@dandavison
Copy link
Owner

Hi @rygwdn, thanks very much for this. Definitely on the list! There's a stub issue #25 for this but yours is much more helpful and better fleshed-out, so I'll close that one and retain this.

@rygwdn
Copy link
Author

rygwdn commented May 15, 2020

If it helps, the syntax for this "Combined diff format" indicates that the number of @ signs in the hunk header can be used to determine the number of files being compared, and thus the number of columns that should be considered for the +, -, and space characters. e.g. @@@ -27,9 -27,8 +27,9 @@@ lazy_static = "1.4 above indicates that 2 columns are being used vs 1 column if it were @@ -27,9 -27,8 +27,9 @@ lazy_static = "1.4 or 3 if it were @@@@ -27,9 -27,8 +27,9 @@@@ lazy_static = "1.4.

Seems to me that handle_hunk_meta_line could count the number of @ symbols and return it to be handed into handle_hunk_line which would then need to read more characters in the Some(' ') case to determine if it should be highlighted. It seems like any case where the first column has + or - is already being handled reasonably so the other cases probably don't need to change. I've never done any rust dev, so I'm not 100% sure how to do this, but I might take a stab at it if you don't think you'll get to it.

@dandavison
Copy link
Owner

Hi @rygwdn, that's very helpful, thanks a lot. You'd be really welcome to have a go at this -- there's plenty of work to go around at the moment! People have been very helpful opening issues and submitting PRs recently. The one thing I'd point out is that I think it would make sense to wait until @clnoll's work adding line number display in #190 is stable because they are also modifying handle_hunk_meta_line and parse_hunk_metadata. So, no pressure/obligation, but I'll ping this ticket again once those changes to handle_hunk_meta_line are ready.

@dandavison
Copy link
Owner

dandavison commented May 15, 2020

What I mean is: you're welcome to go ahead, I just wanted you to know that handle_hunk_meta_line will be changing. So perhaps it would make sense to not worry about that part, put in a stub implementation that returns what you would want regarding the number of @s, and focus on the highlighting, given that stub.

@phil-blain
Copy link
Contributor

phil-blain commented Dec 17, 2020

Very interested in this also. For bonus points, delta could color the conflict markers (>>>>>>>, <<<<<<<<, ======= and ||||||||||| for diff3-style conflicts ) in a different color.

EDIT it's not at all obvious when reading the git diff man page, but in presence of conflicted files, git diff uses the combined diff format. This can be seen in the vanilla diff header emitted by Git, which shows "diff --cc <file>". It can optionnally show the conflict in the more verbose -c mode ("diff --combined <file>"). The difference between these two modes is only detailed in the doc of the low-level git diff-tree command.

@dandavison dandavison changed the title 🐛Does not highlight merge diffs 🚀 Highlight merge diffs and conflict markers Dec 17, 2020
dandavison added a commit that referenced this issue Nov 30, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Nov 30, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Nov 30, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Dec 3, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Dec 4, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
@dandavison
Copy link
Owner

@rygwdn @phil-blain #812 handles combined diff format and makes an attempt at styling merge conflicts appropriately.

Below are screenshots showing what the branch is doing currently; opinions welcomed. Also if you'd like to try the branch out that's always helpful.

The merge conflict handling is particularly intended for users who have set merge.conflictstyle = diff3: it diffs the ancestral commit against the two derived commits in turn. I'm not sure how merge conflicts should be styled and welcome suggestions!

image

Combined diff handling looks like this (note the 2-char-wide prefixes):

image

dandavison added a commit that referenced this issue Dec 4, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Dec 4, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Dec 4, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Dec 4, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Dec 4, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Dec 5, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Dec 5, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
dandavison added a commit that referenced this issue Dec 5, 2021
With this commit combined diff
format (https://git-scm.com/docs/git-diff#_combined_diff_format) is
handled appropriately. However, there is no special handling of merge
conflict markers.

Fixes #189, #736
@dandavison
Copy link
Owner

Handling of combined diff, and merge conflicts, has been implemented in #812. I'll release it soon; if anyone's able to test (on master) that would be fantastic.

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 a pull request may close this issue.

3 participants