diff-parseopt: convert --binary
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Mar 5, 2019 at 19:30 UTC
6d9af6f4dac4079e0ea14a86cbdf6790c1586fce
2 files changed
+17
-6
Documentation/diff-options.txt
+1
-1
@@ -425,7 +425,7 @@ endif::git-format-patch[]
425
426
--binary::
427
In addition to `--full-index`, output a binary diff that
428
- can be applied with `git-apply`.
428
+ can be applied with `git-apply`. Implies `--patch`.
429
430
--abbrev[=<n>]::
431
Instead of showing the full 40-byte hexadecimal object
diff.c
+16
-5
@@ -4852,6 +4852,18 @@ static int diff_opt_anchored(const struct option *opt,
4852
return 0;
4853
}
4854
4855
+static int diff_opt_binary(const struct option *opt,
4856
+ const char *arg, int unset)
4857
+{
4858
+ struct diff_options *options = opt->value;
4859
+
4860
+ BUG_ON_OPT_NEG(unset);
4861
+ BUG_ON_OPT_ARG(arg);
4862
+ enable_patch_output(&options->output_format);
4863
+ options->flags.binary = 1;
4864
+ return 0;
4865
+}
4866
+
4867
static int diff_opt_break_rewrites(const struct option *opt,
4868
const char *arg, int unset)
4869
{
@@ -5116,6 +5128,9 @@ static void prep_parse_options(struct diff_options *options)
5128
OPT_CALLBACK_F(0, "compact-summary", options, NULL,
5129
N_("generate compact summary in diffstat"),
5130
PARSE_OPT_NOARG, diff_opt_compact_summary),
5131
+ OPT_CALLBACK_F(0, "binary", options, NULL,
5132
+ N_("output a binary diff that can be applied"),
5133
+ PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_binary),
5134
OPT_CALLBACK_F(0, "output-indicator-new",
5135
&options->output_indicators[OUTPUT_INDICATOR_NEW],
5136
N_("<char>"),
@@ -5229,11 +5244,7 @@ int diff_opt_parse(struct diff_options *options,
5244
return ac;
5245
5246
/* flags options */
5232
- if (!strcmp(arg, "--binary")) {
5233
- enable_patch_output(&options->output_format);
5234
- options->flags.binary = 1;
5235
- }
5236
- else if (!strcmp(arg, "--full-index"))
5247
+ if (!strcmp(arg, "--full-index"))
5248
options->flags.full_index = 1;
5249
else if (!strcmp(arg, "-a") || !strcmp(arg, "--text"))
5250
options->flags.text = 1;