Skip to content

Commit 6d9af6f

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent df84a43 commit 6d9af6f

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

Documentation/diff-options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ endif::git-format-patch[]
425425

426426
--binary::
427427
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`.
429429

430430
--abbrev[=<n>]::
431431
Instead of showing the full 40-byte hexadecimal object

diff.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4852,6 +4852,18 @@ static int diff_opt_anchored(const struct option *opt,
48524852
return 0;
48534853
}
48544854

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+
48554867
static int diff_opt_break_rewrites(const struct option *opt,
48564868
const char *arg, int unset)
48574869
{
@@ -5116,6 +5128,9 @@ static void prep_parse_options(struct diff_options *options)
51165128
OPT_CALLBACK_F(0, "compact-summary", options, NULL,
51175129
N_("generate compact summary in diffstat"),
51185130
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),
51195134
OPT_CALLBACK_F(0, "output-indicator-new",
51205135
&options->output_indicators[OUTPUT_INDICATOR_NEW],
51215136
N_("<char>"),
@@ -5229,11 +5244,7 @@ int diff_opt_parse(struct diff_options *options,
52295244
return ac;
52305245

52315246
/* 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"))
52375248
options->flags.full_index = 1;
52385249
else if (!strcmp(arg, "-a") || !strcmp(arg, "--text"))
52395250
options->flags.text = 1;

0 commit comments

Comments
 (0)