All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Set git diff driver for C source code files
@ 2016-09-07 12:34 Jean Delvare
  0 siblings, 0 replies; 2+ messages in thread
From: Jean Delvare @ 2016-09-07 12:34 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Joe Perches, Jonathan Corbet, Andrew Morton

Git can be told to apply language-specific rules when generating
diffs. Enable this for C source code files (*.c and *.h) so that
function names are printed right. Specifically, doing so prevents
"git diff" from mistakenly considering unindented goto labels as
function names.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Joe Perches <joe@perches.com>
Cc: Jonathan Corbet <corbet@lwn.net>
---
 .gitattributes |    2 ++
 1 file changed, 2 insertions(+)

--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-4.7/.gitattributes	2016-09-07 14:07:23.042138220 +0200
@@ -0,0 +1,2 @@
+*.c   diff=cpp
+*.h   diff=cpp


-- 
Jean Delvare
SUSE L3 Support

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Set git diff driver for C source code files.
       [not found] <20221025191552.60658-1-a.clayton@nginx.com>
@ 2022-10-25 19:26 ` Alejandro Colomar
  0 siblings, 0 replies; 2+ messages in thread
From: Alejandro Colomar @ 2022-10-25 19:26 UTC (permalink / raw)
  To: Andrew Clayton, Git Mailing List; +Cc: Alejandro Colomar


[-- Attachment #1.1: Type: text/plain, Size: 1564 bytes --]

Hi Andrew,

On 10/25/22 21:15, Andrew Clayton wrote:
> Git can be told to apply language-specific rules when generating diffs.
> Enable this for C source code files (*.c and *.h) so that function names
> are printed right. Specifically, doing so prevents "git diff" from
> mistakenly considering unindented goto labels as function names.
> 
> This has the same effect as adding
> 
>      [diff "default"]
>          xfuncname = "^[[:alpha:]$_].*[^:]$"

Where does that regex come from?

> 
> to your git config file.
> 
> e.g get
> 
>      @@ -10,7 +10,7 @@ int main(void)
> 
> instead of
> 
>      @@ -10,7 +10,7 @@ again:
> 
> This makes use of the gitattributes(5) infrastructure.
> 
> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>

Wow!  git(1) is showing C functions incorrectly?!  The last language I expected 
this to happen with.  I had to use this for man(7) pages, but for C files?!

I mean, we have one of the simplest and most consistent coding styles I've seen 
regarding placement of function definitions (no false negatives or positives in 
grepc(1)).

Should we report a bug to <mailto:Git <git@vger.kernel.org>> too :)

> ---
>   .gitattributes | 2 ++
>   1 file changed, 2 insertions(+)
>   create mode 100644 .gitattributes
> 
> diff --git a/.gitattributes b/.gitattributes
> new file mode 100644
> index 00000000..45ec5156
> --- /dev/null
> +++ b/.gitattributes
> @@ -0,0 +1,2 @@
> +*.c	diff=cpp
> +*.h	diff=cpp

Why cpp?

Thanks,

Alex

-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-25 19:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-07 12:34 [PATCH] Set git diff driver for C source code files Jean Delvare
     [not found] <20221025191552.60658-1-a.clayton@nginx.com>
2022-10-25 19:26 ` Alejandro Colomar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.