Skip to content

Commit d473e2e

Browse files
pcloudsgitster
authored andcommitted
diff.c: convert -U|--unified
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cc013c2 commit d473e2e

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Documentation/diff-options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ endif::git-format-patch[]
3636
-U<n>::
3737
--unified=<n>::
3838
Generate diffs with <n> lines of context instead of
39-
the usual three.
39+
the usual three. Implies `--patch`.
4040
ifndef::git-format-patch[]
4141
Implies `-p`.
4242
endif::git-format-patch[]

diff.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4867,6 +4867,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
48674867
return 1;
48684868
}
48694869

4870+
static int diff_opt_unified(const struct option *opt,
4871+
const char *arg, int unset)
4872+
{
4873+
struct diff_options *options = opt->value;
4874+
char *s;
4875+
4876+
BUG_ON_OPT_NEG(unset);
4877+
4878+
options->context = strtol(arg, &s, 10);
4879+
if (*s)
4880+
return error(_("%s expects a numerical value"), "--unified");
4881+
enable_patch_output(&options->output_format);
4882+
4883+
return 0;
4884+
}
4885+
48704886
static void prep_parse_options(struct diff_options *options)
48714887
{
48724888
struct option parseopts[] = {
@@ -4877,6 +4893,9 @@ static void prep_parse_options(struct diff_options *options)
48774893
OPT_BITOP('u', NULL, &options->output_format,
48784894
N_("generate patch"),
48794895
DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
4896+
OPT_CALLBACK_F('U', "unified", options, N_("<n>"),
4897+
N_("generate diffs with <n> lines context"),
4898+
PARSE_OPT_NONEG, diff_opt_unified),
48804899
OPT_END()
48814900
};
48824901

@@ -4905,9 +4924,7 @@ int diff_opt_parse(struct diff_options *options,
49054924
return ac;
49064925

49074926
/* Output format options */
4908-
if (opt_arg(arg, 'U', "unified", &options->context))
4909-
enable_patch_output(&options->output_format);
4910-
else if (!strcmp(arg, "--raw"))
4927+
if (!strcmp(arg, "--raw"))
49114928
options->output_format |= DIFF_FORMAT_RAW;
49124929
else if (!strcmp(arg, "--patch-with-raw")) {
49134930
enable_patch_output(&options->output_format);

parse-options.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ struct option {
134134
#define OPT_SET_INT_F(s, l, v, h, i, f) { OPTION_SET_INT, (s), (l), (v), NULL, \
135135
(h), PARSE_OPT_NOARG | (f), NULL, (i) }
136136
#define OPT_BOOL_F(s, l, v, h, f) OPT_SET_INT_F(s, l, v, h, 1, f)
137+
#define OPT_CALLBACK_F(s, l, v, a, h, f, cb) \
138+
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) }
137139

138140
#define OPT_END() { OPTION_END }
139141
#define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, \
@@ -164,8 +166,7 @@ struct option {
164166
#define OPT_EXPIRY_DATE(s, l, v, h) \
165167
{ OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0, \
166168
parse_opt_expiry_date_cb }
167-
#define OPT_CALLBACK(s, l, v, a, h, f) \
168-
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }
169+
#define OPT_CALLBACK(s, l, v, a, h, f) OPT_CALLBACK_F(s, l, v, a, h, 0, f)
169170
#define OPT_NUMBER_CALLBACK(v, h, f) \
170171
{ OPTION_NUMBER, 0, NULL, (v), NULL, (h), \
171172
PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) }

0 commit comments

Comments
 (0)