Thread (1 message) 1 message, 1 author, 2022-10-25

Re: [PATCH] Set git diff driver for C source code files.

From: Alejandro Colomar <hidden>
Date: 2022-10-25 19:27:11

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 <redacted>
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 [off-list ref]> too :)
quoted hunk
---
  .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/>

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help