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

[JGIT PATCH 2/4] Fix pushing of annotated tags to actually include the tag object

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 9, 2008, 04:15 UTC
Message-ID
<1215576931-4174-3-git-send-email-spearce@spearce.org>
In-Reply-To
<1215576931-4174-2-git-send-email-spearce@spearce.org>

When we pushed an annotated tag to a remote repository jgit was failing to include the annotated tag object itself as ObjectWalk nextObject() failed to pop the object out of the internal pending queue and return it for inclusion in the generated pack file.

We need to use two different flags for SEEN and IN_PENDING as a blob or tree object can be SEEN during a TreeWalk, yet may also have been inserted into the pending object list. SEEN means we have output the object to the caller, IN_PENDING means we have placed it into the pending object list. Together these prevent duplicates in the queue and duplicate return values.

Noticed by Robin while trying to push an annotated tag:
  $ git tag -m foo X
  $ git rev-parse X
  49aa0e93621...
  $ jgit push somerepo refs/tags/X
  error: unpack should have generated 49aa0e93621...
  To somerepo.git
   ! [remote rejected] X -> X (bad pack)
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/revwalk/ObjectWalk.java   |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/ObjectWalk.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/ObjectWalk.java
index 6a5b857..1ba21eb 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/ObjectWalk.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/ObjectWalk.java
@@ -66,6 +66,15 @@ import org.spearce.jgit.treewalk.TreeWalk;
  * commits that are returned first.
  */
 public class ObjectWalk extends RevWalk {
+	/**
+	 * Indicates a non-RevCommit is in {@link #pendingObjects}.
+	 * <p>
+	 * We can safely reuse {@link RevWalk#REWRITE} here for the same value as it
+	 * is only set on RevCommit and {@link #pendingObjects} never has RevCommit
+	 * instances inserted into it.
+	 */
+	private static final int IN_PENDING = RevWalk.REWRITE;
+
 	private final TreeWalk treeWalk;
 
 	private BlockObjQueue pendingObjects;
@@ -361,8 +370,8 @@ public class ObjectWalk extends RevWalk {
 	}
 
 	private void addObject(final RevObject o) {
-		if ((o.flags & SEEN) == 0) {
-			o.flags |= SEEN;
+		if ((o.flags & IN_PENDING) == 0) {
+			o.flags |= IN_PENDING;
 			pendingObjects.add(o);
 		}
 	}
-- 
1.5.6.74.g8a5e
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 3 of 5 in “Misc. push transport fixes”
  1. 0/4 Misc. push transport fixesShawn O. Pearce, Jul 9, 2008
  2. 1/4 Avoid deadlock while fetching from local repositoryShawn O. Pearce, Jul 9, 2008
  3. 2/4 Fix pushing of annotated tags to actually include the tag objectShawn O. Pearce, Jul 9, 2008
  4. 3/4 Automatically initialize a new dumb repository during pushShawn O. Pearce, Jul 9, 2008
  5. 4/4 Use a singleton for the NullProgressMonitor implementationShawn O. Pearce, Jul 9, 2008

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.