{"thread":{"id":"29181","subject":"[PATCH] pretty: give placeholders to reflog identity","startedAt":"2011-12-16T11:40:24Z","lastAt":"2011-12-16T21:04:05Z","messageCount":2,"participants":["Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"181290","messageId":"20111216114024.GA16965@sigill.intra.peff.net","threadId":"29181","inReplyTo":null,"subject":"[PATCH] pretty: give placeholders to reflog identity","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-16T11:40:24Z","receivedAt":"2011-12-16T11:40:24Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"When doing a reflog walk, you can get some information about\nthe reflog (such as the subject line), but not the identity\ninformation (i.e., name and email).\n\nLet's make those available, mimicing the options for author\nand committer identity.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nInitial posting and discussion here:\n\n  http://thread.gmane.org/gmane.comp.version-control.git/185043\n\nResponse was positive, but we were in 1.7.8 release freeze, so you asked\nme to hold and re-post.\n\n Documentation/pretty-formats.txt |    4 ++++\n pretty.c                         |   25 +++++++++++++++++++++++++\n reflog-walk.c                    |   12 ++++++++++++\n reflog-walk.h                    |    1 +\n t/t6006-rev-list-format.sh       |    6 ++++++\n 5 files changed, 48 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\nindex 561cc9f..880b6f2 100644\n--- a/Documentation/pretty-formats.txt\n+++ b/Documentation/pretty-formats.txt\n@@ -132,6 +132,10 @@ The placeholders are:\n - '%N': commit notes\n - '%gD': reflog selector, e.g., `refs/stash@\\{1\\}`\n - '%gd': shortened reflog selector, e.g., `stash@\\{1\\}`\n+- '%gn': reflog identity name\n+- '%gN': reflog identity name (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])\n+- '%ge': reflog identity email\n+- '%gE': reflog identity email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])\n - '%gs': reflog subject\n - '%Cred': switch color to red\n - '%Cgreen': switch color to green\ndiff --git a/pretty.c b/pretty.c\nindex 230fe1c..1580299 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -822,6 +822,23 @@ static void rewrap_message_tail(struct strbuf *sb,\n \tc->indent2 = new_indent2;\n }\n \n+static int format_reflog_person(struct strbuf *sb,\n+\t\t\t\tchar part,\n+\t\t\t\tstruct reflog_walk_info *log,\n+\t\t\t\tenum date_mode dmode)\n+{\n+\tconst char *ident;\n+\n+\tif (!log)\n+\t\treturn 2;\n+\n+\tident = get_reflog_ident(log);\n+\tif (!ident)\n+\t\treturn 2;\n+\n+\treturn format_person_part(sb, part, ident, strlen(ident), dmode);\n+}\n+\n static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \t\t\t\tvoid *context)\n {\n@@ -963,6 +980,14 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \t\t\tif (c->pretty_ctx->reflog_info)\n \t\t\t\tget_reflog_message(sb, c->pretty_ctx->reflog_info);\n \t\t\treturn 2;\n+\t\tcase 'n':\n+\t\tcase 'N':\n+\t\tcase 'e':\n+\t\tcase 'E':\n+\t\t\treturn format_reflog_person(sb,\n+\t\t\t\t\t\t    placeholder[1],\n+\t\t\t\t\t\t    c->pretty_ctx->reflog_info,\n+\t\t\t\t\t\t    c->pretty_ctx->date_mode);\n \t\t}\n \t\treturn 0;\t/* unknown %g placeholder */\n \tcase 'N':\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex da71a85..c7095b7 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -294,6 +294,18 @@ void get_reflog_message(struct strbuf *sb,\n \tstrbuf_add(sb, info->message, len);\n }\n \n+const char *get_reflog_ident(struct reflog_walk_info *reflog_info)\n+{\n+\tstruct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;\n+\tstruct reflog_info *info;\n+\n+\tif (!commit_reflog)\n+\t\treturn NULL;\n+\n+\tinfo = &commit_reflog->reflogs->items[commit_reflog->recno+1];\n+\treturn info->email;\n+}\n+\n void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,\n \tenum date_mode dmode)\n {\ndiff --git a/reflog-walk.h b/reflog-walk.h\nindex 7bd2cd4..afb1ae3 100644\n--- a/reflog-walk.h\n+++ b/reflog-walk.h\n@@ -14,6 +14,7 @@ extern void show_reflog_message(struct reflog_walk_info *info, int,\n \t\tenum date_mode);\n extern void get_reflog_message(struct strbuf *sb,\n \t\tstruct reflog_walk_info *reflog_info);\n+extern const char *get_reflog_ident(struct reflog_walk_info *reflog_info);\n extern void get_reflog_selector(struct strbuf *sb,\n \t\tstruct reflog_walk_info *reflog_info,\n \t\tenum date_mode dmode,\ndiff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh\nindex d918cc0..4442790 100755\n--- a/t/t6006-rev-list-format.sh\n+++ b/t/t6006-rev-list-format.sh\n@@ -267,6 +267,12 @@ test_expect_success '%gd shortens ref name' '\n \ttest_cmp expect.gd-short actual.gd-short\n '\n \n+test_expect_success 'reflog identity' '\n+\techo \"C O Mitter:committer@example.com\" >expect &&\n+\tgit log -g -1 --format=\"%gn:%ge\" >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'oneline with empty message' '\n \tgit commit -m \"dummy\" --allow-empty &&\n \tgit commit -m \"dummy\" --allow-empty &&\n-- \n1.7.7.4.13.g57bf4\n"},{"id":"181336","messageId":"7vr504grei.fsf@alter.siamese.dyndns.org","threadId":"29181","inReplyTo":"20111216114024.GA16965@sigill.intra.peff.net","subject":"Re: [PATCH] pretty: give placeholders to reflog identity","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-12-16T21:04:05Z","receivedAt":"2011-12-16T21:04:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Makes sense; thanks.\n\nWith the existing helper format_person_part(), this is surprisingly\nsimple. Perhaps I should not be surprised ;-).\n"}]}