{"thread":{"id":"15260","subject":"[PATCH 0/2] Use %as and %cs as pretty format flags","startedAt":"2008-08-28T11:09:37Z","lastAt":"2008-08-29T08:12:18Z","messageCount":9,"participants":["Nathan Panike","Jeff King","Junio C Hamano","Nathan W. Panike","Avery Pennarun","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"89008","messageId":"d77df1110808280409o9445f9fybcab2c8d1066a8d8@mail.gmail.com","threadId":"15260","inReplyTo":null,"subject":"[PATCH 0/2] Use %as and %cs as pretty format flags","fromName":"Nathan Panike","fromEmail":"nathan.panike@gmail.com","sentAt":"2008-08-28T11:09:37Z","receivedAt":"2008-08-28T11:09:37Z","isPatch":true,"sender":{"key":"nathan.panike@gmail.com","avatar":"https://avatars.githubusercontent.com/u/389447?v=4"},"body":"The patch series below allows git to use %as and %cs as flags for\npretty-printing the format of a date.\n\nNathan W. Panike (2):\n  Document %as and %cs as a pretty format flag\n  Give %as and %cs meaning for pretty format\n\n Documentation/pretty-formats.txt |    2 ++\n pretty.c                         |    3 +++\n 2 files changed, 5 insertions(+), 0 deletions(-)\n"},{"id":"89036","messageId":"20080828231547.GD29609@coredump.intra.peff.net","threadId":"15260","inReplyTo":"d77df1110808280409o9445f9fybcab2c8d1066a8d8@mail.gmail.com","subject":"Re: [PATCH 0/2] Use %as and %cs as pretty format flags","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-08-28T23:15:48Z","receivedAt":"2008-08-28T23:15:48Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Aug 28, 2008 at 06:09:37AM -0500, Nathan Panike wrote:\n\n> The patch series below allows git to use %as and %cs as flags for\n> pretty-printing the format of a date.\n\nYour description leaves a little to be desired (here and in the patches\nthemselves). I had to read the patch to figure out that these are\nformatting specifiers for the date format \"short\".\n\nThat being said, I think this is probably reasonable just for the sake\nof completeness (and I doubt we are wasting a useful formatting combo,\nsince %a* is likely to remain dedicated to author information). I wonder\nif there should be \"%al\" for \"local\".\n\nHowever, it makes me wonder even more if '%ad' should simply respect the\n--date= parameter (this wouldn't allow you to mix and match dates in a\nsingle format, but I don't think that is what is desired). Or whether we\nshould have some syntax for \"%ad(short)\" or something, where the\nargument would be handed off to the date format parser. But that is\nprobably overengineering.\n\n-Peff\n\nPS Junio, I think this will make your \"git one\" alias much shorter. :)\n"},{"id":"89045","messageId":"7viqtkd84s.fsf@gitster.siamese.dyndns.org","threadId":"15260","inReplyTo":"20080828231547.GD29609@coredump.intra.peff.net","subject":"Re: [PATCH 0/2] Use %as and %cs as pretty format flags","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-28T23:36:51Z","receivedAt":"2008-08-28T23:36:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Thu, Aug 28, 2008 at 06:09:37AM -0500, Nathan Panike wrote:\n>\n>> The patch series below allows git to use %as and %cs as flags for\n>> pretty-printing the format of a date.\n>\n> Your description leaves a little to be desired (here and in the patches\n> themselves). I had to read the patch to figure out that these are\n> formatting specifiers for the date format \"short\".\n>\n> That being said, I think this is probably reasonable just for the sake\n> of completeness (and I doubt we are wasting a useful formatting combo,\n> since %a* is likely to remain dedicated to author information). I wonder\n> if there should be \"%al\" for \"local\".\n>\n> However, it makes me wonder even more if '%ad' should simply respect the\n> --date= parameter (this wouldn't allow you to mix and match dates in a\n> single format, but I don't think that is what is desired). Or whether we\n> should have some syntax for \"%ad(short)\" or something, where the\n> argument would be handed off to the date format parser. But that is\n> probably overengineering.\n\nI was actually thinking about rejecting this, asking for something that\nallows to express all the other %[ai][dDri] format can express, and\nperhaps more.  So I think \"%ad(short)\" is a good direction to go, except\nthat 'd' is already taken.  Perhaps %a(date), %a(shortdate,local),...?\n\nOh, and before anybody asks, even if we do %a(specifier), you can keep\nwriting \"%ad\" if you are used to it.  I am not talking about deprecating\nthe existing ones, but making future extensions easier without forcing\npeople to remember cryptic one-letter format specifiers.\n"},{"id":"89049","messageId":"20080828235420.GB30195@coredump.intra.peff.net","threadId":"15260","inReplyTo":"7viqtkd84s.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 0/2] Use %as and %cs as pretty format flags","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-08-28T23:54:21Z","receivedAt":"2008-08-28T23:54:21Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Aug 28, 2008 at 04:36:51PM -0700, Junio C Hamano wrote:\n\n> I was actually thinking about rejecting this, asking for something that\n> allows to express all the other %[ai][dDri] format can express, and\n> perhaps more.  So I think \"%ad(short)\" is a good direction to go, except\n> that 'd' is already taken.  Perhaps %a(date), %a(shortdate,local),...?\n\nI was thinking we could accept %ad _or_ %ad(short), but of course\nintroducing the latter can break existing \"%ad(my other random text)\"\nwhich is a bad idea.\n\nI really think some consideration should be given to introducing\narbitrary \"arguments\" to formatting specifiers, of which this is one\nexample. Another that has been mentioned is pulling an arbitrary element\nfrom a list.\n\nHow do you feel about a brand new syntax (and supporting the old, of\ncourse) that is syntactically a little easier to extend. Like:\n\n  %(macro, key=val, key=val)\n\ne.g.\n\n  %(authordate, format=short, tz=local)\n\nwhere the syntax can be easily parsed without understanding what\n\"authordate\" means.  Jakub already suggested something akin to RPM's\nmacro expansion, though I haven't looked too closely at it.\n\n> Oh, and before anybody asks, even if we do %a(specifier), you can keep\n> writing \"%ad\" if you are used to it.  I am not talking about deprecating\n> the existing ones, but making future extensions easier without forcing\n> people to remember cryptic one-letter format specifiers.\n\nYes, I don't see a need to get rid of the existing ones. Introducing a\nnew syntax does have the possibility of breaking existing scripts, since\nwe just leave unrecognized expansions in place (in fact, just adding %as\nhas the potential to break scripts!).\n\nWorst case, we can introduce a --pretty=otherformat:, but I don't know\nif people are really expecting \"%a(blah)\" to be left untouched\ncurrently. I don't think we ever claimed that % was magical.\n\n-Peff\n"},{"id":"89062","messageId":"d77df1110808281710r6d58739fl2acb93e1940c7433@mail.gmail.com","threadId":"15260","inReplyTo":"20080828235420.GB30195@coredump.intra.peff.net","subject":"Re: [PATCH 0/2] Use %as and %cs as pretty format flags","fromName":"Nathan W. Panike","fromEmail":"nathan.panike@gmail.com","sentAt":"2008-08-29T00:10:45Z","receivedAt":"2008-08-29T00:10:45Z","isPatch":true,"sender":{"key":"nathan.panike@gmail.com","avatar":"https://avatars.githubusercontent.com/u/389447?v=4"},"body":"On Thu, Aug 28, 2008 at 6:54 PM, Jeff King <peff@peff.net> wrote:\n> On Thu, Aug 28, 2008 at 04:36:51PM -0700, Junio C Hamano wrote:\n>\n>> I was actually thinking about rejecting this, asking for something that\n>> allows to express all the other %[ai][dDri] format can express, and\n>> perhaps more.  So I think \"%ad(short)\" is a good direction to go, except\n>> that 'd' is already taken.  Perhaps %a(date), %a(shortdate,local),...?\n>\n> I was thinking we could accept %ad _or_ %ad(short), but of course\n> introducing the latter can break existing \"%ad(my other random text)\"\n> which is a bad idea.\n>\n> I really think some consideration should be given to introducing\n> arbitrary \"arguments\" to formatting specifiers, of which this is one\n> example. Another that has been mentioned is pulling an arbitrary element\n> from a list.\n>\n> How do you feel about a brand new syntax (and supporting the old, of\n> course) that is syntactically a little easier to extend. Like:\n>\n>  %(macro, key=val, key=val)\n>\n> e.g.\n>\n>  %(authordate, format=short, tz=local)\n\nThe genesis of this patch was the documentation says that %ad\nrepresents 'author date' without any more specific information.  I\nthought that I could do\n\ngit show --date=short --pretty=format:\"%ad %h\"\n\nand get the date in short form---but alas, this did not work.  So I\nwrote up the patch to get a short date format.  Your ideas are much\nmore powerful.  I like them.\n\nThanks for git.\n\nNathan Panike\n"},{"id":"89070","messageId":"20080829005458.GA4248@coredump.intra.peff.net","threadId":"15260","inReplyTo":"d77df1110808281710r6d58739fl2acb93e1940c7433@mail.gmail.com","subject":"Re: [PATCH 0/2] Use %as and %cs as pretty format flags","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-08-29T00:54:59Z","receivedAt":"2008-08-29T00:54:59Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Aug 28, 2008 at 07:10:45PM -0500, Nathan W. Panike wrote:\n\n> The genesis of this patch was the documentation says that %ad\n> represents 'author date' without any more specific information.  I\n> thought that I could do\n> \n> git show --date=short --pretty=format:\"%ad %h\"\n> \n> and get the date in short form---but alas, this did not work.  So I\n\nRegardless of expansions to --pretty=format:, that is something we\nshould probably be doing _anyway_. The current behavior is just\nconfusing, and %ad is simply documented as \"date\", not in any particular\nformat (and I think anyone relying on it _ignoring_ --date= is insane,\nsince that --date is otherwise not doing anything).\n\nSo how about this?\n\n-- >8 --\npretty=format: respect date format options\n\nWhen running a command like:\n\n  git log --pretty=format:%ad --date=short\n\nthe date option was ignored. This patch causes it to use\nwhatever format was specified by --date (or by\n--relative-date, etc), just as the non-user formats would\ndo.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Documentation/pretty-formats.txt |    2 +-\n archive.c                        |    2 +-\n builtin-commit.c                 |    2 +-\n commit.h                         |    3 ++-\n pretty.c                         |   17 +++++++++++------\n t/t6006-rev-list-format.sh       |    6 ++++++\n 6 files changed, 22 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\nindex c11d495..388d492 100644\n--- a/Documentation/pretty-formats.txt\n+++ b/Documentation/pretty-formats.txt\n@@ -103,7 +103,7 @@ The placeholders are:\n - '%an': author name\n - '%aN': author name (respecting .mailmap)\n - '%ae': author email\n-- '%ad': author date\n+- '%ad': author date (format respects --date= option)\n - '%aD': author date, RFC2822 style\n - '%ar': author date, relative\n - '%at': author date, UNIX timestamp\ndiff --git a/archive.c b/archive.c\nindex 5b40e26..e2280df 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -48,7 +48,7 @@ static void format_subst(const struct commit *commit,\n \t\tstrbuf_add(&fmt, b + 8, c - b - 8);\n \n \t\tstrbuf_add(buf, src, b - src);\n-\t\tformat_commit_message(commit, fmt.buf, buf);\n+\t\tformat_commit_message(commit, fmt.buf, buf, DATE_NORMAL);\n \t\tlen -= c + 1 - src;\n \t\tsrc  = c + 1;\n \t}\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 649c8be..c870037 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -882,7 +882,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)\n \n \tif (!log_tree_commit(&rev, commit)) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n-\t\tformat_commit_message(commit, \"%h: %s\", &buf);\n+\t\tformat_commit_message(commit, \"%h: %s\", &buf, DATE_NORMAL);\n \t\tprintf(\"%s\\n\", buf.buf);\n \t\tstrbuf_release(&buf);\n \t}\ndiff --git a/commit.h b/commit.h\nindex d163c74..de15f4d 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -67,7 +67,8 @@ extern int non_ascii(int);\n struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */\n extern void get_commit_format(const char *arg, struct rev_info *);\n extern void format_commit_message(const struct commit *commit,\n-                                  const void *format, struct strbuf *sb);\n+\t\t\t\t  const void *format, struct strbuf *sb,\n+\t\t\t\t  enum date_mode dmode);\n extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,\n                                 struct strbuf *,\n                                 int abbrev, const char *subject,\ndiff --git a/pretty.c b/pretty.c\nindex 33ef34a..a29c290 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -310,7 +310,7 @@ static int mailmap_name(struct strbuf *sb, const char *email)\n }\n \n static size_t format_person_part(struct strbuf *sb, char part,\n-                               const char *msg, int len)\n+\t\t\t\t const char *msg, int len, enum date_mode dmode)\n {\n \t/* currently all placeholders have same length */\n \tconst int placeholder_len = 2;\n@@ -377,7 +377,7 @@ static size_t format_person_part(struct strbuf *sb, char part,\n \n \tswitch (part) {\n \tcase 'd':\t/* date */\n-\t\tstrbuf_addstr(sb, show_date(date, tz, DATE_NORMAL));\n+\t\tstrbuf_addstr(sb, show_date(date, tz, dmode));\n \t\treturn placeholder_len;\n \tcase 'D':\t/* date, RFC2822 style */\n \t\tstrbuf_addstr(sb, show_date(date, tz, DATE_RFC2822));\n@@ -409,6 +409,7 @@ struct chunk {\n \n struct format_commit_context {\n \tconst struct commit *commit;\n+\tenum date_mode dmode;\n \n \t/* These offsets are relative to the start of the commit message. */\n \tint commit_header_parsed;\n@@ -584,10 +585,12 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,\n \t\treturn 1;\n \tcase 'a':\t/* author ... */\n \t\treturn format_person_part(sb, placeholder[1],\n-\t\t                   msg + c->author.off, c->author.len);\n+\t\t\t\t   msg + c->author.off, c->author.len,\n+\t\t\t\t   c->dmode);\n \tcase 'c':\t/* committer ... */\n \t\treturn format_person_part(sb, placeholder[1],\n-\t\t                   msg + c->committer.off, c->committer.len);\n+\t\t\t\t   msg + c->committer.off, c->committer.len,\n+\t\t\t\t   c->dmode);\n \tcase 'e':\t/* encoding */\n \t\tstrbuf_add(sb, msg + c->encoding.off, c->encoding.len);\n \t\treturn 1;\n@@ -599,12 +602,14 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,\n }\n \n void format_commit_message(const struct commit *commit,\n-                           const void *format, struct strbuf *sb)\n+\t\t\t   const void *format, struct strbuf *sb,\n+\t\t\t   enum date_mode dmode)\n {\n \tstruct format_commit_context context;\n \n \tmemset(&context, 0, sizeof(context));\n \tcontext.commit = commit;\n+\tcontext.dmode = dmode;\n \tstrbuf_expand(sb, format, format_commit_item, &context);\n }\n \n@@ -770,7 +775,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n \tconst char *encoding;\n \n \tif (fmt == CMIT_FMT_USERFORMAT) {\n-\t\tformat_commit_message(commit, user_format, sb);\n+\t\tformat_commit_message(commit, user_format, sb, dmode);\n \t\treturn;\n \t}\n \ndiff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh\nindex 9176484..485ad4d 100755\n--- a/t/t6006-rev-list-format.sh\n+++ b/t/t6006-rev-list-format.sh\n@@ -139,6 +139,12 @@ commit 131a310eb913d107dd3c09a65d1651175898735d\n commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873\n EOF\n \n+test_expect_success '%ad respects --date=' '\n+\techo 2005-04-07 >expect.ad-short &&\n+\tgit log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&\n+\ttest_cmp expect.ad-short output.ad-short\n+'\n+\n test_expect_success 'empty email' '\n \ttest_tick &&\n \tC=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&\n-- \n1.6.0.1.173.g2bf39.dirty\n"},{"id":"89072","messageId":"7viqtkbpcf.fsf@gitster.siamese.dyndns.org","threadId":"15260","inReplyTo":"20080829005458.GA4248@coredump.intra.peff.net","subject":"Re: [PATCH 0/2] Use %as and %cs as pretty format flags","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-29T01:08:00Z","receivedAt":"2008-08-29T01:08:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Thu, Aug 28, 2008 at 07:10:45PM -0500, Nathan W. Panike wrote:\n>\n>> The genesis of this patch was the documentation says that %ad\n>> represents 'author date' without any more specific information.  I\n>> thought that I could do\n>> \n>> git show --date=short --pretty=format:\"%ad %h\"\n>> \n>> and get the date in short form---but alas, this did not work.  So I\n>\n> Regardless of expansions to --pretty=format:, that is something we\n> should probably be doing _anyway_. The current behavior is just\n> confusing, and %ad is simply documented as \"date\", not in any particular\n> format (and I think anyone relying on it _ignoring_ --date= is insane,\n> since that --date is otherwise not doing anything).\n>\n> So how about this?\n>\n> -- >8 --\n> pretty=format: respect date format options\n>\n> When running a command like:\n>\n>   git log --pretty=format:%ad --date=short\n>\n> the date option was ignored. This patch causes it to use\n> whatever format was specified by --date (or by\n> --relative-date, etc), just as the non-user formats would\n> do.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n\nLike the idea; haven't looked at the patch yet, though.\n"},{"id":"89078","messageId":"32541b130808282043v5516e95ai49f928aeefb75fdd@mail.gmail.com","threadId":"15260","inReplyTo":"7viqtkd84s.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 0/2] Use %as and %cs as pretty format flags","fromName":"Avery Pennarun","fromEmail":"apenwarr@gmail.com","sentAt":"2008-08-29T03:43:05Z","receivedAt":"2008-08-29T03:43:05Z","isPatch":true,"sender":{"key":"apenwarr@gmail.com","avatar":"https://avatars.githubusercontent.com/u/20592?v=4"},"body":"On Thu, Aug 28, 2008 at 7:36 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> I was actually thinking about rejecting this, asking for something that\n> allows to express all the other %[ai][dDri] format can express, and\n> perhaps more.  So I think \"%ad(short)\" is a good direction to go, except\n> that 'd' is already taken.  Perhaps %a(date), %a(shortdate,local),...?\n\nThese format strings are getting increasingly complicated without\nreally gaining much in generality.  Why not\n\"%ad(strftime-compatible-format-string)\" ?  You could differentiate\nlocaltime vs. gmtime with %ad vs. %aD, or something like that.\n\nHave fun,\n\nAvery\n"},{"id":"89098","messageId":"m3hc94qlyc.fsf@localhost.localdomain","threadId":"15260","inReplyTo":"20080828235420.GB30195@coredump.intra.peff.net","subject":"Re: [PATCH 0/2] Use %as and %cs as pretty format flags","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-08-29T08:12:18Z","receivedAt":"2008-08-29T08:12:18Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Thu, Aug 28, 2008 at 04:36:51PM -0700, Junio C Hamano wrote:\n> \n> > I was actually thinking about rejecting this, asking for something that\n> > allows to express all the other %[ai][dDri] format can express, and\n> > perhaps more.  So I think \"%ad(short)\" is a good direction to go, except\n> > that 'd' is already taken.  Perhaps %a(date), %a(shortdate,local),...?\n> \n> I was thinking we could accept %ad _or_ %ad(short), but of course\n> introducing the latter can break existing \"%ad(my other random text)\"\n> which is a bad idea.\n> \n> I really think some consideration should be given to introducing\n> arbitrary \"arguments\" to formatting specifiers, of which this is one\n> example. Another that has been mentioned is pulling an arbitrary element\n> from a list.\n> \n> How do you feel about a brand new syntax (and supporting the old, of\n> course) that is syntactically a little easier to extend. Like:\n> \n>   %(macro, key=val, key=val)\n> \n> e.g.\n> \n>   %(authordate, format=short, tz=local)\n> \n> where the syntax can be easily parsed without understanding what\n> \"authordate\" means.  Jakub already suggested something akin to RPM's\n> macro expansion, though I haven't looked too closely at it.\n\nI'd rather we do not introduce yet another pretty-printing /\nformatting syntax, and use the same syntax as git-for-each-ref uses\nfor extra formatting, \n\n  As a special case for the date-type fields, you may specify a format for\n  the date by adding one of `:default`, `:relative`, `:short`, `:local`,\n  `:iso8601` or `:rfc2822` to the end of the fieldname; e.g.\n  `%(taggerdate:relative)`.\n\nwhich incindentally (or not) is the same as rpm uses\n\n  Alternate output formats may be requested by following the tag with  :type-\n  tag.  Currently, the following types are supported:\n\n  :armor  Wrap a public key in ASCII armor.\n\n  :base64\n         Encode binary data using base64.\n\n  :date  Use strftime(3) \"%c\" format.\n\n  :day   Use strftime(3) \"%a %b %d %Y\" format.\n\n  :depflags\n         Format dependency flags.\n\n  :fflags\n         Format file flags.\n\n  :hex   Format in hexadecimal.\n\n  :octal Format in octal.\n\n  :perms Format file permissions.\n\n  :shescape\n         Escape single quotes for use in a script.\n\n  :triggertype\n         Display trigger suffix.\n\nP.S. I Agree with %ad and the like respecting --date=<type>\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}