Skip to content

Commit ac8ec7f

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. The two mechanisms serve the same purpose (external diff tools), so a single flag should control both. Replace the OPT_BOOL for --ext-diff with an OPT_CALLBACK that sets both allow_external and the new no_diff_process flag, keeping the option's user-facing behavior unchanged while extending it to cover the diff process. 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 632f997 commit ac8ec7f

5 files changed

Lines changed: 42 additions & 3 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ 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 drivers. Also disables
829+
`diff.<driver>.process` (see linkgit:gitattributes[5]).
829830

830831
`--textconv`::
831832
`--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),

t/t4080-diff-process.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ test_expect_success PYTHON 'diff process not used by --stat' '
333333
test_path_is_missing backend.log
334334
'
335335

336+
test_expect_success PYTHON 'diff process bypassed by --no-ext-diff' '
337+
rm -f backend.log &&
338+
git -c diff.cdiff.process="$BACKEND --log=backend.log" \
339+
diff --no-ext-diff worddiff.c >actual &&
340+
test_grep "return 999" actual &&
341+
test_path_is_missing backend.log
342+
'
343+
336344
test_expect_success PYTHON 'diff process works with git log -p' '
337345
cat >logtest.c <<-\EOF &&
338346
int logfunc(void) { return 1; }
@@ -354,6 +362,14 @@ test_expect_success PYTHON 'diff process works with git log -p' '
354362
test_must_be_empty stderr
355363
'
356364

365+
test_expect_success PYTHON 'diff process not used by format-patch' '
366+
rm -f backend.log &&
367+
git -c diff.cdiff.process="$BACKEND --log=backend.log" \
368+
format-patch -1 --stdout -- logtest.c >actual &&
369+
test_grep "return 2" actual &&
370+
test_path_is_missing backend.log
371+
'
372+
357373
test_expect_success PYTHON 'diff process startup failure only warns once' '
358374
git -c diff.cdiff.process="/nonexistent/tool" \
359375
diff -- multi1.c multi2.c >actual 2>stderr &&

0 commit comments

Comments
 (0)