Skip to contentSkip to conversation

git diff - no newline after @@ ?

DISCUSSION Petr Sebor 4 participants 7 messages Jun 15, 2016

lore
Share & tools
lore

Petr Sebor

author
#0 lore raw

Hello,

has anyone noticed that the 'git diff' output somehow lacks the newline after the @@ tag?

The linux-kernel list is full of diffs whose hunks begin like:

@@ -1475,6 +1475,7 @@ int do_coredump(long signr, int exit_cod

@@ -1516,22 +1517,34 @@ int do_coredump(long signr, int exit_cod

@@ -1428,7 +1442,7 @@ static int elf_core_dump(long signr, str

instead of:

@@ -1475,6 +1475,7 @@
int do_coredump(long signr, int exit_cod

@@ -1516,22 +1517,34 @@
int do_coredump(long signr, int exit_cod

@@ -1428,7 +1442,7 @@
static int elf_core_dump(long signr, str

It is not only a problem of the linux-kernel, my local git installation suffers from this as well...

Regards
Petr

#1 lore raw
Quoted 5 lines · Petr Sebor

Hello,

has anyone noticed that the 'git diff' output somehow lacks the newline after the @@ tag?

Why should it? It's hunk comment.

author
#2 lore raw
Quoted 8 lines · Alex Riesen
Quoted 5 lines · Petr Sebor

Hello,

has anyone noticed that the 'git diff' output somehow lacks the newline after the @@ tag?

Why should it? It's hunk comment.

Hunk comment? Maybe we don't understand each other...

check another example:

include/linux/kernel.h +0 -0
@@ -13,6 +13,7 @@ #include <linux/stddef.h>

#include <linux/types.h>
#include <linux/compiler.h>
#include <linux/bitops.h>
+#include <linux/memleak.h>
#include <asm/byteorder.h>
#include <asm/bug.h>

whereas gnu diff would output

include/linux/kernel.h +0 -0
@@ -13,6 +13,7 @@

#include <linux/stddef.h>
#include <linux/types.h>
#include <linux/compiler.h>
#include <linux/bitops.h>
+#include <linux/memleak.h>
#include <asm/byteorder.h>
#include <asm/bug.h>

Petr

#3 lore raw
Quoted 4 lines · Petr Sebor
Quoted 3 lines
Quoted 2 lines

has anyone noticed that the 'git diff' output somehow lacks the newline after the @@ tag?

Why should it? It's hunk comment.

Hunk comment? Maybe we don't understand each other...

The intent of a hunk comment is to give the user some context. Note how it's usually the C function name, even if the declaration of that function isn't the line right before the context lines?

include/linux/kernel.h #include <linux/stddef.h> · line 18

Quoted 11 lines

check another example:

include/linux/kernel.h +1 -0
@@ -13,6 +13,7 @@ #include <linux/stddef.h>
 #include <linux/types.h>
 #include <linux/compiler.h>
 #include <linux/bitops.h>
+#include <linux/memleak.h>
 #include <asm/byteorder.h>
 #include <asm/bug.h>

The function detection is very simple (I believe it just looks for the closest preceding line without any prior whitespace).

Quoted 1 line

whereas gnu diff would output

Try diff -p to get a hunk comment.

-Peff

author
#4 lore raw
Quoted 4 lines · Jeff King

Try diff -p to get a hunk comment.

-Peff

Ouch.... got it. Is there a way to turn the comment generation off btw?

Sorry for the noise...

Petr

#5 lore raw
Quoted 7 lines · Petr Sebor
Quoted 4 lines · Jeff King

Try diff -p to get a hunk comment.

-Peff

Ouch.... got it. Is there a way to turn the comment generation off btw?

Other than GIT_DIFF_OPTS (although how to turn off present -p option), or GIT_EXTERNAL_DIFF (see git-diff-tree(1))?

Why do you want to turn it off? patch understands this format...

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#6 lore raw
In reply to Petr Sebor
Quoted 10 lines · Petr Sebor
Quoted 8 lines · Alex Riesen
Quoted 5 lines · Petr Sebor

Hello,

has anyone noticed that the 'git diff' output somehow lacks the newline after the @@ tag?

Why should it? It's hunk comment.

Hunk comment? Maybe we don't understand each other...

Hunk comment as in "diff -p":

-p Show which C function each change is in.

(which is simpliefied to: show first line preceding hunk which begins with word character in first column).

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git