From 84212d382d60904a356755295e8d06a8c3366553 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sat, 15 Nov 2008 00:24:59 +0100 Subject: [PATCH] Add a method to get refs by object Id Signed-off-by: Robin Rosenberg Signed-off-by: Shawn O. Pearce --- .../src/org/spearce/jgit/lib/Repository.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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 4d6e6fd4..5088150d 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.FilenameFilter; 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 class Repository { } /** + * @return a map with all objects referenced by a peeled ref. + */ + public Map> getAllRefsByPeeledObjectId() { + Map allRefs = getAllRefs(); + Map> ret = new HashMap>(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 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(oset); + } + ret.put(target, oset); + oset.add(ref); + } + } + return ret; + } + + /** * @return true if HEAD points to a StGit patch. */ public boolean isStGitMode() { -- 2.11.4.GIT