{"thread":{"id":"37574","subject":"[PATCH v2] pretty: add %D format specifier","startedAt":"2014-09-15T21:50:37Z","lastAt":"2014-09-15T22:44:25Z","messageCount":2,"participants":["Harry Jeffery","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"249461","messageId":"54175F2D.3070209@exec64.co.uk","threadId":"37574","inReplyTo":null,"subject":"[PATCH v2] pretty: add %D format specifier","fromName":"Harry Jeffery","fromEmail":"harry@exec64.co.uk","sentAt":"2014-09-15T21:50:37Z","receivedAt":"2014-09-15T21:50:37Z","isPatch":true,"sender":{"key":"harry@exec64.co.uk","avatar":"https://avatars.githubusercontent.com/u/808760?v=4"},"body":"Add a new format specifier, '%D' that is identical in behaviour to '%d',\nexcept that it does not include the ' (' prefix or ')' suffix provided\nby '%d'.\n\nSigned-off-by: Harry Jeffery <harry@exec64.co.uk>\n---\n  Documentation/pretty-formats.txt |  6 ++++--\n  log-tree.c                       | 24 +++++++++++++-----------\n  log-tree.h                       |  8 +++++++-\n  pretty.c                         |  4 ++++\n  t/t4205-log-pretty-formats.sh    | 11 +++++++++++\n  5 files changed, 39 insertions(+), 14 deletions(-)\n\ndiff --git a/Documentation/pretty-formats.txt \nb/Documentation/pretty-formats.txt\nindex eac7909..2632e1a 100644\n--- a/Documentation/pretty-formats.txt\n+++ b/Documentation/pretty-formats.txt\n@@ -128,6 +128,7 @@ The placeholders are:\n  - '%ct': committer date, UNIX timestamp\n  - '%ci': committer date, ISO 8601 format\n  - '%d': ref names, like the --decorate option of linkgit:git-log[1]\n+- '%D': ref names without the \" (\", \")\" wrapping.\n  - '%e': encoding\n  - '%s': subject\n  - '%f': sanitized subject line, suitable for a filename\n@@ -182,8 +183,9 @@ The placeholders are:\n  NOTE: Some placeholders may depend on other options given to the\n  revision traversal engine. For example, the `%g*` reflog options will\n  insert an empty string unless we are traversing reflog entries (e.g., by\n-`git log -g`). The `%d` placeholder will use the \"short\" decoration\n-format if `--decorate` was not already provided on the command line.\n+`git log -g`). The `%d` and `%D` placeholders will use the \"short\"\n+decoration format if `--decorate` was not already provided on the command\n+line.\n\n  If you add a `+` (plus sign) after '%' of a placeholder, a line-feed\n  is inserted immediately before the expansion if and only if the\ndiff --git a/log-tree.c b/log-tree.c\nindex 95e9b1d..61d1dea 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -179,14 +179,16 @@ static void show_children(struct rev_info *opt, \nstruct commit *commit, int abbre\n  }\n\n  /*\n- * The caller makes sure there is no funny color before\n- * calling. format_decorations makes sure the same after return.\n+ * The caller makes sure there is no funny color before calling.\n+ * format_decorations_extended makes sure the same after return.\n   */\n-void format_decorations(struct strbuf *sb,\n+void format_decorations_extended(struct strbuf *sb,\n  \t\t\tconst struct commit *commit,\n-\t\t\tint use_color)\n+\t\t\tint use_color,\n+\t\t\tconst char *prefix,\n+\t\t\tconst char *separator,\n+\t\t\tconst char *suffix)\n  {\n-\tconst char *prefix;\n  \tstruct name_decoration *decoration;\n  \tconst char *color_commit =\n  \t\tdiff_get_color(use_color, DIFF_COMMIT);\n@@ -196,20 +198,20 @@ void format_decorations(struct strbuf *sb,\n  \tdecoration = lookup_decoration(&name_decoration, &commit->object);\n  \tif (!decoration)\n  \t\treturn;\n-\tprefix = \" (\";\n+\tstrbuf_addstr(sb, color_commit);\n+\tstrbuf_addstr(sb, prefix);\n  \twhile (decoration) {\n-\t\tstrbuf_addstr(sb, color_commit);\n-\t\tstrbuf_addstr(sb, prefix);\n  \t\tstrbuf_addstr(sb, decorate_get_color(use_color, decoration->type));\n  \t\tif (decoration->type == DECORATION_REF_TAG)\n  \t\t\tstrbuf_addstr(sb, \"tag: \");\n  \t\tstrbuf_addstr(sb, decoration->name);\n  \t\tstrbuf_addstr(sb, color_reset);\n-\t\tprefix = \", \";\n+\t\tstrbuf_addstr(sb, color_commit);\n+\t\tif (decoration->next)\n+\t\t\tstrbuf_addstr(sb, separator);\n  \t\tdecoration = decoration->next;\n  \t}\n-\tstrbuf_addstr(sb, color_commit);\n-\tstrbuf_addch(sb, ')');\n+\tstrbuf_addstr(sb, suffix);\n  \tstrbuf_addstr(sb, color_reset);\n  }\n\ndiff --git a/log-tree.h b/log-tree.h\nindex d6ecd4d..b26160c 100644\n--- a/log-tree.h\n+++ b/log-tree.h\n@@ -13,7 +13,13 @@ int log_tree_diff_flush(struct rev_info *);\n  int log_tree_commit(struct rev_info *, struct commit *);\n  int log_tree_opt_parse(struct rev_info *, const char **, int);\n  void show_log(struct rev_info *opt);\n-void format_decorations(struct strbuf *sb, const struct commit *commit, \nint use_color);\n+void format_decorations_extended(struct strbuf *sb, const struct commit \n*commit,\n+\t\t\t     int use_color,\n+\t\t\t     const char *prefix,\n+\t\t\t     const char *separator,\n+\t\t\t     const char *suffix);\n+#define format_decorations(strbuf, commit, color) \\\n+\t\t\t     format_decorations_extended((strbuf), (commit), (color), \" (\", \n\", \", \")\")\n  void show_decorations(struct rev_info *opt, struct commit *commit);\n  void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n  \t\t\t     const char **subject_p,\ndiff --git a/pretty.c b/pretty.c\nindex 44b9f64..46d65b9 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1197,6 +1197,10 @@ static size_t format_commit_one(struct strbuf \n*sb, /* in UTF-8 */\n  \t\tload_ref_decorations(DECORATE_SHORT_REFS);\n  \t\tformat_decorations(sb, commit, c->auto_color);\n  \t\treturn 1;\n+\tcase 'D':\n+\t\tload_ref_decorations(DECORATE_SHORT_REFS);\n+\t\tformat_decorations_extended(sb, commit, c->auto_color, \"\", \", \", \"\");\n+\t\treturn 1;\n  \tcase 'g':\t\t/* reflog info */\n  \t\tswitch(placeholder[1]) {\n  \t\tcase 'd':\t/* reflog selector */\ndiff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\nindex de0cc4a..38148c1 100755\n--- a/t/t4205-log-pretty-formats.sh\n+++ b/t/t4205-log-pretty-formats.sh\n@@ -457,4 +457,15 @@ EOF\n  \ttest_cmp expected actual1\n  '\n\n+test_expect_success 'clean log decoration' '\n+\tgit log --no-walk --tags --pretty=\"%H %D\" --decorate=full >actual &&\n+\tcat <<EOF >expected &&\n+$head1 tag: refs/tags/tag2\n+$head2 tag: refs/tags/message-one\n+$old_head1 tag: refs/tags/message-two\n+EOF\n+\tsort actual >actual1 &&\n+\ttest_cmp expected actual1\n+'\n+\n  test_done\n-- \n2.1.0\n"},{"id":"249493","messageId":"xmqq7g144i7q.fsf@gitster.dls.corp.google.com","threadId":"37574","inReplyTo":"54175F2D.3070209@exec64.co.uk","subject":"Re: [PATCH v2] pretty: add %D format specifier","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-09-15T22:44:25Z","receivedAt":"2014-09-15T22:44:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Harry Jeffery <harry@exec64.co.uk> writes:\n\n> Add a new format specifier, '%D' that is identical in behaviour to '%d',\n> except that it does not include the ' (' prefix or ')' suffix provided\n> by '%d'.\n>\n> Signed-off-by: Harry Jeffery <harry@exec64.co.uk>\n> ---\n\nThe patch is broken and does not apply with \"git am\" here.  Please\nfirst try sending a patch to yourself and make sure it comes through\nOK.\n\nThanks.\n\n> diff --git a/log-tree.h b/log-tree.h\n> index d6ecd4d..b26160c 100644\n> --- a/log-tree.h\n> +++ b/log-tree.h\n> @@ -13,7 +13,13 @@ int log_tree_diff_flush(struct rev_info *);\n>  int log_tree_commit(struct rev_info *, struct commit *);\n>  int log_tree_opt_parse(struct rev_info *, const char **, int);\n>  void show_log(struct rev_info *opt);\n> -void format_decorations(struct strbuf *sb, const struct commit\n> *commit, int use_color);\n> +void format_decorations_extended(struct strbuf *sb, const struct\n> commit *commit,\n\nBroken lines...\n\n> +\t\t\t     int use_color,\n> +\t\t\t     const char *prefix,\n> +\t\t\t     const char *separator,\n> +\t\t\t     const char *suffix);\n> +#define format_decorations(strbuf, commit, color) \\\n> +\t\t\t     format_decorations_extended((strbuf),\n> (commit), (color), \" (\", \", \", \")\")\n\nBroken line here, too.\n\n>  void show_decorations(struct rev_info *opt, struct commit *commit);\n>  void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n>  \t\t\t     const char **subject_p,\n> diff --git a/pretty.c b/pretty.c\n> index 44b9f64..46d65b9 100644\n> --- a/pretty.c\n> +++ b/pretty.c\n> @@ -1197,6 +1197,10 @@ static size_t format_commit_one(struct strbuf\n> *sb, /* in UTF-8 */\n>  \t\tload_ref_decorations(DECORATE_SHORT_REFS);\n>  \t\tformat_decorations(sb, commit, c->auto_color);\n>  \t\treturn 1;\n> +\tcase 'D':\n> +\t\tload_ref_decorations(DECORATE_SHORT_REFS);\n> +\t\tformat_decorations_extended(sb, commit, c->auto_color, \"\", \", \", \"\");\n> +\t\treturn 1;\n>  \tcase 'g':\t\t/* reflog info */\n>  \t\tswitch(placeholder[1]) {\n>  \t\tcase 'd':\t/* reflog selector */\n> diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh\n> index de0cc4a..38148c1 100755\n> --- a/t/t4205-log-pretty-formats.sh\n> +++ b/t/t4205-log-pretty-formats.sh\n> @@ -457,4 +457,15 @@ EOF\n>  \ttest_cmp expected actual1\n>  '\n>\n> +test_expect_success 'clean log decoration' '\n> +\tgit log --no-walk --tags --pretty=\"%H %D\" --decorate=full >actual &&\n> +\tcat <<EOF >expected &&\n> +$head1 tag: refs/tags/tag2\n> +$head2 tag: refs/tags/message-one\n> +$old_head1 tag: refs/tags/message-two\n> +EOF\n> +\tsort actual >actual1 &&\n> +\ttest_cmp expected actual1\n> +'\n> +\n>  test_done\n"}]}