{"thread":{"id":"28866","subject":"pretty placeholders for reflog entries","startedAt":"2011-11-07T05:49:48Z","lastAt":"2011-11-10T01:56:54Z","messageCount":7,"participants":["Jack Nagel","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"179002","messageId":"CAMYxyaWPWVGUHz0qQOnARb9wexHCx73a04Bu_UhrJR=xrinX7g@mail.gmail.com","threadId":"28866","inReplyTo":null,"subject":"pretty placeholders for reflog entries","fromName":"Jack Nagel","fromEmail":"jacknagel@gmail.com","sentAt":"2011-11-07T05:49:48Z","receivedAt":"2011-11-07T05:49:48Z","isPatch":false,"sender":{"key":"jacknagel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/568243?v=4"},"body":"I have the reflog enabled on a bare repo so that I can have a record of\n\"who pushed what, when\". I'd like to define a custom pretty format for\nuse with \"git log -g\" for reading it, but unfortunately the placeholders\nfor reflog information are somewhat limited. In particular, I'd like to\nbe able to access the identity (i.e., name and email) and date from each\nreflog entry.\n\nIs it possible to extract this information in current git? Perhaps I\noverlooked something.\n\nI suppose it would be simple enough to just write a script to parse the\nreflog file(s), but it would be nice to be able to do this with git\nitself.\n\nThanks.\n\nJack\n"},{"id":"179076","messageId":"20111107211325.GB7380@sigill.intra.peff.net","threadId":"28866","inReplyTo":"CAMYxyaWPWVGUHz0qQOnARb9wexHCx73a04Bu_UhrJR=xrinX7g@mail.gmail.com","subject":"Re: pretty placeholders for reflog entries","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-11-07T21:13:25Z","receivedAt":"2011-11-07T21:13:25Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 06, 2011 at 11:49:48PM -0600, Jack Nagel wrote:\n\n> I have the reflog enabled on a bare repo so that I can have a record of\n> \"who pushed what, when\". I'd like to define a custom pretty format for\n> use with \"git log -g\" for reading it, but unfortunately the placeholders\n> for reflog information are somewhat limited. In particular, I'd like to\n> be able to access the identity (i.e., name and email) and date from each\n> reflog entry.\n> \n> Is it possible to extract this information in current git? Perhaps I\n> overlooked something.\n\nSorry, but there aren't convenient placeholders for that. There probably\nshould be.\n\nAs a workaround, you can get the reflog selector (\"%gD\"), and then\ncross-reference it with the output of \"git log -g\". But obviously that's\ninefficient and a giant pain. We really should have \"%gn\" and \"%ge\" for\nthe reflog name and email. And related date options, though annoyingly\n\"%gd\" is already taken for the default format.\n\nI doubt it would be a very big patch. Want to get your feet wet in git\ndevelopment? :)\n\n-Peff\n"},{"id":"179086","messageId":"CAMYxyaWJO7e8Lg__8N9BhL16mwfQtd-GBuLpBSCYmLMZ3gsMPA@mail.gmail.com","threadId":"28866","inReplyTo":"20111107211325.GB7380@sigill.intra.peff.net","subject":"Re: pretty placeholders for reflog entries","fromName":"Jack Nagel","fromEmail":"jacknagel@gmail.com","sentAt":"2011-11-07T21:41:29Z","receivedAt":"2011-11-07T21:41:29Z","isPatch":false,"sender":{"key":"jacknagel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/568243?v=4"},"body":"On Mon, Nov 7, 2011 at 3:13 PM, Jeff King <peff@peff.net> wrote:\n> I doubt it would be a very big patch. Want to get your feet wet in git\n> development? :)\n\nI'll certainly give it a shot if I find some free time to do so. Though if\nsomeone else felt like doing it in the meantime, my feelings wouldn't be\nhurt. =)\n\nJack\n"},{"id":"179093","messageId":"20111107224556.GA28188@sigill.intra.peff.net","threadId":"28866","inReplyTo":"CAMYxyaWJO7e8Lg__8N9BhL16mwfQtd-GBuLpBSCYmLMZ3gsMPA@mail.gmail.com","subject":"Re: pretty placeholders for reflog entries","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-11-07T22:45:56Z","receivedAt":"2011-11-07T22:45:56Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Nov 07, 2011 at 03:41:29PM -0600, Jack Nagel wrote:\n\n> On Mon, Nov 7, 2011 at 3:13 PM, Jeff King <peff@peff.net> wrote:\n> > I doubt it would be a very big patch. Want to get your feet wet in git\n> > development? :)\n> \n> I'll certainly give it a shot if I find some free time to do so. Though if\n> someone else felt like doing it in the meantime, my feelings wouldn't be\n> hurt. =)\n\nActually, it needed to touch a few ugly corners of the code, so I just\nwent ahead and did it. The result is below.\n\n-- >8 --\nSubject: [PATCH] pretty: give placeholders to reflog identity\n\nWhen 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---\nWe're still missing date specifiers. However, if you specify a \"--date\"\nflag, then the reflog selector (\"%gd\") will have the date inside the\ncurly braces instead of the reflog counter.\n\nIt would be a little nicer to provide explicit date placeholders, but we\ncan't quite make them match the author-date specifiers, because \"gd\" is\ntaken.  We could add %gt, %gr, etc. But in the long run, I'd like to\nmove to considering most of %ar, %at, etc to be historical, and have\nsomething like \"%ad(short)\" be the official way of picking different\ndate formats[1]. And then the reflog placeholders could learn\n\"%gt(short)\". So making more reflog placeholders right now just feels\nlike cluttering a namespace I'd like to get changed eventually.\n\nSo I think in the meantime, this is a good start.\n\n[1] I floated some patches about 8 months ago, and Will Palmer had some,\n    too. I really need to take a look at them and push the topic forward.\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 5d81d39..590737e 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -291,6 +291,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.2.7.g9f96f.dirty\n"},{"id":"179097","messageId":"7v8vnr1oww.fsf@alter.siamese.dyndns.org","threadId":"28866","inReplyTo":"20111107224556.GA28188@sigill.intra.peff.net","subject":"Re: pretty placeholders for reflog entries","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-11-07T23:41:19Z","receivedAt":"2011-11-07T23:41:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> It would be a little nicer to provide explicit date placeholders, but we\n> can't quite make them match the author-date specifiers, because \"gd\" is\n> taken.  We could add %gt, %gr, etc. But in the long run, I'd like to\n> move to considering most of %ar, %at, etc to be historical, and have\n> something like \"%ad(short)\" be the official way of picking different\n> date formats[1]. And then the reflog placeholders could learn\n> \"%gt(short)\". So making more reflog placeholders right now just feels\n> like cluttering a namespace I'd like to get changed eventually.\n\nI tend to agree with the direction.\n\nAs we are not adding anything new before the 1.7.8 final, I'd rather ask\nyou to hold onto this and other changes in your footnote, instead of\nhaving me to carry them in 'pu', which is an integration branch even less\nofficial than it would otherwise be during the freeze period.\n"},{"id":"179124","messageId":"20111108054745.GD29643@sigill.intra.peff.net","threadId":"28866","inReplyTo":"7v8vnr1oww.fsf@alter.siamese.dyndns.org","subject":"Re: pretty placeholders for reflog entries","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-11-08T05:47:45Z","receivedAt":"2011-11-08T05:47:45Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Nov 07, 2011 at 03:41:19PM -0800, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > It would be a little nicer to provide explicit date placeholders, but we\n> > can't quite make them match the author-date specifiers, because \"gd\" is\n> > taken.  We could add %gt, %gr, etc. But in the long run, I'd like to\n> > move to considering most of %ar, %at, etc to be historical, and have\n> > something like \"%ad(short)\" be the official way of picking different\n> > date formats[1]. And then the reflog placeholders could learn\n> > \"%gt(short)\". So making more reflog placeholders right now just feels\n> > like cluttering a namespace I'd like to get changed eventually.\n> \n> I tend to agree with the direction.\n> \n> As we are not adding anything new before the 1.7.8 final, I'd rather ask\n> you to hold onto this and other changes in your footnote, instead of\n> having me to carry them in 'pu', which is an integration branch even less\n> official than it would otherwise be during the freeze period.\n\nSure. I'll re-send the patch once the release is out. That will also\ngive Jack and any other interested parties time to comment and test.\n\n-Peff\n"},{"id":"179232","messageId":"CAMYxyaWLEy3VEYcR26vc1pic1z59t4Rgnp7a03PhJ8EvSEmxoA@mail.gmail.com","threadId":"28866","inReplyTo":"20111108054745.GD29643@sigill.intra.peff.net","subject":"Re: pretty placeholders for reflog entries","fromName":"Jack Nagel","fromEmail":"jacknagel@gmail.com","sentAt":"2011-11-10T01:56:54Z","receivedAt":"2011-11-10T01:56:54Z","isPatch":false,"sender":{"key":"jacknagel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/568243?v=4"},"body":"On Mon, Nov 7, 2011 at 11:47 PM, Jeff King <peff@peff.net> wrote:\n> Sure. I'll re-send the patch once the release is out. That will also\n> give Jack and any other interested parties time to comment and test.\n\nThanks. I used this day, and combined with \"--date=\", it gets me pretty\nclose to where I wanted to be. But your comments about reorganizing the\ndate placeholders make sense, so this is perfectly fine for the time\nbeing.\n\nThanks again.\n\nJack\n"}]}