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

[RFC PATCH 4/4] Teach pretty-printer new reflog format codes

From
Deskin Miller <deskinm@umich.edu>
Date
Feb 26, 2009, 04:44 UTC
Message-ID
<eee1f8e216d3813a1dce153dae58aeda5412c418.1235622145.git.deskinm@umich.edu>
In-Reply-To
<cover.1235622145.git.deskinm@umich.edu>

By using %r<char>, one may obtain information from the reflog when using --pretty=format in conjunction with git log -g or git rev-list --walk-reflogs. The following format codes are supported:

%rp, %rP: abbreviated and full old commit hash %rm: reflog message %rn, %re, %rt, %rd, etc: all the formats that work for committer and author work with the reflog printer as well.

Signed-off-by: Deskin Miller <deskinm@umich.edu>
---
 pretty.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/pretty.c b/pretty.c
index 6cd9149..9303958 100644
--- a/pretty.c
+++ b/pretty.c
@@ -7,6 +7,7 @@
 #include "mailmap.h"
 #include "log-tree.h"
 #include "color.h"
+#include "reflog-walk.h"
 
 static char *user_format;
 
@@ -544,6 +545,40 @@ static void format_decoration(struct strbuf *sb, const struct commit *commit)
 		strbuf_addch(sb, ')');
 }
 
+static size_t format_reflog_item(struct strbuf *sb, void *util, char part,
+				 enum date_mode dmode)
+{
+	struct reflog_info *reflog_info = (struct reflog_info *)util;
+	struct strbuf buf = STRBUF_INIT;
+	ssize_t ret;
+
+	if (!util) {
+		return 0;
+	}
+
+	switch (part) {
+	case 'P':
+		strbuf_addstr(sb, sha1_to_hex(reflog_info->osha1));
+		return 2;
+	case 'p':		/* abbreviated commit hash */
+		strbuf_addstr(sb, find_unique_abbrev(reflog_info->osha1,
+						DEFAULT_ABBREV));
+		return 2;
+	case 'm':
+		/* don't print trailing newline */
+		strbuf_add(sb, reflog_info->message,
+			   strlen(reflog_info->message) - 1);
+		return 2;
+	}
+
+	strbuf_addf(&buf, "%s %lu %+04d", reflog_info->email,
+		reflog_info->timestamp, reflog_info->tz);
+	ret = format_person_part(sb, part, buf.buf, buf.len, dmode);
+	strbuf_release(&buf);
+	return ret;
+
+}
+
 static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
                                void *context)
 {
@@ -650,6 +685,9 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
 	case 'd':
 		format_decoration(sb, commit);
 		return 1;
+	case 'r':
+		return format_reflog_item(sb, commit->util, placeholder[1],
+					c->dmode);
 	}
 
 	/* For the rest we have to parse the commit header. */
-- 
1.6.2.rc0.90.g0753
Previous: Deskin MillerNext: Johannes Schindelin
Message 5 of 7 in “git log -g --pretty=format: learns about reflog”
  1. 0/4 git log -g --pretty=format: learns about reflogDeskin Miller, Feb 26, 2009
  2. 1/4 Expose reflog_info struct in headerDeskin Miller, Feb 26, 2009
  3. 2/4 Add attach_reflog_infoDeskin Miller, Feb 26, 2009
  4. 3/4 Attach reflog to commit prior to pretty-printingDeskin Miller, Feb 26, 2009
  5. 4/4 Teach pretty-printer new reflog format codesDeskin Miller, Feb 26, 2009
  6. Johannes SchindelinFeb 26, 2009
  7. Jeff KingFeb 26, 2009

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.