threads / patch / 28221

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

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

## tl;dr

10 messages between Aug 25, 2011 and Aug 29, 2011. Diffs are folded; open one to read it.

replies: 9people: 4as markdown or json

Boaz Harrosh· Aug 25, 2011, 22:37 UTC · lore

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
Show changes to .gitattributes +2 −0
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· Aug 26, 2011, 20:27 UTC · re: Boaz Harrosh · lore

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

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· Aug 26, 2011, 20:54 UTC · re: Linus Torvalds · lore

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

Linus Torvalds <torvalds@linux-foundation.org> writes:
Show 12 quoted lines
> 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
Linus Torvalds· Aug 26, 2011, 20:59 UTC · re: Junio C Hamano · lore

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

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
Boaz Harrosh· Aug 26, 2011, 20:55 UTC · re: Linus Torvalds · lore

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

On 08/26/2011 01:27 PM, Linus Torvalds wrote:
Show 15 quoted lines
> 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
Peter Zijlstra· Aug 29, 2011, 13:32 UTC · re: Boaz Harrosh · lore

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

On Fri, 2011-08-26 at 13:55 -0700, Boaz Harrosh wrote:
Show 13 quoted lines
> 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· Aug 29, 2011, 20:57 UTC · re: Peter Zijlstra · lore

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

On 08/29/2011 06:32 AM, Peter Zijlstra wrote:
Show 24 quoted lines
> 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· Aug 29, 2011, 21:30 UTC · re: Boaz Harrosh · lore

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

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· Aug 29, 2011, 22:02 UTC · re: Boaz Harrosh · lore

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

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· Aug 29, 2011, 22:43 UTC · re: Linus Torvalds · lore

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

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

← back to recent threads