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

diff-highlight: highlight range-diff #684

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jablko
Copy link

@jablko jablko commented Dec 28, 2019

Piping git range-diff through diff-highlight currently has no effect,
for two reasons:

  1. There are ANSI escapes before and after the @@ hunk headers (when
    color is enabled) which diff-highlight fails to match. One solution
    is to match both escapes (/^$COLOR*\@\@$COLOR* /). This patch
    drops the trailing space from the existing pattern instead.

  2. Unlike git log, git range-diff diffs are indented, which
    diff-highlight also fails to match. This patch allows hunk headers
    preceded by any amount of whitespace, and then skips past that
    indentation when parsing subsequent lines, by reusing the machinery
    that handles the --graph output.

Signed-off-by: Jack Bates jack@nottheoilrig.com

@gitgitgadget-git
Copy link

Welcome to GitGitGadget

Hi @jablko, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that this Pull Request has a good description, as it will be used as cover letter.

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "commit:", and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the FreeNode IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions.

If you want to see what email(s) would be sent for a submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this.

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox ("raw") file corresponding to the mail you want to reply to from the Git mailing list. If you use GMail, you can upload that raw mbox file via:

curl -g --user "<EMailAddress>:<Password>" --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

Need help?

New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join.

You may also be able to find help in real time in the developer IRC channel, #git-devel on Freenode. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

@jablko
Copy link
Author

jablko commented Dec 28, 2019

/submit

@gitgitgadget-git
Copy link

Error: User jablko is not permitted to use GitGitGadget

@dscho
Copy link
Member

dscho commented Dec 29, 2019

/allow

@gitgitgadget-git
Copy link

User jablko is now allowed to use GitGitGadget.

@dscho
Copy link
Member

dscho commented Dec 29, 2019

@jablko please note that the Git project requires your Sign-off. In the past, there have been contributions that lacked that Signed-off-by: footer and that were completely ignored as a consequence.

Piping `git range-diff` through diff-highlight currently has no effect,
for two reasons:

  1. There are ANSI escapes before and after the `@@` hunk headers (when
     color is enabled) which diff-highlight fails to match. One solution
     is to match both escapes (`/^$COLOR*\@\@$COLOR* /`). This patch
     drops the trailing space from the existing pattern instead.

  2. Unlike `git log`, `git range-diff` diffs are indented, which
     diff-highlight also fails to match. This patch allows hunk headers
     preceded by any amount of whitespace, and then skips past that
     indentation when parsing subsequent lines, by reusing the machinery
     that handles the --graph output.

Signed-off-by: Jack Bates <jack@nottheoilrig.com>
@jablko
Copy link
Author

jablko commented Dec 29, 2019

/submit

@gitgitgadget-git
Copy link

@jablko
Copy link
Author

jablko commented Dec 29, 2019

@dscho Thanks a lot for your help! I've now signed-off. ✔️

@dscho
Copy link
Member

dscho commented Jan 6, 2020

With many Git contributors trickling back in from holidays, you might want to reply to your cover letter on the mailing list, with a "gentle ping" or something like that ;-)

@dscho
Copy link
Member

dscho commented Jan 25, 2020

@jablko I still think that you may want to re-start the conversation on the Git mailing list by replying with a gentle ping.

@@ -90,7 +90,8 @@ sub handle_line {

Choose a reason for hiding this comment

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

On the Git mailing list, Jeff King wrote (reply to this):

On Sun, Dec 29, 2019 at 03:49:50PM +0000, Jack Bates via GitGitGadget wrote:

> From: Jack Bates <jack@nottheoilrig.com>
> 
> Piping `git range-diff` through diff-highlight currently has no effect,
> for two reasons:

Sorry for the slow review; this got overlooked over the holidays.

>   1. There are ANSI escapes before and after the `@@` hunk headers (when
>      color is enabled) which diff-highlight fails to match. One solution
>      is to match both escapes (`/^$COLOR*\@\@$COLOR* /`). This patch
>      drops the trailing space from the existing pattern instead.

Hmm. Matching $COLOR on either side would be stricter. In particular,
with your patch I think we'd match "@@@", undoing 3dbfe2b8ae
(diff-highlight: avoid highlighting combined diffs, 2016-08-31).

>   2. Unlike `git log`, `git range-diff` diffs are indented, which
>      diff-highlight also fails to match. This patch allows hunk headers
>      preceded by any amount of whitespace, and then skips past that
>      indentation when parsing subsequent lines, by reusing the machinery
>      that handles the --graph output.

This also means we'd start trying to highlight diffs that are inside
commit messages. That might not be the end of the world.

You can see some examples in git.git by doing:

  git log | /path/to/original/diff-highlight >old
  git log | /path/to/your/new/diff-highlight >new
  diff -u old new

> diff --git a/contrib/diff-highlight/DiffHighlight.pm b/contrib/diff-highlight/DiffHighlight.pm
> index e2589922a6..74f53e53c9 100644
> --- a/contrib/diff-highlight/DiffHighlight.pm
> +++ b/contrib/diff-highlight/DiffHighlight.pm
> @@ -90,7 +90,8 @@ sub handle_line {
>  
>  	if (!$in_hunk) {
>  		$line_cb->($orig);
> -		$in_hunk = /^$COLOR*\@\@ /;
> +		$in_hunk = /^( *)$COLOR*\@\@/;

There's a similar regex a few lines below to decide of we should remain
in a hunk. Would you need to modify that, too?

> +		$graph_indent = length($1);

This throws away the existing $graph_indent. I know we wouldn't have a
range-diff mixed with a graph, but I think it breaks normal graph usage.
At least "make test" in contrib/diff-highlight seems to complain, and
adding "--graph -p" to the "git log" invocations above shows that we're
not highlighting a bunch of cases (perhaps all?).

-Peff

@dscho
Copy link
Member

dscho commented Mar 11, 2020

@jablko have you received the mail with Jeff King's review? If so, please do reply (the custom on the Git mailing list is to use reply-to-all and to avoid top-posting but to reply inline like Jeff did).

@phil-blain
Copy link
Contributor

@jablko today I wanted to use this feature, remembered seeing a PR about it, googled it and discovered it was not ready yet. Thus, I also encourage you to continue working on this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants