{"thread":{"id":"37591","subject":"[PATCH v4] pretty: add %D format specifier","startedAt":"2014-09-18T20:53:53Z","lastAt":"2014-09-18T20:53:53Z","messageCount":1,"participants":["Harry Jeffery"],"isPatch":true,"patchVersion":4,"patchTotal":null},"messages":[{"id":"249649","messageId":"1411073633-31271-1-git-send-email-harry@exec64.co.uk","threadId":"37591","inReplyTo":null,"subject":"[PATCH v4] pretty: add %D format specifier","fromName":"Harry Jeffery","fromEmail":"harry@exec64.co.uk","sentAt":"2014-09-18T20:53:53Z","receivedAt":"2014-09-18T20:53:53Z","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                       | 17 +++++++++--------\n log-tree.h                       |  8 +++++++-\n pretty.c                         |  4 ++++\n t/t4205-log-pretty-formats.sh    | 11 +++++++++++\n 5 files changed, 35 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/pretty-formats.txt b/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..8d05bb3 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -179,14 +179,16 @@ static void show_children(struct rev_info *opt, struct 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,7 +198,6 @@ void format_decorations(struct strbuf *sb,\n \tdecoration = lookup_decoration(&name_decoration, &commit->object);\n \tif (!decoration)\n \t\treturn;\n-\tprefix = \" (\";\n \twhile (decoration) {\n \t\tstrbuf_addstr(sb, color_commit);\n \t\tstrbuf_addstr(sb, prefix);\n@@ -205,11 +206,11 @@ void format_decorations(struct strbuf *sb,\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\tprefix = 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, int use_color);\n+void format_decorations_extended(struct strbuf *sb, const struct commit *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 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 *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..eb3d7a2 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 >expected <<EOF &&\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"}]}