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

[EGIT PATCH 2/6] Peel annotated tags when getting all refs

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Oct 5, 2008, 23:36 UTC
Message-ID
<1223249802-9959-3-git-send-email-robin.rosenberg@dewire.com>
In-Reply-To
<1223249802-9959-2-git-send-email-robin.rosenberg@dewire.com>

For packed refs we got this automatically from packed-refs, but for loose tags we have to follow the tags and get the leaf object in order to comply with the documentation.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/lib/RefDatabase.java      |   24 ++++++++++++++++++-
 1 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
index 5a1b85f..1ee70d9 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
@@ -271,7 +271,16 @@ private void readOneLooseRef(final Map<String, Ref> avail,
 					return;
 				}
 
-				ref = new Ref(Ref.Storage.LOOSE, origName, refName, id);
+				Object tt = db.mapObject(id, refName);
+				if (tt != null && tt instanceof Tag) {
+					Tag t = (Tag)tt;
+					while (t != null && t.getType().equals(Constants.TYPE_TAG))
+						t = db.mapTag(t.getTag(), t.getObjId());
+					if (t != null)
+						ref = new Ref(Ref.Storage.LOOSE, origName, refName, id, t.getObjId());
+				} else
+					ref = new Ref(Ref.Storage.LOOSE, origName, refName, id);
+
 				looseRefs.put(ref.getName(), ref);
 				looseRefsMTime.put(ref.getName(), ent.lastModified());
 				avail.put(ref.getName(), ref);
@@ -363,7 +372,18 @@ private Ref readRefBasic(final String origName, final String name, final int dep
 			throw new IOException("Not a ref: " + name + ": " + line);
 		}
 
-		ref = new Ref(Ref.Storage.LOOSE, origName, name, id);
+		Object tt = db.mapObject(id, origName);
+		if (tt != null && tt instanceof Tag) {
+			Tag t = (Tag)tt;
+			while (t != null && t.getType().equals(Constants.TYPE_TAG))
+				t = db.mapTag(t.getTag(), t.getObjId());
+			if (t != null)
+				ref = new Ref(Ref.Storage.LOOSE, origName, name, id, t.getObjId());
+		} else
+			ref = new Ref(Ref.Storage.LOOSE, origName, name, id);
+
+		looseRefs.put(origName, ref);
+		ref = new Ref(Ref.Storage.LOOSE, origName, id);
 		looseRefs.put(name, ref);
 		looseRefsMTime.put(name, mtime);
 		return ref;
-- 
1.6.0.1.310.gf789d0.dirty
Previous: Robin RosenbergNext: Robin Rosenberg
Message 3 of 14 in “(unknown)”
  1. Robin RosenbergOct 5, 2008
  2. 1/6 Keep original ref name when reading refsRobin Rosenberg, Oct 5, 2008
  3. 2/6 Peel annotated tags when getting all refsRobin Rosenberg, Oct 5, 2008
  4. 3/6 Add a method to get refs by object IdRobin Rosenberg, Oct 5, 2008
  5. 4/6 Add tags to the graphical history display.Robin Rosenberg, Oct 5, 2008
  6. 5/6 Add decorate option to log programRobin Rosenberg, Oct 5, 2008
  7. 6/6 Comment the getId method and hint for copy to actually get an ObjectIdRobin Rosenberg, Oct 5, 2008
  8. Shawn O. PearceOct 6, 2008
  9. Robin RosenbergOct 6, 2008
  10. Shawn O. PearceOct 6, 2008
  11. Shawn O. PearceOct 6, 2008
  12. Robin RosenbergOct 6, 2008
  13. Shawn O. PearceOct 6, 2008
  14. Shawn O. PearceOct 6, 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.