interpret-trailers: allow suppressing "---" divider

Even with the newly-tightened "---" parser, it's still possible for a commit message to trigger a false positive if it contains something like "--- foo". If the caller knows that it has only a single commit message, it can now tell us with the "--no-divider" option, eliminating any false positives. If we were designing this from scratch, I'd probably make this the default. But we've advertised the "---" behavior in the documentation since interpret-trailers has existed. Since it's meant to be scripted, breaking that would be a bad idea. Note that the logic is in the underlying trailer.c code, which is used elsewhere. The default there will keep the current behavior, but many callers will benefit from setting this new option. That's left for future patches. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 22, 2018 at 20:49 UTC 1688c9a4894df517241026c7a3848bdc84607986
5 files changed +33 -2
Documentation/git-interpret-trailers.txt
+6 -1
@@ -58,7 +58,7 @@ The group must be preceded by one or more empty (or whitespace-only) lines.
58 The group must either be at the end of the message or be the last
59 non-whitespace lines before a line that starts with '---' (followed by a
60 space or the end of the line). Such three minus signs start the patch
61 -part of the message.
61 +part of the message. See also `--no-divider` below.
62
63 When reading trailers, there can be whitespaces after the
64 token, the separator and the value. There can also be whitespaces
@@ -123,6 +123,11 @@ OPTIONS
123 A convenience alias for `--only-trailers --only-input
124 --unfold`.
125
126 +--no-divider::
127 + Do not treat `---` as the end of the commit message. Use this
128 + when you know your input contains just the commit message itself
129 + (and not an email or the output of `git format-patch`).
130 +
131 CONFIGURATION VARIABLES
132 -----------------------
133
builtin/interpret-trailers.c
+1
@@ -104,6 +104,7 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
104 OPT_BOOL(0, "unfold", &opts.unfold, N_("join whitespace-continued values")),
105 { OPTION_CALLBACK, 0, "parse", &opts, NULL, N_("set parsing options"),
106 PARSE_OPT_NOARG | PARSE_OPT_NONEG, parse_opt_parse },
107 + OPT_BOOL(0, "no-divider", &opts.no_divider, N_("do not treat --- specially")),
108 OPT_CALLBACK(0, "trailer", &trailers, N_("trailer"),
109 N_("trailer(s) to add"), option_parse_trailer),
110 OPT_END()
t/t7513-interpret-trailers.sh
+20
@@ -1439,4 +1439,24 @@ test_expect_success 'handling of --- lines in input' '
1439 test_cmp expected actual
1440 '
1441
1442 +test_expect_success 'suppress --- handling' '
1443 + echo "real-trailer: just right" >expected &&
1444 +
1445 + git interpret-trailers --parse --no-divider >actual <<-\EOF &&
1446 + subject
1447 +
1448 + This commit message has a "---" in it, but because we tell
1449 + interpret-trailers not to respect that, it has no effect.
1450 +
1451 + not-a-trailer: too soon
1452 + ---
1453 +
1454 + This is still the commit message body.
1455 +
1456 + real-trailer: just right
1457 + EOF
1458 +
1459 + test_cmp expected actual
1460 +'
1461 +
1462 test_done
trailer.c
+5 -1
@@ -1080,7 +1080,11 @@ void trailer_info_get(struct trailer_info *info, const char *str,
1080
1081 ensure_configured();
1082
1083 - patch_start = find_patch_start(str);
1083 + if (opts->no_divider)
1084 + patch_start = strlen(str);
1085 + else
1086 + patch_start = find_patch_start(str);
1087 +
1088 trailer_end = find_trailer_end(str, patch_start);
1089 trailer_start = find_trailer_start(str, trailer_end);
1090
trailer.h
+1
@@ -69,6 +69,7 @@ struct process_trailer_options {
69 int only_trailers;
70 int only_input;
71 int unfold;
72 + int no_divider;
73 };
74
75 #define PROCESS_TRAILER_OPTIONS_INIT {0}