{"thread":{"id":"23650","subject":"[PATCH/RFC] pretty.c: add %O format specifier to format_commit_one()","startedAt":"2010-05-01T10:56:41Z","lastAt":"2010-05-02T04:55:52Z","messageCount":5,"participants":["Alexander Shishkin","Junio C Hamano","Jakub Narebski","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"140677","messageId":"1272711401-29005-1-git-send-email-ash@koowaldah.org","threadId":"23650","inReplyTo":null,"subject":"[PATCH/RFC] pretty.c: add %O format specifier to format_commit_one()","fromName":"Alexander Shishkin","fromEmail":"ash@koowaldah.org","sentAt":"2010-05-01T10:56:41Z","receivedAt":"2010-05-01T10:56:41Z","isPatch":true,"sender":{"key":"ash@koowaldah.org","avatar":null},"body":"This specifier represents the number of each commit in the output\nstream.\n\nSigned-off-by: Alexander Shishkin <ash@koowaldah.org>\n---\n Documentation/pretty-formats.txt |    3 ++-\n pretty.c                         |    5 +++++\n 2 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\nindex 1686a54..7b0cab1 100644\n--- a/Documentation/pretty-formats.txt\n+++ b/Documentation/pretty-formats.txt\n@@ -137,7 +137,8 @@ The placeholders are:\n - '%%': a raw '%'\n - '%x00': print a byte from a hex code\n - '%w([<w>[,<i1>[,<i2>]]])': switch line wrapping, like the -w option of\n-  linkgit:git-shortlog[1].\n+  linkgit:git-shortlog[1]\n+- '%O': number of the record in the output.\n \n NOTE: Some placeholders may depend on other options given to the\n revision traversal engine. For example, the `%g*` reflog options will\ndiff --git a/pretty.c b/pretty.c\nindex 7cb3a2a..3e3d399 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -11,6 +11,7 @@\n #include \"reflog-walk.h\"\n \n static char *user_format;\n+static int record_number;\n \n static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat)\n {\n@@ -639,6 +640,9 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \n \t/* these are independent of the commit */\n \tswitch (placeholder[0]) {\n+\tcase 'O':\n+\t\tstrbuf_addf(sb, \"%d\", record_number);\n+\t\treturn 1;\n \tcase 'C':\n \t\tif (placeholder[1] == '(') {\n \t\t\tconst char *end = strchr(placeholder + 2, ')');\n@@ -899,6 +903,7 @@ void format_commit_message(const struct commit *commit,\n \tcontext.wrap_start = sb->len;\n \tstrbuf_expand(sb, format, format_commit_item, &context);\n \trewrap_message_tail(sb, &context, 0, 0, 0);\n+\trecord_number++;\n }\n \n static void pp_header(enum cmit_fmt fmt,\n-- \n1.7.0.4\n"},{"id":"140690","messageId":"7vsk6b5yms.fsf@alter.siamese.dyndns.org","threadId":"23650","inReplyTo":"1272711401-29005-1-git-send-email-ash@koowaldah.org","subject":"Re: [PATCH/RFC] pretty.c: add %O format specifier to format_commit_one()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-01T17:18:35Z","receivedAt":"2010-05-01T17:18:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Shishkin <ash@koowaldah.org> writes:\n\n> This specifier represents the number of each commit in the output\n> stream.\n\nI don't like this.  What does such a number _mean_ in a non-linear\nhistory?\n\nAlso the next person who sees this will inevitably ask for %TOTAL to so\nthat the output can say [N/M], but that would mean the list has to be\nlimited and we cannot stream the output anymore.\n"},{"id":"140698","messageId":"20100501175601.GB27062@shisha.kicks-ass.net","threadId":"23650","inReplyTo":"7vsk6b5yms.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC] pretty.c: add %O format specifier to format_commit_one()","fromName":"Alexander Shishkin","fromEmail":"ash@koowaldah.org","sentAt":"2010-05-01T17:56:01Z","receivedAt":"2010-05-01T17:56:01Z","isPatch":true,"sender":{"key":"ash@koowaldah.org","avatar":null},"body":"On Sat, May 01, 2010 at 10:18:35 -0700, Junio C Hamano wrote:\n> Alexander Shishkin <ash@koowaldah.org> writes:\n> \n> > This specifier represents the number of each commit in the output\n> > stream.\n> \n> I don't like this.  What does such a number _mean_ in a non-linear\n> history?\n\nMy idea is to have something like\n\n$ git log --pretty=oneline | nl | less -R\n\nThis is generally useful when my local topic branch contains more than 5\n(or so) commits and I can't immediately see which one's which if I want\nto do a\n\n$ git show HEAD~$n\n\nto see what's inside, which is useful when reordering and/or squashing\ncommits by an interactive rebase. So this %O gives me this $n quicker\nthan counting.\n\n> Also the next person who sees this will inevitably ask for %TOTAL to so\n> that the output can say [N/M], but that would mean the list has to be\n> limited and we cannot stream the output anymore.\n\nWell, for me this kind of numbering only makes sense on a short part of\nthe topmost history.\n\nRegards,\n--\nAlex\n"},{"id":"140705","messageId":"m3fx2bcsze.fsf@localhost.localdomain","threadId":"23650","inReplyTo":"20100501175601.GB27062@shisha.kicks-ass.net","subject":"Re: [PATCH/RFC] pretty.c: add %O format specifier to format_commit_one()","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-05-01T19:39:48Z","receivedAt":"2010-05-01T19:39:48Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Alexander Shishkin <ash@koowaldah.org> writes:\n\n> On Sat, May 01, 2010 at 10:18:35 -0700, Junio C Hamano wrote:\n> > Alexander Shishkin <ash@koowaldah.org> writes:\n> > \n> > > This specifier represents the number of each commit in the output\n> > > stream.\n> > \n> > I don't like this.  What does such a number _mean_ in a non-linear\n> > history?\n> \n> My idea is to have something like\n> \n> $ git log --pretty=oneline | nl | less -R\n> \n> This is generally useful when my local topic branch contains more than 5\n> (or so) commits and I can't immediately see which one's which if I want\n> to do a\n> \n> $ git show HEAD~$n\n> \n> to see what's inside, which is useful when reordering and/or squashing\n> commits by an interactive rebase. So this %O gives me this $n quicker\n> than counting.\n\nWouldn't somthing like\n\n  git log --pretty=oneline | git name-rev --stdin | less -R\n\nbe good enough?\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"140727","messageId":"20100502045552.GC14776@coredump.intra.peff.net","threadId":"23650","inReplyTo":"7vsk6b5yms.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC] pretty.c: add %O format specifier to format_commit_one()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-05-02T04:55:52Z","receivedAt":"2010-05-02T04:55:52Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, May 01, 2010 at 10:18:35AM -0700, Junio C Hamano wrote:\n\n> Alexander Shishkin <ash@koowaldah.org> writes:\n> \n> > This specifier represents the number of each commit in the output\n> > stream.\n> \n> I don't like this.  What does such a number _mean_ in a non-linear\n> history?\n> \n> Also the next person who sees this will inevitably ask for %TOTAL to so\n> that the output can say [N/M], but that would mean the list has to be\n> limited and we cannot stream the output anymore.\n\nHmph. I started on a patch a while ago (but never finished) that would\nallow an [N/M] output. My intent was to allow pretty-format specifiers\nfor generating cover letters[1].\n\nOf course you can't stream when asking for %TOTAL, but that is already\nthe case with format-patch, which does such a calculation when numbering\npatch subjects. We could use userformat_find_requirements to do the\nlookup when needed, and then only formats which use the placeholder\nwould have to pay the penalty.\n\n-Peff\n\n[1] These days I do:\n\n  git format-patch --stdout \"$@\" |\n    sed -ne 's/^Subject: //p' |\n    sed -e 's/\\[PATCH /[/' \\\n        -e 's/]/]:/' \\\n        -e 's/^/  /'\n\nand pull the result into a cover letter that I write manually.\n"}]}