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

[JGIT PATCH 01/10] Fix TreeWalk.idEqual when both trees are missing the path

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 22, 2009, 23:28 UTC
Message-ID
<1232666890-23488-2-git-send-email-spearce@spearce.org>
In-Reply-To
<1232666890-23488-1-git-send-email-spearce@spearce.org>

The Javadoc of idEqual() says its simply a faster form of getObjectId(nthA).equals(getObjectId(nthB)), but its code didn't match that definition when both trees didn't exist at the current path.

If a tree doesn't exist for the current path getObjectId() returns ObjectId.zero(), indicating the "magic" 0{40} SHA-1 for the current path. If both tree entries don't exist for the current path, we should be doing a compare of ObjectId.zero() against ObjectId.zero(), which must be true as the values are the same.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
index ecf8851..414587c 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
@@ -616,7 +616,16 @@ public boolean idEqual(final int nthA, final int nthB) {
 		final AbstractTreeIterator ch = currentHead;
 		final AbstractTreeIterator a = trees[nthA];
 		final AbstractTreeIterator b = trees[nthB];
-		return a.matches == ch && b.matches == ch && a.idEqual(b);
+		if (a.matches == ch && b.matches == ch)
+			return a.idEqual(b);
+		if (a.matches != ch && b.matches != ch) {
+			// If neither tree matches the current path node then neither
+			// tree has this entry. In such case the ObjectId is zero(),
+			// and zero() is always equal to zero().
+			//
+			return true;
+		}
+		return false;
 	}
 
 	/**
-- 
1.6.1.399.g0d272
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 2 of 12 in “Merge API v2”
  1. 00/10 Merge API v2Shawn O. Pearce, Jan 22, 2009
  2. 01/10 Fix TreeWalk.idEqual when both trees are missing the pathShawn O. Pearce, Jan 22, 2009
  3. 02/10 Expose the raw path for the current entry of a TreeWalkShawn O. Pearce, Jan 22, 2009
  4. 03/10 Expose DirCacheEntry.getFileMode as a utility functionShawn O. Pearce, Jan 22, 2009
  5. 04/10 Add writeTree support to DirCacheShawn O. Pearce, Jan 22, 2009
  6. 05/10 Allow a DirCache to be created with no backing store fileShawn O. Pearce, Jan 22, 2009
  7. 06/10 Allow CanonicalTreeParsers to be created with a UTF-8 path prefixShawn O. Pearce, Jan 22, 2009
  8. 07/10 Recursively load an entire tree into a DirCacheBuilderShawn O. Pearce, Jan 22, 2009
  9. 08/10 Allow DirCacheEntry instances to be created with stage > 0Shawn O. Pearce, Jan 22, 2009
  10. 09/10 Define a basic merge API, and a two-way tree merge strategyShawn O. Pearce, Jan 22, 2009
  11. 10/10 Add a few simple merge test casesShawn O. Pearce, Jan 22, 2009
  12. Robin RosenbergJan 23, 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.