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

[EGIT PATCH 5/7 v3] Add a method to get refs by object Id

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Nov 14, 2008, 23:24 UTC
Message-ID
<1226705099-18066-5-git-send-email-robin.rosenberg@dewire.com>
In-Reply-To
<1226705099-18066-4-git-send-email-robin.rosenberg@dewire.com>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/lib/Repository.java       |   30 ++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index 4d6e6fd..5088150 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -47,10 +47,13 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.Vector;
 
 import org.spearce.jgit.errors.IncorrectObjectTypeException;
@@ -952,6 +955,33 @@ public Ref peel(final Ref ref) {
 	}
 
 	/**
+	 * @return a map with all objects referenced by a peeled ref.
+	 */
+	public Map<AnyObjectId, Set<Ref>> getAllRefsByPeeledObjectId() {
+		Map<String, Ref> allRefs = getAllRefs();
+		Map<AnyObjectId, Set<Ref>> ret = new HashMap<AnyObjectId, Set<Ref>>(allRefs.size());
+		for (Ref ref : allRefs.values()) {
+			if (!ref.isPeeled())
+				ref = peel(ref);
+			AnyObjectId target = ref.getPeeledObjectId();
+			if (target == null)
+				target = ref.getObjectId();
+			// We assume most Sets here are singletons
+			Set<Ref> oset = ret.put(target, Collections.singleton(ref));
+			if (oset != null) {
+				// that was not the case (rare)
+				if (oset.size() == 1) {
+					// Was a read-only singleton, we must copy to a new Set
+					oset = new HashSet<Ref>(oset);
+				}
+				ret.put(target, oset);
+				oset.add(ref);
+			}
+		}
+		return ret;
+	}
+
+	/**
 	 * @return true if HEAD points to a StGit patch.
 	 */
 	public boolean isStGitMode() {
-- 
1.6.0.3.640.g6331a.dirty
Previous: Robin RosenbergNext: Shawn O. Pearce
Message 16 of 22 in “Tag decoration v2”
  1. 0/7 Tag decoration v2Robin Rosenberg, Nov 7, 2008
  2. 1/7 Test the origName part of the key vs the ref itselfRobin Rosenberg, Nov 7, 2008
  3. 2/7 Add constant for "refs/"Robin Rosenberg, Nov 7, 2008
  4. 3/7 Keep original ref name when reading refsRobin Rosenberg, Nov 7, 2008
  5. 4/7 Handle peeling of loose refs.Robin Rosenberg, Nov 7, 2008
  6. 5/7 Add a method to get refs by object IdRobin Rosenberg, Nov 7, 2008
  7. 6/7 Add tags to the graphical history display.Robin Rosenberg, Nov 7, 2008
  8. 7/7 Add decorate option to log programRobin Rosenberg, Nov 7, 2008
  9. Shawn O. PearceNov 11, 2008
  10. Robin RosenbergNov 14, 2008
  11. Shawn O. PearceNov 11, 2008
  12. 1/7 Add constant for "refs/"Robin Rosenberg, Nov 14, 2008
  13. 2/7 Keep original ref name when reading refsRobin Rosenberg, Nov 14, 2008
  14. 3/7 Test the origName part of the key vs the ref itselfRobin Rosenberg, Nov 14, 2008
  15. 4/7 Handle peeling of loose refs.Robin Rosenberg, Nov 14, 2008
  16. 5/7 Add a method to get refs by object IdRobin Rosenberg, Nov 14, 2008
  17. Shawn O. PearceNov 16, 2008
  18. Shawn O. PearceNov 11, 2008
  19. Shawn O. PearceNov 11, 2008
  20. Robin RosenbergNov 14, 2008
  21. Shawn O. PearceNov 11, 2008
  22. Robin RosenbergNov 13, 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.