pretty: add %D format specifier

Add a new format specifier, '%D' that is identical in behaviour to '%d', except that it does not include the ' (' prefix or ')' suffix provided by '%d'. Signed-off-by: Harry Jeffery <harry@exec64.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Harry Jeffery committed Sep 18, 2014 at 21:53 UTC 9271095cc5571e306d709ebf8eb7f0a388254d9d
5 files changed +35 -11
Documentation/pretty-formats.txt
+4 -2
@@ -128,6 +128,7 @@ The placeholders are:
128 - '%ct': committer date, UNIX timestamp
129 - '%ci': committer date, ISO 8601 format
130 - '%d': ref names, like the --decorate option of linkgit:git-log[1]
131 +- '%D': ref names without the " (", ")" wrapping.
132 - '%e': encoding
133 - '%s': subject
134 - '%f': sanitized subject line, suitable for a filename
@@ -182,8 +183,9 @@ The placeholders are:
183 NOTE: Some placeholders may depend on other options given to the
184 revision traversal engine. For example, the `%g*` reflog options will
185 insert an empty string unless we are traversing reflog entries (e.g., by
185 -`git log -g`). The `%d` placeholder will use the "short" decoration
186 -format if `--decorate` was not already provided on the command line.
186 +`git log -g`). The `%d` and `%D` placeholders will use the "short"
187 +decoration format if `--decorate` was not already provided on the command
188 +line.
189
190 If you add a `+` (plus sign) after '%' of a placeholder, a line-feed
191 is inserted immediately before the expansion if and only if the
log-tree.c
+9 -8
@@ -179,14 +179,16 @@ static void show_children(struct rev_info *opt, struct commit *commit, int abbre
179 }
180
181 /*
182 - * The caller makes sure there is no funny color before
183 - * calling. format_decorations makes sure the same after return.
182 + * The caller makes sure there is no funny color before calling.
183 + * format_decorations_extended makes sure the same after return.
184 */
185 -void format_decorations(struct strbuf *sb,
185 +void format_decorations_extended(struct strbuf *sb,
186 const struct commit *commit,
187 - int use_color)
187 + int use_color,
188 + const char *prefix,
189 + const char *separator,
190 + const char *suffix)
191 {
189 - const char *prefix;
192 struct name_decoration *decoration;
193 const char *color_commit =
194 diff_get_color(use_color, DIFF_COMMIT);
@@ -196,7 +198,6 @@ void format_decorations(struct strbuf *sb,
198 decoration = lookup_decoration(&name_decoration, &commit->object);
199 if (!decoration)
200 return;
199 - prefix = " (";
201 while (decoration) {
202 strbuf_addstr(sb, color_commit);
203 strbuf_addstr(sb, prefix);
@@ -205,11 +206,11 @@ void format_decorations(struct strbuf *sb,
206 strbuf_addstr(sb, "tag: ");
207 strbuf_addstr(sb, decoration->name);
208 strbuf_addstr(sb, color_reset);
208 - prefix = ", ";
209 + prefix = separator;
210 decoration = decoration->next;
211 }
212 strbuf_addstr(sb, color_commit);
212 - strbuf_addch(sb, ')');
213 + strbuf_addstr(sb, suffix);
214 strbuf_addstr(sb, color_reset);
215 }
216
log-tree.h
+7 -1
@@ -13,7 +13,13 @@ int log_tree_diff_flush(struct rev_info *);
13 int log_tree_commit(struct rev_info *, struct commit *);
14 int log_tree_opt_parse(struct rev_info *, const char **, int);
15 void show_log(struct rev_info *opt);
16 -void format_decorations(struct strbuf *sb, const struct commit *commit, int use_color);
16 +void format_decorations_extended(struct strbuf *sb, const struct commit *commit,
17 + int use_color,
18 + const char *prefix,
19 + const char *separator,
20 + const char *suffix);
21 +#define format_decorations(strbuf, commit, color) \
22 + format_decorations_extended((strbuf), (commit), (color), " (", ", ", ")")
23 void show_decorations(struct rev_info *opt, struct commit *commit);
24 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
25 const char **subject_p,
pretty.c
+4
@@ -1190,6 +1190,10 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1190 load_ref_decorations(DECORATE_SHORT_REFS);
1191 format_decorations(sb, commit, c->auto_color);
1192 return 1;
1193 + case 'D':
1194 + load_ref_decorations(DECORATE_SHORT_REFS);
1195 + format_decorations_extended(sb, commit, c->auto_color, "", ", ", "");
1196 + return 1;
1197 case 'g': /* reflog info */
1198 switch(placeholder[1]) {
1199 case 'd': /* reflog selector */
t/t4205-log-pretty-formats.sh
+11
@@ -450,4 +450,15 @@ EOF
450 test_cmp expected actual1
451 '
452
453 +test_expect_success 'clean log decoration' '
454 + git log --no-walk --tags --pretty="%H %D" --decorate=full >actual &&
455 + cat >expected <<EOF &&
456 +$head1 tag: refs/tags/tag2
457 +$head2 tag: refs/tags/message-one
458 +$old_head1 tag: refs/tags/message-two
459 +EOF
460 + sort actual >actual1 &&
461 + test_cmp expected actual1
462 +'
463 +
464 test_done