From c169af8f7ab521cc47b59f104db78847e324a3cb Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 Mar 2023 01:11:49 -0500 Subject: format-patch: do not respect diff.noprefix The output of format-patch respects diff.noprefix, but this usually ends up being a hassle for people receiving the patch, as they have to manually specify "-p0" in order to apply it. I don't think there was any specific intention for it to behave this way. The noprefix option is handled by git_diff_ui_config(), and format-patch exists in a gray area between plumbing and porcelain. People do look at the output, and we'd expect it to colorize things, respect their choice of algorithm, and so on. But this particular option creates problems for the receiver (in theory so does diff.mnemonicprefix, but since we are always formatting commits, the mnemonic prefixes will always be "a/" and "b/"). So let's disable it. The slight downsides are: - people who have set diff.noprefix presumably like to see their patches without prefixes. If they use format-patch to review their series, they'll see prefixes. On the other hand, it is probably a good idea for them to look at what will actually get sent out. We could try to play games here with "is stdout a tty", as we do for color. But that's not a completely reliable signal, and it's probably not worth the trouble. If you want to see the patch with the usual bells and whistles, then you are better off using "git log" or "git show". - if a project really does have a workflow that likes prefix-less patches, and the receiver is prepared to use "-p0", then the sender now has to manually say "--no-prefix" for each format-patch invocation. That doesn't seem _too_ terrible given that the receiver has to manually say "-p0" for each git-am invocation. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/log.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'builtin') diff --git a/builtin/log.c b/builtin/log.c index a70fba198f..eaf511aab8 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1085,6 +1085,15 @@ static int git_format_config(const char *var, const char *value, void *cb) return 0; } + /* + * ignore some porcelain config which would otherwise be parsed by + * git_diff_ui_config(), via git_log_config(); we can't just avoid + * diff_ui_config completely, because we do care about some ui options + * like color. + */ + if (!strcmp(var, "diff.noprefix")) + return 0; + return git_log_config(var, value, cb); } -- cgit v1.2.3 From 8d5213decff887b2d950b732e37b7abad6f8d450 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 Mar 2023 01:12:37 -0500 Subject: format-patch: add format.noprefix option 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 Signed-off-by: Junio C Hamano --- builtin/log.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'builtin') diff --git a/builtin/log.c b/builtin/log.c index eaf511aab8..b1f59062f4 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -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 [] [] [[--] ...]"), @@ -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; -- cgit v1.2.3 From ab89575387c02ea024163256826ad1c6dd2e4247 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 13 Mar 2023 15:54:11 -0400 Subject: rebase: prefer --default-prefix to --{src,dst}-prefix for format-patch When git-rebase invokes format-patch, it wants to make sure we use the normal prefixes, and are not confused by diff.noprefix or similar. When this was added in 5b220a6876f (Add --src/dst-prefix to git-formt-patch in git-rebase.sh, 2010-09-09), we only had --src-prefix and --dst-prefix to do so, which requires re-specifying the prefixes we expect to see. These days we can say what we want more directly: just use the defaults. This is a minor cleanup that should have no behavior change, but hopefully the result expresses more clearly what the code is trying to accomplish. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/rebase.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/rebase.c b/builtin/rebase.c index 6635f10d52..a47dfd45ef 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -660,7 +660,7 @@ static int run_am(struct rebase_options *opts) format_patch.git_cmd = 1; strvec_pushl(&format_patch.args, "format-patch", "-k", "--stdout", "--full-index", "--cherry-pick", "--right-only", - "--src-prefix=a/", "--dst-prefix=b/", "--no-renames", + "--default-prefix", "--no-renames", "--no-cover-letter", "--pretty=mboxrd", "--topo-order", "--no-base", NULL); if (opts->git_format_patch_opt.len) -- cgit v1.2.3