git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH 8/6] Fix zero context insert and delete hunk headers to match CGit
Date: Sat, 2 May 2009 17:14:23 -0700	[thread overview]
Message-ID: <20090503001423.GO23604@spearce.org> (raw)
In-Reply-To: <20090503000540.GN23604@spearce.org>

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
  "Shawn O. Pearce" <spearce@spearce.org> wrote:
  >  This test currently fails because it shows the difference between
  >  the way CGit and JGit number a zero context line patch.
  > 
  >  Either we hack JGit to match CGit here

  And here is that hack.  It just feels wrong to me that I need
  to subtract 1 from the Edit region's line numbers, *only* when
  context is 0, in order to get the same output as CGit.

 .../src/org/spearce/jgit/diff/DiffFormatter.java   |   23 ++++++++++++++++---
 1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/diff/DiffFormatter.java b/org.spearce.jgit/src/org/spearce/jgit/diff/DiffFormatter.java
index 97db9a2..9930904 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/diff/DiffFormatter.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/diff/DiffFormatter.java
@@ -120,7 +120,7 @@ private void formatEdits(final OutputStream out, final RawText a,
 			final int aEnd = Math.min(a.size(), endEdit.getEndA() + context);
 			final int bEnd = Math.min(b.size(), endEdit.getEndB() + context);
 
-			writeHunkHeader(out, aCur, aEnd, bCur, bEnd, curIdx == 0);
+			writeHunkHeader(out, aCur, aEnd, bCur, bEnd, curEdit, curIdx == 0);
 
 			while (aCur < aEnd || bCur < bEnd) {
 				if (aCur < curEdit.getBeginA() || endIdx + 1 < curIdx) {
@@ -141,9 +141,24 @@ private void formatEdits(final OutputStream out, final RawText a,
 		}
 	}
 
-	private void writeHunkHeader(final OutputStream out, final int aCur,
-			final int aEnd, final int bCur, final int bEnd,
-			final boolean firstHunk) throws IOException {
+	private void writeHunkHeader(final OutputStream out, int aCur, int aEnd,
+			int bCur, int bEnd, final Edit curEdit, final boolean firstHunk)
+			throws IOException {
+		if (context == 0) {
+			switch (curEdit.getType()) {
+			case INSERT:
+				aCur--;
+				aEnd--;
+				break;
+			case DELETE:
+				bCur--;
+				bEnd--;
+				break;
+			default:
+				break;
+			}
+		}
+
 		out.write('@');
 		out.write('@');
 		if (firstHunk) {
-- 
1.6.3.rc4.190.g4648

  reply	other threads:[~2009-05-03  0:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-03  0:05 [JGIT PATCH 7/6] BROKEN: Add a zero line context test for diff.DiffFormatter Shawn O. Pearce
2009-05-03  0:14 ` Shawn O. Pearce [this message]
2009-05-03  0:50   ` [JGIT PATCH 8/6] Fix zero context insert and delete hunk headers to match CGit Miles Bader
2009-05-03  8:25     ` Robin Rosenberg
2009-05-03  8:31       ` Ferry Huberts (Pelagic)
2009-05-03  9:24         ` Robin Rosenberg
2009-05-03  9:29           ` Ferry Huberts (Pelagic)
2009-05-05 22:19           ` SZEDER Gábor

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=20090503001423.GO23604@spearce.org \
    --to=spearce@spearce.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    /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).