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

Re: [JGIT PATCH 2/3] Fix ObjectWalk to handle single-entry subtrees correctly

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 13, 2009, 18:37 UTC
Message-ID
<20090313183703.GG22920@spearce.org>
In-Reply-To
<1236967912-15088-2-git-send-email-spearce@spearce.org>
"Shawn O. Pearce" <spearce@spearce.org> wrote:
Show 23 quoted lines
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
> index 8028b14..5c331ca 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
> @@ -145,8 +145,19 @@ public CanonicalTreeParser resetRoot(final Repository repo,
>  
>  	/** @return this iterator, or its parent, if the tree is at eof. */
>  	public CanonicalTreeParser next() {
> -		next(1);
> -		return eof() && parent != null ? (CanonicalTreeParser) parent : this;
> +		CanonicalTreeParser p = this;
> +		for (;;) {
> +			p.next(1);
> +			if (p.eof() && parent != null) {
> +				// Parent was left pointing at the entry for us; advance
> +				// the parent to the next entry, possibly unwinding many
> +				// levels up the tree.
> +				//
> +				p = (CanonicalTreeParser) p.parent;
> +				continue;
> +			}
> +			return p;
> +		}
The parent != null test is wrong, we need "p.parent" here:
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
index 5c331ca..7f89cff 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
@@ -148,7 +148,7 @@ public CanonicalTreeParser next() {
 		CanonicalTreeParser p = this;
 		for (;;) {
 			p.next(1);
-			if (p.eof() && parent != null) {
+			if (p.eof() && p.parent != null) {
 				// Parent was left pointing at the entry for us; advance
 				// the parent to the next entry, possibly unwinding many
 				// levels up the tree.
-- 
Shawn.
Previous: Shawn O. Pearce
Message 6 of 6 in “Add lookupBlob to RevWalk”
  1. 1/3 Add lookupBlob to RevWalkShawn O. Pearce, Mar 13, 2009
  2. 2/3 Fix ObjectWalk to handle single-entry subtrees correctlyShawn O. Pearce, Mar 13, 2009
  3. 3/3 Use a common skipObject method to avoid UNINTERESTING itemsShawn O. Pearce, Mar 13, 2009
  4. Robin RosenbergMar 15, 2009
  5. Shawn O. PearceMar 16, 2009
  6. Shawn O. PearceMar 13, 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.