git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: git@vger.kernel.org
Subject: bug in git diff --unified=0 ?
Date: Sat, 2 May 2009 16:47:01 -0700	[thread overview]
Message-ID: <20090502234701.GL23604@spearce.org> (raw)

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

Notice that `git diff --unified=1` said the first hunk started on
line 2 of the pre-image, as the 2nd line of the file is the context
line "b\n".  I call that correct.

However, `git diff --unified=0` said the first hunk started on line
2 of the pre-image, but there is no pre-image mentioned.  JGit says
it starts on line 3 of the pre-image, because the script is adding
a "c\n" on line 3.

The exact opposite behavior can be seen in the 2nd hunk, where we
delete lines.  Again, `git diff --unified=0` seems to behave as
though we had 1 line of context, but we don't.

-- 
Shawn.

             reply	other threads:[~2009-05-02 23:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-02 23:47 Shawn O. Pearce [this message]
2009-05-03  0:17 ` bug in git diff --unified=0 ? Junio C Hamano
2009-05-03  0:23   ` Shawn O. Pearce
2009-05-03  5:18   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090502234701.GL23604@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).