From: Michael Montalbo via GitGitGadget Date: Fri, 29 May 2026 20:48:18 GMT Subject: [PATCH v3 5/6] diff: bypass diff process with --no-ext-diff and in format-patch Message-ID: In-Reply-To: From: Michael Montalbo Make --no-ext-diff disable diff..process in addition to diff..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 --- Documentation/diff-algorithm-option.adoc | 3 +++ Documentation/diff-options.adoc | 4 +++- builtin/log.c | 7 +++++++ diff.c | 16 ++++++++++++++-- diff.h | 4 +++- t/t4080-diff-process.sh | 16 ++++++++++++++++ 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Documentation/diff-algorithm-option.adoc b/Documentation/diff-algorithm-option.adoc index 8e3a0b63d7..4d7e2ec35f 100644 --- a/Documentation/diff-algorithm-option.adoc +++ b/Documentation/diff-algorithm-option.adoc @@ -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..process` (see linkgit:gitattributes[5]). diff --git a/Documentation/diff-options.adoc b/Documentation/diff-options.adoc index 8a63b5e164..18b8b0ed24 100644 --- a/Documentation/diff-options.adoc +++ b/Documentation/diff-options.adoc @@ -825,7 +825,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..command` and `diff..process` + (see linkgit:gitattributes[5]). `--textconv`:: `--no-textconv`:: diff --git a/builtin/log.c b/builtin/log.c index 8c0939dd42..1ea520c12d 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -2213,6 +2213,13 @@ int cmd_format_patch(int argc, if (argc > 1) die(_("unrecognized argument: %s"), argv[1]); + /* + * Disable diff..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 2d5ed6ea8c..38932db084 100644 --- a/diff.c +++ b/diff.c @@ -5913,6 +5913,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) { @@ -6241,8 +6252,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 d1e5a13e9e..71ba389f03 100644 --- a/diff.h +++ b/diff.h @@ -173,7 +173,9 @@ struct diff_flags { */ unsigned allow_external; - /** Disables diff..process. */ + /** + * Disables diff..process. Set by --no-ext-diff. + */ unsigned no_diff_process; /** diff --git a/t/t4080-diff-process.sh b/t/t4080-diff-process.sh index f159cd86d8..ee0c306abd 100755 --- a/t/t4080-diff-process.sh +++ b/t/t4080-diff-process.sh @@ -419,6 +419,22 @@ test_expect_success PYTHON 'diff process bypassed by --diff-algorithm' ' test_path_is_missing backend.log ' +test_expect_success PYTHON 'diff process bypassed by --no-ext-diff' ' + 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 PYTHON 'diff process not used by format-patch' ' + 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 PYTHON 'diff process not used by --stat' ' rm -f backend.log && git -c diff.cdiff.process="$BACKEND --log=backend.log" \ -- gitgitgadget