interpret-trailers: add --parse convenience option

The last few commits have added command line options that can turn interpret-trailers into a parsing tool. Since they'd most often be used together, let's provide a convenient single option for callers to invoke this mode. This is implemented as a callback rather than a boolean so that its effect is applied immediately, as if those options had been specified. Later options can then override them. E.g.: git interpret-trailers --parse --no-unfold would work. Let's also update the documentation to make clear that this parsing mode behaves quite differently than the normal "add trailers to the input" mode. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 15, 2017 at 06:23 UTC 99e09dafd7b7bcac4d8189b41dc6038bf36334f5
2 files changed +26 -7
Documentation/git-interpret-trailers.txt
+14 -7
@@ -3,24 +3,27 @@ git-interpret-trailers(1)
3
4 NAME
5 ----
6 -git-interpret-trailers - help add structured information into commit messages
6 +git-interpret-trailers - add or parse structured information in commit messages
7
8 SYNOPSIS
9 --------
10 [verse]
11 -'git interpret-trailers' [--in-place] [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [<file>...]
11 +'git interpret-trailers' [options] [(--trailer <token>[(=|:)<value>])...] [<file>...]
12 +'git interpret-trailers' [options] [--parse] [<file>...]
13
14 DESCRIPTION
15 -----------
15 -Help adding 'trailers' lines, that look similar to RFC 822 e-mail
16 +Help parsing or adding 'trailers' lines, that look similar to RFC 822 e-mail
17 headers, at the end of the otherwise free-form part of a commit
18 message.
19
20 This command reads some patches or commit messages from either the
20 -<file> arguments or the standard input if no <file> is specified. Then
21 -this command applies the arguments passed using the `--trailer`
22 -option, if any, to the commit message part of each input file. The
23 -result is emitted on the standard output.
21 +<file> arguments or the standard input if no <file> is specified. If
22 +`--parse` is specified, the output consists of the parsed trailers.
23 +
24 +Otherwise, the this command applies the arguments passed using the
25 +`--trailer` option, if any, to the commit message part of each input
26 +file. The result is emitted on the standard output.
27
28 Some configuration variables control the way the `--trailer` arguments
29 are applied to each commit message and the way any existing trailer in
@@ -92,6 +95,10 @@ OPTIONS
95 Remove any whitespace-continuation in trailers, so that each
96 trailer appears on a line by itself with its full content.
97
98 +--parse::
99 + A convenience alias for `--only-trailers --only-input
100 + --unfold`.
101 +
102 CONFIGURATION VARIABLES
103 -----------------------
104
builtin/interpret-trailers.c
+12
@@ -16,6 +16,16 @@ static const char * const git_interpret_trailers_usage[] = {
16 NULL
17 };
18
19 +static int parse_opt_parse(const struct option *opt, const char *arg,
20 + int unset)
21 +{
22 + struct process_trailer_options *v = opt->value;
23 + v->only_trailers = 1;
24 + v->only_input = 1;
25 + v->unfold = 1;
26 + return 0;
27 +}
28 +
29 int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
30 {
31 struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
@@ -27,6 +37,8 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
37 OPT_BOOL(0, "only-trailers", &opts.only_trailers, N_("output only the trailers")),
38 OPT_BOOL(0, "only-input", &opts.only_input, N_("do not apply config rules")),
39 OPT_BOOL(0, "unfold", &opts.unfold, N_("join whitespace-continued values")),
40 + { OPTION_CALLBACK, 0, "parse", &opts, NULL, N_("set parsing options"),
41 + PARSE_OPT_NOARG | PARSE_OPT_NONEG, parse_opt_parse },
42 OPT_STRING_LIST(0, "trailer", &trailers, N_("trailer"),
43 N_("trailer(s) to add")),
44 OPT_END()