Integrated: 8314543: gitattributes: make diffs easier to read

Andrei Rybak duke at openjdk.org
Fri Aug 18 07:51:38 UTC 2023


On Thu, 17 Aug 2023 17:25:52 GMT, Andrei Rybak <duke at openjdk.org> wrote:

> Git supports special hunk headers for several languages in diff output, which make it easier to read diffs of files in that language, generated by Git (git-diff, git-show, `git log -p`, etc).  For details, see `git help gitattributes` or [the online documentation](https://git-scm.com/docs/gitattributes).
> 
> Add entries to the root .gitattributes file to support showing the hunk headers for Java, C, C++, Markdown, Shell script, HTML, and CSS.  This makes it easier to read diffs generated by Git.
> 
> As an example, for j.l.Integer, before, the hunk header just shows the class name, found using the generic hunk header regex:
> 
> 
> $ git show --format='' 71ca85f5a6741a2db55a529192564f94b269fbd9 -- src/java.base/share/classes/java/lang/Integer.java
> diff --git a/src/java.base/share/classes/java/lang/Integer.java b/src/java.base/share/classes/java/lang/Integer.java
> index 7d200e7edf5..9ec9d3941f8 100644
> --- a/src/java.base/share/classes/java/lang/Integer.java
> +++ b/src/java.base/share/classes/java/lang/Integer.java
> @@ -517,13 +517,9 @@ public final class Integer extends Number
>          }
> 
>          // We know there are at most two digits left at this point.
> -        q = i / 10;
> -        r = (q * 10) - i;
> -        buf[--charPos] = (byte)('0' + r);
> -
> -        // Whatever left is the remaining digit.
> -        if (q < 0) {
> -            buf[--charPos] = (byte)('0' - q);
> +        buf[--charPos] = DigitOnes[-i];
> +        if (i < -9) {
> +            buf[--charPos] = DigitTens[-i];
>          }
> 
>          if (negative) {
> 
> 
> After, the hunk shows the method edited by the commit, derived using the regex specific to Java:
> 
> 
> $ git show --format='' 71ca85f5a6741a2db55a529192564f94b269fbd9 -- src/java.base/share/classes/java/lang/Integer.java
> diff --git a/src/java.base/share/classes/java/lang/Integer.java b/src/java.base/share/classes/java/lang/Integer.java
> index 7d200e7edf5..9ec9d3941f8 100644
> --- a/src/java.base/share/classes/java/lang/Integer.java
> +++ b/src/java.base/share/classes/java/lang/Integer.java
> @@ -517,13 +517,9 @@ static int getChars(int i, int index, byte[] buf) {
>          }
> 
>          // We know there are at most two digits left at this point.
> -        q = i / 10;
> -        r = (q * 10) - i;
> -        buf[--charPos] = (byte)('0' + r);
> -
> -        // Whatever left is the remaining digit.
> -        if (q < 0) {
> -            buf[--charPos] = (byte)('0' - q);
> +        buf[--charPos] = DigitOnes[-i];
> +        if (i < -9) {
> +            buf[--charPos] = DigitTens[-i];
>          }
> 
>          ...

This pull request has now been integrated.

Changeset: 33d5dfda
Author:    Andrei Rybak <rybak.a.v at gmail.com>
Committer: Koichi Sakata <ksakata at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/33d5dfdab3098549366088c43797bdcaebe02cd6
Stats:     9 lines in 1 file changed: 9 ins; 0 del; 0 mod

8314543: gitattributes: make diffs easier to read

Git supports special hunk headers for several languages in diff output,
which make it easier to read diffs of files in that language, generated
by Git (git-diff, git-show, `git log -p`, etc).  For details, see
`git help gitattributes` or the online documentation.[1]

Add entries to the root .gitattributes file to support showing the hunk
headers for Java, C, C++, Markdown, Shell script, HTML, and CSS.  This
makes it easier to read diffs generated by Git.

[1] https://git-scm.com/docs/gitattributes

Reviewed-by: erikj, ksakata

-------------

PR: https://git.openjdk.org/jdk/pull/15334


More information about the build-dev mailing list