Skip to content

Commit 99e09da

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0000239 commit 99e09da

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

Documentation/git-interpret-trailers.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@ git-interpret-trailers(1)
33

44
NAME
55
----
6-
git-interpret-trailers - help add structured information into commit messages
6+
git-interpret-trailers - add or parse structured information in commit messages
77

88
SYNOPSIS
99
--------
1010
[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>...]
1213

1314
DESCRIPTION
1415
-----------
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
1617
headers, at the end of the otherwise free-form part of a commit
1718
message.
1819

1920
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.
2427

2528
Some configuration variables control the way the `--trailer` arguments
2629
are applied to each commit message and the way any existing trailer in
@@ -92,6 +95,10 @@ OPTIONS
9295
Remove any whitespace-continuation in trailers, so that each
9396
trailer appears on a line by itself with its full content.
9497

98+
--parse::
99+
A convenience alias for `--only-trailers --only-input
100+
--unfold`.
101+
95102
CONFIGURATION VARIABLES
96103
-----------------------
97104

builtin/interpret-trailers.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ static const char * const git_interpret_trailers_usage[] = {
1616
NULL
1717
};
1818

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+
1929
int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
2030
{
2131
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)
2737
OPT_BOOL(0, "only-trailers", &opts.only_trailers, N_("output only the trailers")),
2838
OPT_BOOL(0, "only-input", &opts.only_input, N_("do not apply config rules")),
2939
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 },
3042
OPT_STRING_LIST(0, "trailer", &trailers, N_("trailer"),
3143
N_("trailer(s) to add")),
3244
OPT_END()

0 commit comments

Comments
 (0)