]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: bypass diff process with --no-ext-diff and in format-patch
authorMichael Montalbo <mmontalbo@gmail.com>
Sun, 26 Jul 2026 18:51:25 +0000 (18:51 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 26 Jul 2026 21:03:54 +0000 (14:03 -0700)
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 forces the builtin algorithm.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/diff-algorithm-option.adoc
Documentation/diff-options.adoc
Documentation/gitattributes.adoc
builtin/log.c
diff.c
diff.h
t/t4080-diff-process.sh

index 8e3a0b63d784d8b68fdaf83ae1fba495b656d426..4d7e2ec35f97ea2bc02ab474eef99dac0e552a00 100644 (file)
@@ -18,3 +18,6 @@
 For instance, if you configured the `diff.algorithm` variable to a
 non-default value and want to use the default one, then you
 have to use `--diff-algorithm=default` option.
++
+If you explicitly choose a diff algorithm, it also bypasses
+`diff.<driver>.process` (see linkgit:gitattributes[5]).
index c8242e24627eef89554f94ff06fa2bd0c6d1c562..a884445211ed8ec9d2e42c5e844aa6dbcad77ac7 100644 (file)
@@ -833,7 +833,9 @@ endif::git-format-patch[]
        to use this option with linkgit:git-log[1] and friends.
 
 `--no-ext-diff`::
-       Disallow external diff drivers.
+       Disallow external diff helpers, including
+       `diff.<driver>.command` and `diff.<driver>.process`
+       (see linkgit:gitattributes[5]).
 
 `--textconv`::
 `--no-textconv`::
index f4ca4a8c7e229605ee547c553cdc0c426e7d244b..a03fb9deb108d5b6104fae62ea29a4cbac6586e4 100644 (file)
@@ -1073,9 +1073,9 @@ display, which is covered above); and combined diffs (`--cc` and merge
 diffs), whose protocol would have to be extended from a single old/new
 pair to one comparison per merge parent.
 
-`--diff-algorithm` bypasses the process entirely, for every feature
-listed above.  The whitespace-ignoring options (`-w`,
-`--ignore-space-change`, `--ignore-blank-lines`, and the like),
+`--no-ext-diff` and `--diff-algorithm` bypass the process entirely,
+for every feature listed above.  The whitespace-ignoring options
+(`-w`, `--ignore-space-change`, `--ignore-blank-lines`, and the like),
 `-I<regex>`, and `--anchored` also bypass it for the affected files:
 the tool is never told about these options, so it could not honor
 them, and Git falls back to the builtin diff, which does.
index 350b35c556362d6bc987ea9af701db2f20b86cff..ebbf411659056e574e78cfb298d6b50ed5bbdb81 100644 (file)
@@ -2218,6 +2218,13 @@ int cmd_format_patch(int argc,
        if (argc > 1)
                die(_("unrecognized argument: %s"), argv[1]);
 
+       /*
+        * Disable diff.<driver>.process so that patches generated by
+        * format-patch are always based on the builtin diff algorithm
+        * and can be applied reliably.
+        */
+       rev.diffopt.flags.no_diff_process = 1;
+
        if (rev.diffopt.output_format & DIFF_FORMAT_NAME)
                die(_("--name-only does not make sense"));
        if (rev.diffopt.output_format & DIFF_FORMAT_NAME_STATUS)
diff --git a/diff.c b/diff.c
index 31b1b2f4cf7ec1716e908a8ddb6be24722e7f4e3..0fcb694d3050d2589dcc74cd5aecf7a74d2391e8 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -6075,6 +6075,17 @@ static int diff_opt_submodule(const struct option *opt,
        return 0;
 }
 
+static int diff_opt_ext_diff(const struct option *opt,
+                            const char *arg, int unset)
+{
+       struct diff_options *options = opt->value;
+
+       BUG_ON_OPT_ARG(arg);
+       options->flags.allow_external = !unset;
+       options->flags.no_diff_process = unset;
+       return 0;
+}
+
 static int diff_opt_textconv(const struct option *opt,
                             const char *arg, int unset)
 {
@@ -6405,8 +6416,9 @@ struct option *add_diff_options(const struct option *opts,
                         N_("exit with 1 if there were differences, 0 otherwise")),
                OPT_BOOL(0, "quiet", &options->flags.quick,
                         N_("disable all output of the program")),
-               OPT_BOOL(0, "ext-diff", &options->flags.allow_external,
-                        N_("allow an external diff helper to be executed")),
+               OPT_CALLBACK_F(0, "ext-diff", options, NULL,
+                              N_("allow an external diff helper to be executed"),
+                              PARSE_OPT_NOARG, diff_opt_ext_diff),
                OPT_CALLBACK_F(0, "textconv", options, NULL,
                               N_("run external text conversion filters when comparing binary files"),
                               PARSE_OPT_NOARG, diff_opt_textconv),
diff --git a/diff.h b/diff.h
index 7dc157968d69f992bdcb0fc1ab783245a3e11001..ee034d240da78b9e05fb94f8f5afd0a865d90a42 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -173,7 +173,10 @@ struct diff_flags {
         */
        unsigned allow_external;
 
-       /** Disables diff.<driver>.process. */
+       /**
+        * Disables diff.<driver>.process.  Set by --no-ext-diff and by
+        * format-patch.
+        */
        unsigned no_diff_process;
 
        /**
index 3b75df082e8defd6402da0aae22ed921b018b646..7e71b70ab95467345385935b393a634f18afb19c 100755 (executable)
@@ -398,6 +398,22 @@ test_expect_success 'diff process bypassed by --diff-algorithm' '
        test_path_is_missing backend.log
 '
 
+test_expect_success 'diff process bypassed by --no-ext-diff' '
+       test_when_finished "rm -f backend.log" &&
+       git -c diff.cdiff.process="$BACKEND --log=backend.log" \
+               diff --no-ext-diff worddiff.c >actual &&
+       test_grep "return 999" actual &&
+       test_path_is_missing backend.log
+'
+
+test_expect_success 'diff process not used by format-patch' '
+       test_when_finished "rm -f backend.log" &&
+       git -c diff.cdiff.process="$BACKEND --log=backend.log" \
+               format-patch -1 --stdout -- logtest.c >actual &&
+       test_grep "return 2" actual &&
+       test_path_is_missing backend.log
+'
+
 test_expect_success 'diff process bypassed under whitespace-ignoring flags' '
        test_when_finished "rm -f backend.log" &&
        printf "a\nb\nc\n" >wsbypass.c &&