Skip to content

Commit b8e533f

Browse files
committed
Merge branch 'hj/pretty-naked-decoration'
The pretty-format specifier "%d", which expanded to " (tagname)" for a tagged commit, gained a cousin "%D" that just gives the "tagname" without frills. * hj/pretty-naked-decoration: pretty: add %D format specifier
2 parents a9583af + 9271095 commit b8e533f

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

Documentation/pretty-formats.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ The placeholders are:
130130
- '%ci': committer date, ISO 8601-like format
131131
- '%cI': committer date, strict ISO 8601 format
132132
- '%d': ref names, like the --decorate option of linkgit:git-log[1]
133+
- '%D': ref names without the " (", ")" wrapping.
133134
- '%e': encoding
134135
- '%s': subject
135136
- '%f': sanitized subject line, suitable for a filename
@@ -184,8 +185,9 @@ The placeholders are:
184185
NOTE: Some placeholders may depend on other options given to the
185186
revision traversal engine. For example, the `%g*` reflog options will
186187
insert an empty string unless we are traversing reflog entries (e.g., by
187-
`git log -g`). The `%d` placeholder will use the "short" decoration
188-
format if `--decorate` was not already provided on the command line.
188+
`git log -g`). The `%d` and `%D` placeholders will use the "short"
189+
decoration format if `--decorate` was not already provided on the command
190+
line.
189191

190192
If you add a `+` (plus sign) after '%' of a placeholder, a line-feed
191193
is inserted immediately before the expansion if and only if the

log-tree.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,16 @@ static void show_children(struct rev_info *opt, struct commit *commit, int abbre
174174
}
175175

176176
/*
177-
* The caller makes sure there is no funny color before
178-
* calling. format_decorations makes sure the same after return.
177+
* The caller makes sure there is no funny color before calling.
178+
* format_decorations_extended makes sure the same after return.
179179
*/
180-
void format_decorations(struct strbuf *sb,
180+
void format_decorations_extended(struct strbuf *sb,
181181
const struct commit *commit,
182-
int use_color)
182+
int use_color,
183+
const char *prefix,
184+
const char *separator,
185+
const char *suffix)
183186
{
184-
const char *prefix;
185187
const struct name_decoration *decoration;
186188
const char *color_commit =
187189
diff_get_color(use_color, DIFF_COMMIT);
@@ -191,7 +193,6 @@ void format_decorations(struct strbuf *sb,
191193
decoration = get_name_decoration(&commit->object);
192194
if (!decoration)
193195
return;
194-
prefix = " (";
195196
while (decoration) {
196197
strbuf_addstr(sb, color_commit);
197198
strbuf_addstr(sb, prefix);
@@ -200,11 +201,11 @@ void format_decorations(struct strbuf *sb,
200201
strbuf_addstr(sb, "tag: ");
201202
strbuf_addstr(sb, decoration->name);
202203
strbuf_addstr(sb, color_reset);
203-
prefix = ", ";
204+
prefix = separator;
204205
decoration = decoration->next;
205206
}
206207
strbuf_addstr(sb, color_commit);
207-
strbuf_addch(sb, ')');
208+
strbuf_addstr(sb, suffix);
208209
strbuf_addstr(sb, color_reset);
209210
}
210211

log-tree.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ int log_tree_diff_flush(struct rev_info *);
1313
int log_tree_commit(struct rev_info *, struct commit *);
1414
int log_tree_opt_parse(struct rev_info *, const char **, int);
1515
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), " (", ", ", ")")
1723
void show_decorations(struct rev_info *opt, struct commit *commit);
1824
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
1925
const char **subject_p,

pretty.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,10 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
11791179
load_ref_decorations(DECORATE_SHORT_REFS);
11801180
format_decorations(sb, commit, c->auto_color);
11811181
return 1;
1182+
case 'D':
1183+
load_ref_decorations(DECORATE_SHORT_REFS);
1184+
format_decorations_extended(sb, commit, c->auto_color, "", ", ", "");
1185+
return 1;
11821186
case 'g': /* reflog info */
11831187
switch(placeholder[1]) {
11841188
case 'd': /* reflog selector */

t/t4205-log-pretty-formats.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,15 @@ EOF
465465
test_cmp expected actual1
466466
'
467467

468+
test_expect_success 'clean log decoration' '
469+
git log --no-walk --tags --pretty="%H %D" --decorate=full >actual &&
470+
cat >expected <<EOF &&
471+
$head1 tag: refs/tags/tag2
472+
$head2 tag: refs/tags/message-one
473+
$old_head1 tag: refs/tags/message-two
474+
EOF
475+
sort actual >actual1 &&
476+
test_cmp expected actual1
477+
'
478+
468479
test_done

0 commit comments

Comments
 (0)