Skip to content

Commit 84ff053

Browse files
ttaylorrgitster
authored andcommitted
pretty.c: delimit "%(trailers)" arguments with ","
In preparation for adding consistent "%(trailers)" atom options to `git-for-each-ref(1)`'s "--format" argument, change "%(trailers)" in pretty.c to separate sub-arguments with a ",", instead of a ":". Multiple sub-arguments are given either as "%(trailers:unfold,only)" or "%(trailers:only,unfold)". This change disambiguates between "top-level" arguments, and arguments given to the trailers atom itself. It is consistent with the behavior of "%(upstream)" and "%(push)" atoms. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ea220ee commit 84ff053

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

pretty.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,24 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
10561056
return 0;
10571057
}
10581058

1059+
static int match_placeholder_arg(const char *to_parse, const char *candidate,
1060+
const char **end)
1061+
{
1062+
const char *p;
1063+
1064+
if (!(skip_prefix(to_parse, candidate, &p)))
1065+
return 0;
1066+
if (*p == ',') {
1067+
*end = p + 1;
1068+
return 1;
1069+
}
1070+
if (*p == ')') {
1071+
*end = p;
1072+
return 1;
1073+
}
1074+
return 0;
1075+
}
1076+
10591077
static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
10601078
const char *placeholder,
10611079
void *context)
@@ -1285,11 +1303,16 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
12851303

12861304
if (skip_prefix(placeholder, "(trailers", &arg)) {
12871305
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
1288-
while (*arg == ':') {
1289-
if (skip_prefix(arg, ":only", &arg))
1290-
opts.only_trailers = 1;
1291-
else if (skip_prefix(arg, ":unfold", &arg))
1292-
opts.unfold = 1;
1306+
if (*arg == ':') {
1307+
arg++;
1308+
for (;;) {
1309+
if (match_placeholder_arg(arg, "only", &arg))
1310+
opts.only_trailers = 1;
1311+
else if (match_placeholder_arg(arg, "unfold", &arg))
1312+
opts.unfold = 1;
1313+
else
1314+
break;
1315+
}
12931316
}
12941317
if (*arg == ')') {
12951318
format_trailers_from_commit(sb, msg + c->subject_off, &opts);

t/t4205-log-pretty-formats.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ test_expect_success '%(trailers:unfold) unfolds trailers' '
588588
'
589589

590590
test_expect_success ':only and :unfold work together' '
591-
git log --no-walk --pretty="%(trailers:only:unfold)" >actual &&
592-
git log --no-walk --pretty="%(trailers:unfold:only)" >reverse &&
591+
git log --no-walk --pretty="%(trailers:only,unfold)" >actual &&
592+
git log --no-walk --pretty="%(trailers:unfold,only)" >reverse &&
593593
test_cmp actual reverse &&
594594
{
595595
grep -v patch.description <trailers | unfold &&

0 commit comments

Comments
 (0)