threads / patch / 27976

patch, 2 partsMinor userdiff stuff

Subject: [PATCH 0/2] Minor userdiff stuff

## tl;dr

9 messages between Aug 1, 2011 and Aug 3, 2011. Diffs are folded; open one to read it.

replies: 8people: 3as markdown or json

Giuseppe Bilotta· Aug 1, 2011, 10:37 UTC · lore
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(-)
-- 
1.7.6.451.gcb935.dirty
Giuseppe Bilotta· Aug 1, 2011, 10:37 UTC · re: Giuseppe Bilotta · lore

[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.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 userdiff.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Show changes to userdiff.c +3 −0
diff --git a/userdiff.c b/userdiff.c
index 01d3a8b..70120c3 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -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}\\{.*)$",
-- 
1.7.6.451.gcb935.dirty
Junio C Hamano· Aug 2, 2011, 17:51 UTC · re: Giuseppe Bilotta · lore

Re: [PATCH 1/2] Diff patterns for POSIX shells

Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:
Show 20 quoted lines
> 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 <giuseppe.bilotta@gmail.com>
> ---
>  userdiff.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/userdiff.c b/userdiff.c
> index 01d3a8b..70120c3 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -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?
>  PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
>  	 "[={}\"]|[^={}\" \t]+"),
>  PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
Giuseppe Bilotta· Aug 2, 2011, 18:52 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/2] Diff patterns for POSIX shells

On Tue, Aug 2, 2011 at 7:51 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 25 quoted lines
> Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:
>
>> 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 <giuseppe.bilotta@gmail.com>
>> ---
>>  userdiff.c |    3 +++
>>  1 files changed, 3 insertions(+), 0 deletions(-)
>>
>> diff --git a/userdiff.c b/userdiff.c
>> index 01d3a8b..70120c3 100644
>> --- a/userdiff.c
>> +++ b/userdiff.c
>> @@ -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.

-- 
Giuseppe "Oblomov" Bilotta
Giuseppe Bilotta· Aug 3, 2011, 05:26 UTC · re: Junio C Hamano · lore

[PATCH 1bis/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.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 userdiff.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Show changes to userdiff.c +3 −0
diff --git a/userdiff.c b/userdiff.c
index 01d3a8b..94b1c47 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -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}\\{.*)$",
-- 
1.7.6.485.gd947c.dirty
Jeff King· Aug 3, 2011, 09:32 UTC · re: Giuseppe Bilotta · lore

Re: [PATCH 1bis/2] Diff patterns for POSIX shells

On Wed, Aug 03, 2011 at 07:26:16AM +0200, Giuseppe Bilotta wrote:
> 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
Giuseppe Bilotta· Aug 3, 2011, 10:12 UTC · re: Jeff King · lore

Re: [PATCH 1bis/2] Diff patterns for POSIX shells

On Wed, Aug 3, 2011 at 11:32 AM, Jeff King <peff@peff.net> wrote:
Show 33 quoted lines
> On Wed, Aug 03, 2011 at 07:26:16AM +0200, Giuseppe Bilotta wrote:
>
>> 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.

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.

Show 12 quoted lines
>  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.
Indeed. I'll change the regexp to include the parenthesis.
-- 
Giuseppe "Oblomov" Bilotta
Junio C Hamano· Aug 3, 2011, 18:53 UTC · re: Jeff King · lore

Re: [PATCH 1bis/2] Diff patterns for POSIX shells

Jeff King <peff@peff.net> writes:
Show 9 quoted lines
> On Wed, Aug 03, 2011 at 07:26:16AM +0200, Giuseppe Bilotta wrote:
>
>> 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.

Giuseppe Bilotta· Aug 1, 2011, 10:37 UTC · re: Giuseppe Bilotta · lore

[PATCH 2/2] Use specific diff rules for repo files

Let's eat our own dogfood. (Also, this makes word diff much nicer on git's own repo.)

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 .gitattributes |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
Show changes to .gitattributes +3 −2
diff --git a/.gitattributes b/.gitattributes
index 5e98806..16930e6 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -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
-- 
1.7.6.451.gcb935.dirty

← back to recent threads