{"thread":{"id":"19161","subject":"bug in git diff --unified=0 ?","startedAt":"2009-05-02T23:47:01Z","lastAt":"2009-05-03T05:18:07Z","messageCount":4,"participants":["Shawn O. Pearce","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"112892","messageId":"20090502234701.GL23604@spearce.org","threadId":"19161","inReplyTo":null,"subject":"bug in git diff --unified=0 ?","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-05-02T23:47:01Z","receivedAt":"2009-05-02T23:47:01Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"I can't decide if this is a bug in JGit, or a bug in CGit, or just\nan area where the patch format is very unclear.\n\nThe following 2 patches are identical, but use different context:\n\ngit diff --unified=1:\n\n    diff --git a/X b/X\n    index a3648a1..2d44096 100644\n    --- a/X\n    +++ b/X\n    @@ -2,2 +2,3 @@\n     b\n    +c\n     d\n    @@ -16,4 +17,2 @@\n     q\n    -r\n    -s\n     t\n\ngit diff --unified=0:\n\n    diff --git a/X b/X\n    index a3648a1..2d44096 100644\n    --- a/X\n    +++ b/X\n    @@ -2,0 +3 @@\n    +c\n    @@ -17,2 +17,0 @@\n    -r\n    -s\n    \nNow lets look at JGit's output of that last patch, unified=0:\n\n    diff --git a/X b/X\n    index a3648a1..2d44096 100644\n    --- a/X\n    +++ b/X\n    @@ -3,0 +3,1 @@\n    +c\n    @@ -17,2 +18,0 @@\n    -r\n    -s\n\nNotice that `git diff --unified=1` said the first hunk started on\nline 2 of the pre-image, as the 2nd line of the file is the context\nline \"b\\n\".  I call that correct.\n\nHowever, `git diff --unified=0` said the first hunk started on line\n2 of the pre-image, but there is no pre-image mentioned.  JGit says\nit starts on line 3 of the pre-image, because the script is adding\na \"c\\n\" on line 3.\n\nThe exact opposite behavior can be seen in the 2nd hunk, where we\ndelete lines.  Again, `git diff --unified=0` seems to behave as\nthough we had 1 line of context, but we don't.\n\n-- \nShawn.\n"},{"id":"112896","messageId":"7vocub59b3.fsf@alter.siamese.dyndns.org","threadId":"19161","inReplyTo":"20090502234701.GL23604@spearce.org","subject":"Re: bug in git diff --unified=0 ?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-03T00:17:36Z","receivedAt":"2009-05-03T00:17:36Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> I can't decide if this is a bug in JGit, or a bug in CGit, or just\n> an area where the patch format is very unclear.\n>\n> The following 2 patches are identical, but use different context:\n>\n> git diff --unified=1:\n>\n>     diff --git a/X b/X\n>     index a3648a1..2d44096 100644\n>     --- a/X\n>     +++ b/X\n>     @@ -2,2 +2,3 @@\n>      b\n>     +c\n>      d\n>     @@ -16,4 +17,2 @@\n>      q\n>     -r\n>     -s\n>      t\n>\n> git diff --unified=0:\n>\n>     diff --git a/X b/X\n>     index a3648a1..2d44096 100644\n>     --- a/X\n>     +++ b/X\n>     @@ -2,0 +3 @@\n>     +c\n>     @@ -17,2 +17,0 @@\n>     -r\n>     -s\n>     \n> Now lets look at JGit's output of that last patch, unified=0:\n>\n>     diff --git a/X b/X\n>     index a3648a1..2d44096 100644\n>     --- a/X\n>     +++ b/X\n>     @@ -3,0 +3,1 @@\n>     +c\n>     @@ -17,2 +18,0 @@\n>     -r\n>     -s\n\nI do not know what the current status of the POSIX draft for spliting\n\"context diff\" format into \"copied context\" and \"unified context\", but\nsee http://www.opengroup.org/austin/aardvark/latest/xcubug2.txt for the\ndefinition that was on track the last time I checked.\n\n    First the range of lines in each file shall be written in the\n    following format:\n\n    \"@@^-%s^+%s^@@\", <file1 range>, <file2 range>\n\n    Each <range> field shall be of the form:\n\n   \"%1d\", <beginning line number>\n\n    if the range contains exactly one line, and:\n\n   \"%1d,%1d\", <beginning line number>, <number of lines>\n\n    otherwise.  If a range is empty, its beginning line number shall be\n    the number of the line just before the range, or 0 if the empty\n    range starts the file.\n\nSo, JGit is wrong.\n"},{"id":"112897","messageId":"20090503002352.GP23604@spearce.org","threadId":"19161","inReplyTo":"7vocub59b3.fsf@alter.siamese.dyndns.org","subject":"Re: bug in git diff --unified=0 ?","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-05-03T00:23:52Z","receivedAt":"2009-05-03T00:23:52Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n> I do not know what the current status of the POSIX draft for spliting\n> \"context diff\" format into \"copied context\" and \"unified context\", but\n> see http://www.opengroup.org/austin/aardvark/latest/xcubug2.txt for the\n> definition that was on track the last time I checked.\n\nDoh.  Thank you for the clarification Junio.\n \n> So, JGit is wrong.\n\nYup, I agree.  /me works up a replacement patch.\n\n-- \nShawn.\n"},{"id":"112905","messageId":"7vy6ten4s0.fsf@alter.siamese.dyndns.org","threadId":"19161","inReplyTo":"7vocub59b3.fsf@alter.siamese.dyndns.org","subject":"Re: bug in git diff --unified=0 ?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-03T05:18:07Z","receivedAt":"2009-05-03T05:18:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n>\n> I do not know what the current status of the POSIX draft for spliting\n> \"context diff\" format into \"copied context\" and \"unified context\"...\n\nPOSIX 1003.1-2008 (base specifications issue 7) was published in December\n2008.\n\n    http://www.opengroup.org/onlinepubs/9699919799/toc.htm\n\nThe text in the part I quoted in the previous message seems to be\nunchanged.\n\n    http://www.opengroup.org/onlinepubs/9699919799/utilities/diff.html#tag_20_34_10_07\n"}]}