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

[EGIT PATCH 7/7] Add decorate option to log program

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Nov 7, 2008, 22:07 UTC
Message-ID
<1226095664-13759-8-git-send-email-robin.rosenberg@dewire.com>
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
Previous: Robin RosenbergNext: Shawn O. Pearce
Message 8 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.