git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT PATCH 7/7] Add decorate option to log program
Date: Fri,  7 Nov 2008 23:07:44 +0100	[thread overview]
Message-ID: <1226095664-13759-8-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1226095664-13759-7-git-send-email-robin.rosenberg@dewire.com>

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/pgm/Log.java              |   33 ++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Log.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Log.java
index e3a32c8..bb424d4 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Log.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Log.java
@@ -40,11 +40,19 @@
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
 import java.util.TimeZone;
 
+import org.kohsuke.args4j.Option;
+import org.spearce.jgit.lib.AnyObjectId;
 import org.spearce.jgit.lib.PersonIdent;
+import org.spearce.jgit.lib.Ref;
 import org.spearce.jgit.revwalk.RevCommit;
+import org.spearce.jgit.revwalk.RevWalk;
 
 @Command(common = true, usage = "View commit history")
 class Log extends RevWalkTextBuiltin {
@@ -52,14 +60,39 @@
 
 	private final DateFormat fmt;
 
+	private Map<AnyObjectId, Set<Ref>> allRefsByPeeledObjectId;
+
+	@Option(name="--decorate", usage="Show ref names matching commits")
+	private boolean decorate;
+
 	Log() {
 		fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy ZZZZZ", Locale.US);
 	}
 
 	@Override
+	protected RevWalk createWalk() {
+		RevWalk ret = super.createWalk();
+		if (decorate)
+			allRefsByPeeledObjectId = getRepository().getAllRefsByPeeledObjectId();
+		return ret;
+	}
+
+	@Override
 	protected void show(final RevCommit c) throws Exception {
 		out.print("commit ");
 		c.getId().copyTo(outbuffer, out);
+		if (decorate) {
+			Collection<Ref> list = allRefsByPeeledObjectId.get(c.copy());
+			if (list != null) {
+				out.print(" (");
+				for (Iterator<Ref> i = list.iterator(); i.hasNext(); ) {
+					out.print(i.next().getOrigName());
+					if (i.hasNext())
+						out.print(" ");
+				}
+				out.print(")");
+			}
+		}
 		out.println();
 
 		final PersonIdent author = c.getAuthorIdent();
-- 
1.6.0.3.578.g6a50

  reply	other threads:[~2008-11-07 22:09 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-07 22:07 [J/E-GIT PATCH 0/7] Tag decoration v2 Robin Rosenberg
2008-11-07 22:07 ` [EGIT PATCH 1/7] Test the origName part of the key vs the ref itself Robin Rosenberg
2008-11-07 22:07   ` [EGIT PATCH 2/7] Add constant for "refs/" Robin Rosenberg
2008-11-07 22:07     ` [EGIT PATCH 3/7] Keep original ref name when reading refs Robin Rosenberg
2008-11-07 22:07       ` [EGIT PATCH 4/7] Handle peeling of loose refs Robin Rosenberg
2008-11-07 22:07         ` [EGIT PATCH 5/7] Add a method to get refs by object Id Robin Rosenberg
2008-11-07 22:07           ` [EGIT PATCH 6/7] Add tags to the graphical history display Robin Rosenberg
2008-11-07 22:07             ` Robin Rosenberg [this message]
2008-11-11 18:28             ` Shawn O. Pearce
2008-11-14  0:49               ` Robin Rosenberg
2008-11-11 18:32             ` Shawn O. Pearce
2008-11-14 23:24               ` [EGIT PATCH 1/7 v3] Add constant for "refs/" Robin Rosenberg
2008-11-14 23:24                 ` [EGIT PATCH 2/7 v3] Keep original ref name when reading refs Robin Rosenberg
2008-11-14 23:24                   ` [EGIT PATCH 3/7 v3] Test the origName part of the key vs the ref itself Robin Rosenberg
2008-11-14 23:24                     ` [EGIT PATCH 4/7 v3] Handle peeling of loose refs Robin Rosenberg
2008-11-14 23:24                       ` [EGIT PATCH 5/7 v3] Add a method to get refs by object Id Robin Rosenberg
2008-11-16 22:37                       ` [EGIT PATCH 4/7 v3] Handle peeling of loose refs Shawn O. Pearce
2008-11-11 18:26           ` [EGIT PATCH 5/7] Add a method to get refs by object Id Shawn O. Pearce
2008-11-11 18:23         ` [EGIT PATCH 4/7] Handle peeling of loose refs Shawn O. Pearce
2008-11-14  0:38           ` Robin Rosenberg
2008-11-11 18:05   ` [EGIT PATCH 1/7] Test the origName part of the key vs the ref itself Shawn O. Pearce
2008-11-13 22:13     ` Robin Rosenberg

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=1226095664-13759-8-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).