Minor userdiff stuff
cover Minor userdiff stuff
The first commit introduces diff patterns for POSIX shells.
The second defines diff types for C, Perl and shell scripts in git.git
Giuseppe Bilotta (2):
Diff patterns for POSIX shells
Use specific diff rules for repo files
.gitattributes | 5 +++-- userdiff.c | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.6.451.gcb935.dirty
PATCH 1/2 Diff patterns for POSIX shells
All diffs following a function definition will have that function name as chunck header, but this is the best we can do with the current userdiff capabilities.
--- userdiff.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
userdiff.c +3 -0
@@ -107,6 +107,9 @@"(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*" "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?." "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"), +PATTERNS ("shell" ,"^[ \t]*([a-zA-Z_0-9]+)[ \t]*\\(\\).*" , +/* -- */ +"(--|\\$)?[a-zA-Z_0-9]+|&&|\\|\\|" ),PATTERNS ("bibtex" ,"(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$" ,"[={}\"]|[^={}\" \t]+" ), PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
Signature · 1 line
1.7.6.451.gcb935.dirty
PATCH 2/2 Use specific diff rules for repo files
In reply to Giuseppe BilottaLet's eat our own dogfood. (Also, this makes word diff much nicer on git's own repo.)
--- .gitattributes | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
.gitattributes +3 -2
@@ -1,3 +1,4 @@ * whitespace=!indent,trail,space -*.[ch] whitespace=indent,trail,space -*.sh whitespace=indent,trail,space +*.[ch] whitespace=indent,trail,space diff=cpp +*.sh whitespace=indent,trail,space diff=shell +*.perl diff=perl
Signature · 1 line
1.7.6.451.gcb935.dirty
Re: [PATCH 1/2] Diff patterns for POSIX shells
In reply to Giuseppe BilottaQuoted 14 lines · Giuseppe Bilotta
All diffs following a function definition will have that function name as chunck header, but this is the best we can do with the current userdiff capabilities.
Signed-off-by Giuseppe Bilotta <[email protected]>--- userdiff.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)userdiff.c +0
-0
userdiff.c line 112
Quoted 6 lines
userdiff.c +3
-0@@ -107,6 +107,9 @@"(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*" "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?." "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"), +PATTERNS ("shell" ,"^[ \t]*([a-zA-Z_0-9]+)[ \t]*\\(\\).*" , +/* -- */ + "(--|\\$)?[a-zA-Z_0-9]+|&&|\\|\\|"),
Hmm, what is this "double-dash -- might be present before a name" about?
Quoted 3 lines
userdiff.c +0
-0PATTERNS ("bibtex" ,"(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$" ,"[={}\"]|[^={}\" \t]+" ), PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
PATCH 1/1 Diff patterns for POSIX shells
All diffs following a function definition will have that function name as chunck header, but this is the best we can do with the current userdiff capabilities.
--- userdiff.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
userdiff.c +3 -0
@@ -107,6 +107,9 @@"(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*" "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?." "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"), +PATTERNS ("shell" ,"^[ \t]*([a-zA-Z_0-9]+)[ \t]*\\(\\).*" , +/* -- */ +"\\$?[a-zA-Z_0-9]+|&&|\\|\\|" ),PATTERNS ("bibtex" ,"(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$" ,"[={}\"]|[^={}\" \t]+" ), PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
Signature · 1 line
1.7.6.485.gd947c.dirty
Re: [PATCH 1bis/2] Diff patterns for POSIX shells
Quoted 3 lines · Giuseppe Bilotta
All diffs following a function definition will have that function name as chunck header, but this is the best we can do with the current userdiff capabilities.
Curious as to how this would look in git.git, I tried "git log -p" before and after your patches, and diffed the result. I noticed two things:
1. Given a block of shell code like this:
foo() {
... do something ...
}
test_expect_success 'test foo' '
... the actual test ...
'
if we add new code after the test, the old regex would print:
@@ -1,2 +3,4 @@ test_expect_success 'test foo' '
and now we say:
@@ -1,2 +3,4 @@ foo
which seems more misleading. I know the function-matching code has no way to say "look for ^}, which signals end of function", so we can't be entirely accurate. But I wonder if the new heuristic (which seems to look for a name followed by parentheses) is actually any better than the old.
2. What would have printed before:
@@ -1,2 +3,4 @@ foo() {
now prints
@@ -1,2 +3,4 @@ foo
without the parentheses or brace. It looks like the similar C one keeps the parentheses, at least. I find that a bit more readable, as it is more clear that the line indicates a function, and not simply some top-level command.
-Peff
Re: [PATCH 1bis/2] Diff patterns for POSIX shells
Quoted 26 lines · Jeff King
Quoted 3 lines · Giuseppe Bilotta
All diffs following a function definition will have that function name as chunck header, but this is the best we can do with the current userdiff capabilities.
Curious as to how this would look in git.git, I tried "git log -p" before and after your patches, and diffed the result. I noticed two things:
1. Given a block of shell code like this:
foo() {
... do something ...
}test_expect_success 'test foo' '
... the actual test ...
'if we add new code after the test, the old regex would print:
@@ -1,2 +3,4 @@
test_expect_success'test foo' 'and now we say:
Quoted 7 lines
@@ -1,2 +3,4 @@ foo
which seems more misleading. I know the function-matching code has no way to say "look for ^}, which signals end of function", so we can't be entirely accurate. But I wonder if the new heuristic (which seems to look for a name followed by parentheses) is actually any better than the old.
I'm not too satisfied with the solution either. I've been thinking about adding some important keywords such as for, while, if, until, case etc, but decided it would be too much overkill. And, it still woudln't work 'correctly' in a case such as this one you presented above.
Quoted 4 lines
2. What would have printed before:
@@ -1,2 +3,4 @@
foo(){
Quoted 8 lines
now prints
@@ -1,2 +3,4 @@ foo
without the parentheses or brace. It looks like the similar C one keeps the parentheses, at least. I find that a bit more readable, as it is more clear that the line indicates a function, and not simply some top-level command.
Indeed. I'll change the regexp to include the parenthesis.
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Re: [PATCH 1/2] Diff patterns for POSIX shells
In reply to Junio C HamanoQuoted 11 lines · Junio C Hamano
Quoted 9 lines · Giuseppe Bilotta
All diffs following a function definition will have that function name as chunck header, but this is the best we can do with the current userdiff capabilities.
Signed-off-by Giuseppe Bilotta <[email protected]>---
userdiff.c | 3 +++1 files changed, 3 insertions(+), 0 deletions(-)
Quoted 14 lines
Quoted 11 lines
userdiff.c +0
-0@@ -107,6 +107,9 @@"(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*" "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?." "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"), +PATTERNS("shell", "^[ \t]*([a-zA-Z_0-9]+)[ \t]*\\(\\).*",
+ /* -- */
+ "(--|\\$)?[a-zA-Z_0-9]+|&&|\\|\\|"),Hmm, what is this "double-dash -- might be present before a name" about?
Now that's a good question. I think it was a brainfart while testing the regexp; came across a case switch where the candidate were options, and somehow decided that it was better to include the --. I'll prepare a patch without this stupidity.
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Re: [PATCH 1bis/2] Diff patterns for POSIX shells
In reply to Jeff KingQuoted 9 lines · Jeff King
Quoted 3 lines · Giuseppe Bilotta
All diffs following a function definition will have that function name as chunck header, but this is the best we can do with the current userdiff capabilities.
Curious as to how this would look in git.git, I tried "git log -p" before and after your patches, and diffed the result. I noticed two things:
Hmm, sounds like a regression without much upside to me. Thanks for looking.