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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Oct 1, 2017 at 09:18 UTC
84ff053d47c20c9f417f857e4adac0bcd8e01f0d
2 files changed
+30
-7
pretty.c
+28
-5
@@ -1056,6 +1056,24 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
1056
return 0;
1057
}
1058
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
+
1077
static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1078
const char *placeholder,
1079
void *context)
@@ -1285,11 +1303,16 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1303
1304
if (skip_prefix(placeholder, "(trailers", &arg)) {
1305
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
+ }
1316
}
1317
if (*arg == ')') {
1318
format_trailers_from_commit(sb, msg + c->subject_off, &opts);
t/t4205-log-pretty-formats.sh
+2
-2
@@ -588,8 +588,8 @@ test_expect_success '%(trailers:unfold) unfolds trailers' '
588
'
589
590
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 &&
593
test_cmp actual reverse &&
594
{
595
grep -v patch.description <trailers | unfold &&