# [PATCH 0/2] Minor userdiff stuff

9 messages from 2011-08-01 to 2011-08-03. Participants: Giuseppe Bilotta, Junio C Hamano, Jeff King.
Thread: https://gitlist.dev/t/27976

## Giuseppe Bilotta, 2011-08-01 10:37

Subject: [PATCH 0/2] Minor userdiff stuff
Message-ID: <1312195069-10782-1-git-send-email-giuseppe.bilotta@gmail.com>
URL: https://gitlist.dev/e/1312195069-10782-1-git-send-email-giuseppe.bilotta%40gmail.com

```
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, 2011-08-01 10:37

Subject: [PATCH 1/2] Diff patterns for POSIX shells
Message-ID: <1312195069-10782-2-git-send-email-giuseppe.bilotta@gmail.com>
URL: https://gitlist.dev/e/1312195069-10782-2-git-send-email-giuseppe.bilotta%40gmail.com
In-Reply-To: <1312195069-10782-1-git-send-email-giuseppe.bilotta@gmail.com>

```
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]+|&&|\\|\\|"),
 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

```

## Giuseppe Bilotta, 2011-08-01 10:37

Subject: [PATCH 2/2] Use specific diff rules for repo files
Message-ID: <1312195069-10782-3-git-send-email-giuseppe.bilotta@gmail.com>
URL: https://gitlist.dev/e/1312195069-10782-3-git-send-email-giuseppe.bilotta%40gmail.com
In-Reply-To: <1312195069-10782-1-git-send-email-giuseppe.bilotta@gmail.com>

```
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(-)

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

```

## Junio C Hamano, 2011-08-02 17:51

Subject: Re: [PATCH 1/2] Diff patterns for POSIX shells
Message-ID: <7vzkjrem6b.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzkjrem6b.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1312195069-10782-2-git-send-email-giuseppe.bilotta@gmail.com>

```
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?

>  PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
>  	 "[={}\"]|[^={}\" \t]+"),
>  PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",

```

## Giuseppe Bilotta, 2011-08-02 18:52

Subject: Re: [PATCH 1/2] Diff patterns for POSIX shells
Message-ID: <CAOxFTcy-AXtCW7-BCLgYnNTGd+unkiSaWAGPO+k+fcKr5VK-mw@mail.gmail.com>
URL: https://gitlist.dev/e/CAOxFTcy-AXtCW7-BCLgYnNTGd%2BunkiSaWAGPO%2Bk%2BfcKr5VK-mw%40mail.gmail.com
In-Reply-To: <7vzkjrem6b.fsf@alter.siamese.dyndns.org>

```
On Tue, Aug 2, 2011 at 7:51 PM, Junio C Hamano <gitster@pobox.com> wrote:
> 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, 2011-08-03 05:26

Subject: [PATCH 1bis/2] Diff patterns for POSIX shells
Message-ID: <1312349176-20984-1-git-send-email-giuseppe.bilotta@gmail.com>
URL: https://gitlist.dev/e/1312349176-20984-1-git-send-email-giuseppe.bilotta%40gmail.com
In-Reply-To: <7vzkjrem6b.fsf@alter.siamese.dyndns.org>

```
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..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, 2011-08-03 09:32

Subject: Re: [PATCH 1bis/2] Diff patterns for POSIX shells
Message-ID: <20110803093252.GA16351@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20110803093252.GA16351%40sigill.intra.peff.net
In-Reply-To: <1312349176-20984-1-git-send-email-giuseppe.bilotta@gmail.com>

```
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, 2011-08-03 10:12

Subject: Re: [PATCH 1bis/2] Diff patterns for POSIX shells
Message-ID: <CAOxFTcxEL38HW0mX++Wa7b0TEPo56xDZPZaqJ5wrpMcQGSfQoQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAOxFTcxEL38HW0mX%2B%2BWa7b0TEPo56xDZPZaqJ5wrpMcQGSfQoQ%40mail.gmail.com
In-Reply-To: <20110803093252.GA16351@sigill.intra.peff.net>

```
On Wed, Aug 3, 2011 at 11:32 AM, Jeff King <peff@peff.net> wrote:
> 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.

>  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, 2011-08-03 18:53

Subject: Re: [PATCH 1bis/2] Diff patterns for POSIX shells
Message-ID: <7vmxfqba2p.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vmxfqba2p.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20110803093252.GA16351@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

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

```
