Skip to content

Commit bd8bc2b

Browse files
committed
diff: bypass diff process with --no-ext-diff and in format-patch
Make --no-ext-diff disable diff.<driver>.process in addition to diff.<driver>.command. Although the two mechanisms work differently (command replaces Git's output, process feeds hunks back into the pipeline), both invoke external tools and --no-ext-diff means "no external tools." Replace the OPT_BOOL for --ext-diff with an OPT_CALLBACK that sets both allow_external and no_diff_process, so a single option controls both. Passing --ext-diff explicitly clears no_diff_process, so a later --ext-diff overrides an earlier --no-ext-diff. Disable the diff process unconditionally in format-patch so that generated patches are always based on the builtin diff algorithm and can be applied reliably by recipients who do not have the external tool. Document that --diff-algorithm also bypasses the diff process, since it sets ignore_driver_algorithm which diff_process_fill_hunks already checks. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
1 parent 76f1c8e commit bd8bc2b

6 files changed

Lines changed: 46 additions & 4 deletions

File tree

Documentation/diff-algorithm-option.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
For instance, if you configured the `diff.algorithm` variable to a
1919
non-default value and want to use the default one, then you
2020
have to use `--diff-algorithm=default` option.
21+
+
22+
If you explicitly choose a diff algorithm, it also bypasses
23+
`diff.<driver>.process` (see linkgit:gitattributes[5]).

Documentation/diff-options.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,9 @@ endif::git-format-patch[]
825825
to use this option with linkgit:git-log[1] and friends.
826826

827827
`--no-ext-diff`::
828-
Disallow external diff drivers.
828+
Disallow external diff helpers, including
829+
`diff.<driver>.command` and `diff.<driver>.process`
830+
(see linkgit:gitattributes[5]).
829831

830832
`--textconv`::
831833
`--no-textconv`::

builtin/log.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,13 @@ int cmd_format_patch(int argc,
22132213
if (argc > 1)
22142214
die(_("unrecognized argument: %s"), argv[1]);
22152215

2216+
/*
2217+
* Disable diff.<driver>.process so that patches generated by
2218+
* format-patch are always based on the builtin diff algorithm
2219+
* and can be applied reliably.
2220+
*/
2221+
rev.diffopt.flags.no_diff_process = 1;
2222+
22162223
if (rev.diffopt.output_format & DIFF_FORMAT_NAME)
22172224
die(_("--name-only does not make sense"));
22182225
if (rev.diffopt.output_format & DIFF_FORMAT_NAME_STATUS)

diff.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5913,6 +5913,17 @@ static int diff_opt_submodule(const struct option *opt,
59135913
return 0;
59145914
}
59155915

5916+
static int diff_opt_ext_diff(const struct option *opt,
5917+
const char *arg, int unset)
5918+
{
5919+
struct diff_options *options = opt->value;
5920+
5921+
BUG_ON_OPT_ARG(arg);
5922+
options->flags.allow_external = !unset;
5923+
options->flags.no_diff_process = unset;
5924+
return 0;
5925+
}
5926+
59165927
static int diff_opt_textconv(const struct option *opt,
59175928
const char *arg, int unset)
59185929
{
@@ -6241,8 +6252,9 @@ struct option *add_diff_options(const struct option *opts,
62416252
N_("exit with 1 if there were differences, 0 otherwise")),
62426253
OPT_BOOL(0, "quiet", &options->flags.quick,
62436254
N_("disable all output of the program")),
6244-
OPT_BOOL(0, "ext-diff", &options->flags.allow_external,
6245-
N_("allow an external diff helper to be executed")),
6255+
OPT_CALLBACK_F(0, "ext-diff", options, NULL,
6256+
N_("allow an external diff helper to be executed"),
6257+
PARSE_OPT_NOARG, diff_opt_ext_diff),
62466258
OPT_CALLBACK_F(0, "textconv", options, NULL,
62476259
N_("run external text conversion filters when comparing binary files"),
62486260
PARSE_OPT_NOARG, diff_opt_textconv),

diff.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ struct diff_flags {
173173
*/
174174
unsigned allow_external;
175175

176-
/** Disables diff.<driver>.process. */
176+
/**
177+
* Disables diff.<driver>.process. Set by --no-ext-diff.
178+
*/
177179
unsigned no_diff_process;
178180

179181
/**

t/t4080-diff-process.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,22 @@ test_expect_success PYTHON 'diff process bypassed by --diff-algorithm' '
419419
test_path_is_missing backend.log
420420
'
421421

422+
test_expect_success PYTHON 'diff process bypassed by --no-ext-diff' '
423+
rm -f backend.log &&
424+
git -c diff.cdiff.process="$BACKEND --log=backend.log" \
425+
diff --no-ext-diff worddiff.c >actual &&
426+
test_grep "return 999" actual &&
427+
test_path_is_missing backend.log
428+
'
429+
430+
test_expect_success PYTHON 'diff process not used by format-patch' '
431+
rm -f backend.log &&
432+
git -c diff.cdiff.process="$BACKEND --log=backend.log" \
433+
format-patch -1 --stdout -- logtest.c >actual &&
434+
test_grep "return 2" actual &&
435+
test_path_is_missing backend.log
436+
'
437+
422438
test_expect_success PYTHON 'diff process not used by --stat' '
423439
rm -f backend.log &&
424440
git -c diff.cdiff.process="$BACKEND --log=backend.log" \

0 commit comments

Comments
 (0)