pretty: give placeholders to reflog identity
When doing a reflog walk, you can get some information about the reflog (such as the subject line), but not the identity information (i.e., name and email). Let's make those available, mimicing the options for author and committer identity. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Dec 16, 2011 at 06:40 UTC
cd1957f5fc6ecc5ae557246126d9e74c029ccd61
5 files changed
+48
Documentation/pretty-formats.txt
+4
@@ -132,6 +132,10 @@ The placeholders are:
132
- '%N': commit notes
133
- '%gD': reflog selector, e.g., `refs/stash@\{1\}`
134
- '%gd': shortened reflog selector, e.g., `stash@\{1\}`
135
+- '%gn': reflog identity name
136
+- '%gN': reflog identity name (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])
137
+- '%ge': reflog identity email
138
+- '%gE': reflog identity email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])
139
- '%gs': reflog subject
140
- '%Cred': switch color to red
141
- '%Cgreen': switch color to green
pretty.c
+25
@@ -822,6 +822,23 @@ static void rewrap_message_tail(struct strbuf *sb,
822
c->indent2 = new_indent2;
823
}
824
825
+static int format_reflog_person(struct strbuf *sb,
826
+ char part,
827
+ struct reflog_walk_info *log,
828
+ enum date_mode dmode)
829
+{
830
+ const char *ident;
831
+
832
+ if (!log)
833
+ return 2;
834
+
835
+ ident = get_reflog_ident(log);
836
+ if (!ident)
837
+ return 2;
838
+
839
+ return format_person_part(sb, part, ident, strlen(ident), dmode);
840
+}
841
+
842
static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
843
void *context)
844
{
@@ -963,6 +980,14 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
980
if (c->pretty_ctx->reflog_info)
981
get_reflog_message(sb, c->pretty_ctx->reflog_info);
982
return 2;
983
+ case 'n':
984
+ case 'N':
985
+ case 'e':
986
+ case 'E':
987
+ return format_reflog_person(sb,
988
+ placeholder[1],
989
+ c->pretty_ctx->reflog_info,
990
+ c->pretty_ctx->date_mode);
991
}
992
return 0; /* unknown %g placeholder */
993
case 'N':
reflog-walk.c
+12
@@ -291,6 +291,18 @@ void get_reflog_message(struct strbuf *sb,
291
strbuf_add(sb, info->message, len);
292
}
293
294
+const char *get_reflog_ident(struct reflog_walk_info *reflog_info)
295
+{
296
+ struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
297
+ struct reflog_info *info;
298
+
299
+ if (!commit_reflog)
300
+ return NULL;
301
+
302
+ info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
303
+ return info->email;
304
+}
305
+
306
void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
307
enum date_mode dmode)
308
{
reflog-walk.h
+1
@@ -14,6 +14,7 @@ extern void show_reflog_message(struct reflog_walk_info *info, int,
14
enum date_mode);
15
extern void get_reflog_message(struct strbuf *sb,
16
struct reflog_walk_info *reflog_info);
17
+extern const char *get_reflog_ident(struct reflog_walk_info *reflog_info);
18
extern void get_reflog_selector(struct strbuf *sb,
19
struct reflog_walk_info *reflog_info,
20
enum date_mode dmode,
t/t6006-rev-list-format.sh
+6
@@ -267,6 +267,12 @@ test_expect_success '%gd shortens ref name' '
267
test_cmp expect.gd-short actual.gd-short
268
'
269
270
+test_expect_success 'reflog identity' '
271
+ echo "C O Mitter:committer@example.com" >expect &&
272
+ git log -g -1 --format="%gn:%ge" >actual &&
273
+ test_cmp expect actual
274
+'
275
+
276
test_expect_success 'oneline with empty message' '
277
git commit -m "dummy" --allow-empty &&
278
git commit -m "dummy" --allow-empty &&