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

[JGIT PATCH 8/6] Fix zero context insert and delete hunk headers to match CGit

From
Shawn O. Pearce <spearce@spearce.org>
Date
May 3, 2009, 00:14 UTC
Message-ID
<20090503001423.GO23604@spearce.org>
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
Previous: Shawn O. PearceNext: Miles Bader
Message 2 of 8 in “BROKEN: Add a zero line context test for diff.DiffFormatter”
  1. 7/6 BROKEN: Add a zero line context test for diff.DiffFormatterShawn O. Pearce, May 3, 2009
  2. 8/6 Fix zero context insert and delete hunk headers to match CGitShawn O. Pearce, May 3, 2009
  3. Miles BaderMay 3, 2009
  4. Robin RosenbergMay 3, 2009
  5. Ferry Huberts (Pelagic)May 3, 2009
  6. Robin RosenbergMay 3, 2009
  7. Ferry Huberts (Pelagic)May 3, 2009
  8. SZEDER GáborMay 5, 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.