# [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files

10 messages from 2011-08-25 to 2011-08-29. Participants: Boaz Harrosh, Linus Torvalds, Junio C Hamano, Peter Zijlstra.
Thread: https://gitlist.dev/t/28221

## Boaz Harrosh, 2011-08-25 22:37

Subject: [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files
Message-ID: <4E56CE8F.8080501@panasas.com>
URL: https://gitlist.dev/e/4E56CE8F.8080501%40panasas.com

```

The Linux Kernel source tree is certainly a C language repository.
As a maintainer and code reviewer I would like too, for example:
See function names as hunk headers and not goto labels. And all
the other goodies a language specific diff parser gives me.

Add a .gitattributes file to the Linux tree to enable cpp parsing
of the source files.

People are welcome to add other parsers for other type of files
if needed. (Like Makefile or Kconfig ...)

CC: Jeff King <peff@peff.net>
CC: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
 .gitattributes |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 .gitattributes

diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..6d2b620
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+*.h diff=cpp
+*.c diff=cpp
-- 
1.7.6

```

## Linus Torvalds, 2011-08-26 20:27

Subject: Re: [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files
Message-ID: <CA+55aFxNXK-AJdrHBBycM5W632qUBi4E=jangcdRoefQiHzbug@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2B55aFxNXK-AJdrHBBycM5W632qUBi4E%3DjangcdRoefQiHzbug%40mail.gmail.com
In-Reply-To: <4E56CE8F.8080501@panasas.com>

```
On Thu, Aug 25, 2011 at 3:37 PM, Boaz Harrosh <bharrosh@panasas.com> wrote:
>
> Add a .gitattributes file to the Linux tree to enable cpp parsing
> of the source files.

Hmm. I'm not entirely conviced. If people really think that the hunk
description matters that much, maybe we should just instead improve on
the automatic diff detection, and extend it from just binary-vs-text,
to also do the common hunk-headers.

After all, not having a diff pattern already *does* mean "automatic",
so it would be just a rather trivial extension to that.

Junio?

                     Linus

```

## Junio C Hamano, 2011-08-26 20:54

Subject: Re: [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files
Message-ID: <7vfwkndhc4.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vfwkndhc4.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CA+55aFxNXK-AJdrHBBycM5W632qUBi4E=jangcdRoefQiHzbug@mail.gmail.com>

```
Linus Torvalds <torvalds@linux-foundation.org> writes:

> On Thu, Aug 25, 2011 at 3:37 PM, Boaz Harrosh <bharrosh@panasas.com> wrote:
>>
>> Add a .gitattributes file to the Linux tree to enable cpp parsing
>> of the source files.
>
> Hmm. I'm not entirely conviced. If people really think that the hunk
> description matters that much, maybe we should just instead improve on
> the automatic diff detection, and extend it from just binary-vs-text,
> to also do the common hunk-headers.
>
> After all, not having a diff pattern already *does* mean "automatic",
> so it would be just a rather trivial extension to that.

Not quite sure what you exactly mean by "extend it from just binary-vs-text".
Do you mean update buffer_is_binary() and add source language detection?

See also:

    http://thread.gmane.org/gmane.comp.version-control.git/180103/focus=180113

```

## Boaz Harrosh, 2011-08-26 20:55

Subject: Re: [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files
Message-ID: <4E580830.4010305@panasas.com>
URL: https://gitlist.dev/e/4E580830.4010305%40panasas.com
In-Reply-To: <CA+55aFxNXK-AJdrHBBycM5W632qUBi4E=jangcdRoefQiHzbug@mail.gmail.com>

```
On 08/26/2011 01:27 PM, Linus Torvalds wrote:
> On Thu, Aug 25, 2011 at 3:37 PM, Boaz Harrosh <bharrosh@panasas.com> wrote:
>>
>> Add a .gitattributes file to the Linux tree to enable cpp parsing
>> of the source files.
> 
> Hmm. I'm not entirely conviced. If people really think that the hunk
> description matters that much, maybe we should just instead improve on
> the automatic diff detection, and extend it from just binary-vs-text,
> to also do the common hunk-headers.
> 
> After all, not having a diff pattern already *does* mean "automatic",
> so it would be just a rather trivial extension to that.
> 
> Junio?
> 

There was a patch submitted for new git version to auto detect file
extensions and do the right thing. 
(Look for the thread "git diff annoyance / feature request" on the git
 mailing list)

But this patch is for all the people and distributions that are going
to use the old git versions for a while, (Years).

It is important for the Linux mailing-list review, because you get
patches with:

@@@ lable out:
-	change foo
+	to bazz

And how the hell are you suppose to know where in the file it is.
This is such a trivial addition, that can help unify everyone's
usage. I don't see the down sides.

Thanks
Boaz

>                      Linus

```

## Linus Torvalds, 2011-08-26 20:59

Subject: Re: [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files
Message-ID: <CA+55aFy=T82q==OxAzRfUgyfzMvy7=oeLOEAL8=rTJWOwkw-iA@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2B55aFy%3DT82q%3D%3DOxAzRfUgyfzMvy7%3DoeLOEAL8%3DrTJWOwkw-iA%40mail.gmail.com
In-Reply-To: <7vfwkndhc4.fsf@alter.siamese.dyndns.org>

```
On Fri, Aug 26, 2011 at 1:54 PM, Junio C Hamano <gitster@pobox.com> wrote:
>
> Not quite sure what you exactly mean by "extend it from just binary-vs-text".
> Do you mean update buffer_is_binary() and add source language detection?

Yes. Except the "detection" would be just "if we auto-detect it as
text, then use the standard file extensions to also make an automatic
hunk rule detection".

So it would do the most common cases (*.[Cch] etc)

                         Linus

```

## Peter Zijlstra, 2011-08-29 13:32

Subject: Re: [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files
Message-ID: <1314624752.2816.32.camel@twins>
URL: https://gitlist.dev/e/1314624752.2816.32.camel%40twins
In-Reply-To: <4E580830.4010305@panasas.com>

```
On Fri, 2011-08-26 at 13:55 -0700, Boaz Harrosh wrote:

> But this patch is for all the people and distributions that are going
> to use the old git versions for a while, (Years).
> 
> It is important for the Linux mailing-list review, because you get
> patches with:
> 
> @@@ lable out:
> -	change foo
> +	to bazz
> 
> And how the hell are you suppose to know where in the file it is.
> This is such a trivial addition, that can help unify everyone's
> usage. I don't see the down sides.

Ah, I'm using:

# cat ~/.gitconfig 
[diff "default"]
                xfuncname = "^[[:alpha:]$_].*[^:]$"


For this.

```

## Boaz Harrosh, 2011-08-29 20:57

Subject: Re: [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files
Message-ID: <4E5BFD36.2090000@panasas.com>
URL: https://gitlist.dev/e/4E5BFD36.2090000%40panasas.com
In-Reply-To: <1314624752.2816.32.camel@twins>

```
On 08/29/2011 06:32 AM, Peter Zijlstra wrote:
> On Fri, 2011-08-26 at 13:55 -0700, Boaz Harrosh wrote:
> 
>> But this patch is for all the people and distributions that are going
>> to use the old git versions for a while, (Years).
>>
>> It is important for the Linux mailing-list review, because you get
>> patches with:
>>
>> @@@ lable out:
>> -	change foo
>> +	to bazz
>>
>> And how the hell are you suppose to know where in the file it is.
>> This is such a trivial addition, that can help unify everyone's
>> usage. I don't see the down sides.
> 
> Ah, I'm using:
> 
> # cat ~/.gitconfig 
> [diff "default"]
>                 xfuncname = "^[[:alpha:]$_].*[^:]$"
> 
> 
> For this.

It looks like a lost cause so I'll try for the last time.

Everyone is suggesting that each one do his own cooked up secrets and solutions.
And those that are stupid and know nothing like me are un-lucky. But what I'm
proposing is that by just doing a "git clone" you'll be using these settings
that we like to see, when you send us your patches.

Adding a .gitattributes file to the Linux git tree is a very simple message.
"In the linux git tree all .c and .h files are c-source files" (And git will
treat them that way)

Now that was not so hard was it? Really, no one said anything bad or negative
about the patch, only excuses how it can be achieved, very difficultly, in
another way. So for the last time:
  What are you guys afraid of? what possibly could be bad about this patch?

Sigh

Good bye to this subject
Boaz

```

## Peter Zijlstra, 2011-08-29 21:30

Subject: Re: [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files
Message-ID: <1314653414.2054.0.camel@twins>
URL: https://gitlist.dev/e/1314653414.2054.0.camel%40twins
In-Reply-To: <4E5BFD36.2090000@panasas.com>

```
On Mon, 2011-08-29 at 13:57 -0700, Boaz Harrosh wrote:
> 
> Adding a .gitattributes file to the Linux git tree is a very simple message.
> "In the linux git tree all .c and .h files are c-source files" (And git will
> treat them that way) 

I'm all for it, I hate those labels in git-diff output.. 

```

## Linus Torvalds, 2011-08-29 22:02

Subject: Re: [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files
Message-ID: <CA+55aFxB7mBByT9W4c0D6kELcZMZDD_j0_S2869nS4LV0mNTbA@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2B55aFxB7mBByT9W4c0D6kELcZMZDD_j0_S2869nS4LV0mNTbA%40mail.gmail.com
In-Reply-To: <4E5BFD36.2090000@panasas.com>

```
On Mon, Aug 29, 2011 at 1:57 PM, Boaz Harrosh <bharrosh@panasas.com> wrote:
>
>  What are you guys afraid of? what possibly could be bad about this patch?

I just detest filling the kernel tree with git stuff.

Right now, the only git-specific file we have in the kernel tree is
the ".gitignore" files, afaik. And if you were to use some other SCM,
the "ignore" model at least translates directly to just about anything
else (with the problem that the .gitignore model tends to be more
powerful than most other SCM's have, but whatever).

I'd hate to start populating the project with more stuff.

                     Linus

```

## Boaz Harrosh, 2011-08-29 22:43

Subject: Re: [PATCH] .gitattributes: Enable cpp diff parsing for .[ch] files
Message-ID: <4E5C1604.2060209@panasas.com>
URL: https://gitlist.dev/e/4E5C1604.2060209%40panasas.com
In-Reply-To: <CA+55aFxB7mBByT9W4c0D6kELcZMZDD_j0_S2869nS4LV0mNTbA@mail.gmail.com>

```
On 08/29/2011 03:02 PM, Linus Torvalds wrote:
> 
> I'd hate to start populating the project with more stuff.
> 
>                      Linus

OK Thanks for the answer. That I can understand
Boaz

```
