git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: git@vger.kernel.org
Cc: spearce@spearce.org, Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT PATCH 3/6] Add a method to get refs by object Id
Date: Mon,  6 Oct 2008 01:36:39 +0200	[thread overview]
Message-ID: <1223249802-9959-4-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1223249802-9959-3-git-send-email-robin.rosenberg@dewire.com>

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/lib/Repository.java       |   28 ++++++++++++++++++++
 1 files changed, 28 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 dfce1b8..3fc5236 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -47,6 +47,7 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -939,6 +940,33 @@ public String getBranch() throws IOException {
 	}
 
 	/**
+	 * @return a map with all objects referenced by a peeled ref.
+	 */
+	public Map<AnyObjectId, List<Ref>> getAllRefsByPeeledObjectId() {
+		Map<String, Ref> allRefs = getAllRefs();
+		HashMap<AnyObjectId, List<Ref>> ret = new HashMap<AnyObjectId, List<Ref>>(allRefs.size());
+		for (Map.Entry<String,Ref> e : allRefs.entrySet()) {
+			Ref ref = e.getValue();
+			AnyObjectId target = ref.getPeeledObjectId();
+			if (target == null)
+				target = ref.getObjectId();
+			List<Ref> list = ret.get(target);
+			if (list == null) {
+				list = Collections.singletonList(ref);
+			} else {
+				if (list.size() == 1) {
+					ArrayList<Ref> list2 = new ArrayList<Ref>(2);
+					list2.add(list.get(0));
+					list = list2;
+				}
+				list.add(ref);
+			}
+			ret.put(target, list);
+		}
+		return ret;
+	}
+
+	/**
 	 * @return true if HEAD points to a StGit patch.
 	 */
 	public boolean isStGitMode() {
-- 
1.6.0.1.310.gf789d0.dirty

  reply	other threads:[~2008-10-05 23:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-05 23:36 (unknown), Robin Rosenberg
2008-10-05 23:36 ` [EGIT PATCH 1/6] Keep original ref name when reading refs Robin Rosenberg
2008-10-05 23:36   ` [EGIT PATCH 2/6] Peel annotated tags when getting all refs Robin Rosenberg
2008-10-05 23:36     ` Robin Rosenberg [this message]
2008-10-05 23:36       ` [EGIT PATCH 4/6] Add tags to the graphical history display Robin Rosenberg
2008-10-05 23:36         ` [EGIT PATCH 5/6] Add decorate option to log program Robin Rosenberg
2008-10-05 23:36           ` [EGIT PATCH 6/6] Comment the getId method and hint for copy to actually get an ObjectId Robin Rosenberg
2008-10-06  8:08         ` [EGIT PATCH 4/6] Add tags to the graphical history display Shawn O. Pearce
2008-10-06 21:58           ` Robin Rosenberg
2008-10-06 22:14             ` Shawn O. Pearce
2008-10-06  8:15       ` [EGIT PATCH 3/6] Add a method to get refs by object Id Shawn O. Pearce
2008-10-06 22:37         ` Robin Rosenberg
2008-10-06 22:43           ` Shawn O. Pearce
2008-10-06  7:43     ` [EGIT PATCH 2/6] Peel annotated tags when getting all refs Shawn O. Pearce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1223249802-9959-4-git-send-email-robin.rosenberg@dewire.com \
    --to=robin.rosenberg@dewire.com \
    --cc=git@vger.kernel.org \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).