git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: bug in git diff --unified=0 ?

From
Junio C Hamano <gitster@pobox.com>
Date
May 3, 2009, 00:17 UTC
Message-ID
<7vocub59b3.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20090502234701.GL23604@spearce.org>
"Shawn O. Pearce" <spearce@spearce.org> writes:
Show 44 quoted lines
> I can't decide if this is a bug in JGit, or a bug in CGit, or just
> an area where the patch format is very unclear.
>
> The following 2 patches are identical, but use different context:
>
> git diff --unified=1:
>
>     diff --git a/X b/X
>     index a3648a1..2d44096 100644
>     --- a/X
>     +++ b/X
>     @@ -2,2 +2,3 @@
>      b
>     +c
>      d
>     @@ -16,4 +17,2 @@
>      q
>     -r
>     -s
>      t
>
> git diff --unified=0:
>
>     diff --git a/X b/X
>     index a3648a1..2d44096 100644
>     --- a/X
>     +++ b/X
>     @@ -2,0 +3 @@
>     +c
>     @@ -17,2 +17,0 @@
>     -r
>     -s
>     
> Now lets look at JGit's output of that last patch, unified=0:
>
>     diff --git a/X b/X
>     index a3648a1..2d44096 100644
>     --- a/X
>     +++ b/X
>     @@ -3,0 +3,1 @@
>     +c
>     @@ -17,2 +18,0 @@
>     -r
>     -s

I do not know what the current status of the POSIX draft for spliting "context diff" format into "copied context" and "unified context", but see http://www.opengroup.org/austin/aardvark/latest/xcubug2.txt for the definition that was on track the last time I checked.

    First the range of lines in each file shall be written in the
    following format:
    "@@^-%s^+%s^@@", <file1 range>, <file2 range>
    Each <range> field shall be of the form:
   "%1d", <beginning line number>
    if the range contains exactly one line, and:
   "%1d,%1d", <beginning line number>, <number of lines>
    otherwise.  If a range is empty, its beginning line number shall be
    the number of the line just before the range, or 0 if the empty
    range starts the file.
So, JGit is wrong.
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 2 of 4 in “bug in git diff --unified=0 ?”
  1. Shawn O. PearceMay 2, 2009
  2. Junio C HamanoMay 3, 2009
  3. Shawn O. PearceMay 3, 2009
  4. Junio C HamanoMay 3, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.