pretty.c: delimit "%(trailers)" arguments with ","
authorTaylor Blau <me@ttaylorr.com>
Sun, 1 Oct 2017 16:18:47 +0000 (09:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Oct 2017 00:22:52 +0000 (09:22 +0900)
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>
pretty.c
t/t4205-log-pretty-formats.sh
index 94eab5c89ee1a1fa696b9fc491a5846008a2a255..2f6b0ae6c1486660bb37442b991cb1140a9f2bb6 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1056,6 +1056,24 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
        return 0;
 }
 
+static int match_placeholder_arg(const char *to_parse, const char *candidate,
+                                const char **end)
+{
+       const char *p;
+
+       if (!(skip_prefix(to_parse, candidate, &p)))
+               return 0;
+       if (*p == ',') {
+               *end = p + 1;
+               return 1;
+       }
+       if (*p == ')') {
+               *end = p;
+               return 1;
+       }
+       return 0;
+}
+
 static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
                                const char *placeholder,
                                void *context)
@@ -1285,11 +1303,16 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 
        if (skip_prefix(placeholder, "(trailers", &arg)) {
                struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
-               while (*arg == ':') {
-                       if (skip_prefix(arg, ":only", &arg))
-                               opts.only_trailers = 1;
-                       else if (skip_prefix(arg, ":unfold", &arg))
-                               opts.unfold = 1;
+               if (*arg == ':') {
+                       arg++;
+                       for (;;) {
+                               if (match_placeholder_arg(arg, "only", &arg))
+                                       opts.only_trailers = 1;
+                               else if (match_placeholder_arg(arg, "unfold", &arg))
+                                       opts.unfold = 1;
+                               else
+                                       break;
+                       }
                }
                if (*arg == ')') {
                        format_trailers_from_commit(sb, msg + c->subject_off, &opts);
index ec5f530102c04080b9d199269583cac9ab924c7e..977472f5390fbe6d1a19c52dd70692ca55dff505 100755 (executable)
@@ -588,8 +588,8 @@ test_expect_success '%(trailers:unfold) unfolds trailers' '
 '
 
 test_expect_success ':only and :unfold work together' '
-       git log --no-walk --pretty="%(trailers:only:unfold)" >actual &&
-       git log --no-walk --pretty="%(trailers:unfold:only)" >reverse &&
+       git log --no-walk --pretty="%(trailers:only,unfold)" >actual &&
+       git log --no-walk --pretty="%(trailers:unfold,only)" >reverse &&
        test_cmp actual reverse &&
        {
                grep -v patch.description <trailers | unfold &&