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];
}
if (negative) {
----
This was [previously
discussed](https://mail.openjdk.org/pipermail/skara-dev/2023-August/008108.html)
on the skara-dev mailing list.
-------------
Commit messages:
- gitattributes: make diffs easier to read
Changes: https://git.openjdk.org/jdk/pull/15334/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15334&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8314543
Stats: 9 lines in 1 file changed: 9 ins; 0 del; 0 mod
Patch: https://git.openjdk.org/jdk/pull/15334.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/15334/head:pull/15334
PR: https://git.openjdk.org/jdk/pull/15334