]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: add format.noprefix option
authorJeff King <peff@peff.net>
Thu, 9 Mar 2023 06:12:37 +0000 (01:12 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Mar 2023 16:37:27 +0000 (08:37 -0800)
The previous commit dropped support for diff.noprefix in format-patch.
While this will do the right thing in most cases (where sending patches
without a prefix was an accidental side effect of the sender preferring
to see their local patches without prefixes), it left no good option for
a project or workflow where you really do want to send patches without
prefixes. You'd be stuck using "--no-prefix" for every invocation.

So let's add a config option specific to format-patch that enables this
behavior. That gives people who have such a workflow a way to get what
they want, but makes it hard to accidentally trigger it.

A more backwards-compatible way of doing the transition would be to have
format.noprefix default to diff.noprefix when it's not set. But that
doesn't really help the "accidental" problem; people would have to
manually set format.noprefix=false. And it's unlikely that anybody
really wants format.noprefix=true in the first place. I'm adding it here
mostly as an escape hatch, not because anybody has expressed any
interest in it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/format.txt
builtin/log.c
t/t4014-format-patch.sh

index 73678d88a1dba172c43f4fb850e750c6a0c7f96c..8cf6f00d9365cf19b6244ba005d078c5ebed8a05 100644 (file)
@@ -144,3 +144,10 @@ will only show notes from `refs/notes/bar`.
 format.mboxrd::
        A boolean value which enables the robust "mboxrd" format when
        `--stdout` is in use to escape "^>+From " lines.
+
+format.noprefix::
+       If set, do not show any source or destination prefix in patches.
+       This is equivalent to the `diff.noprefix` option used by `git
+       diff` (but which is not respected by `format-patch`). Note that
+       by setting this, the receiver of any patches you generate will
+       have to apply them using the `-p0` option.
index eaf511aab86697c222cc12e3568e1d51d5701928..b1f59062f40d45b40f173e8feaa6e6f2f03995f8 100644 (file)
@@ -56,6 +56,7 @@ static int stdout_mboxrd;
 static const char *fmt_patch_subject_prefix = "PATCH";
 static int fmt_patch_name_max = FORMAT_PATCH_NAME_MAX_DEFAULT;
 static const char *fmt_pretty;
+static int format_no_prefix;
 
 static const char * const builtin_log_usage[] = {
        N_("git log [<options>] [<revision-range>] [[--] <path>...]"),
@@ -1084,6 +1085,10 @@ static int git_format_config(const char *var, const char *value, void *cb)
                stdout_mboxrd = git_config_bool(var, value);
                return 0;
        }
+       if (!strcmp(var, "format.noprefix")) {
+               format_no_prefix = 1;
+               return 0;
+       }
 
        /*
         * ignore some porcelain config which would otherwise be parsed by
@@ -2002,6 +2007,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        s_r_opt.def = "HEAD";
        s_r_opt.revarg_opt = REVARG_COMMITTISH;
 
+       if (format_no_prefix)
+               diff_set_noprefix(&rev.diffopt);
+
        if (default_attach) {
                rev.mime_boundary = default_attach;
                rev.no_inline = 1;
index f5a41fd47ed3cfddbf9c8216afc849975b5a3ea4..2711fd09ca0761cf2ada959faf2e83a4c7d201af 100755 (executable)
@@ -2391,4 +2391,15 @@ test_expect_success 'format-patch does not respect diff.noprefix' '
        grep "^--- a/blorp" actual
 '
 
+test_expect_success 'format-patch respects format.noprefix' '
+       git -c format.noprefix format-patch -1 --stdout >actual &&
+       grep "^--- blorp" actual
+'
+
+test_expect_success 'format-patch --default-prefix overrides format.noprefix' '
+       git -c format.noprefix \
+               format-patch -1 --default-prefix --stdout >actual &&
+       grep "^--- a/blorp" actual
+'
+
 test_done