Skip to content

Commit 8d5213d

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c169af8 commit 8d5213d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Documentation/config/format.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,10 @@ will only show notes from `refs/notes/bar`.
144144
format.mboxrd::
145145
A boolean value which enables the robust "mboxrd" format when
146146
`--stdout` is in use to escape "^>+From " lines.
147+
148+
format.noprefix::
149+
If set, do not show any source or destination prefix in patches.
150+
This is equivalent to the `diff.noprefix` option used by `git
151+
diff` (but which is not respected by `format-patch`). Note that
152+
by setting this, the receiver of any patches you generate will
153+
have to apply them using the `-p0` option.

builtin/log.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static int stdout_mboxrd;
5656
static const char *fmt_patch_subject_prefix = "PATCH";
5757
static int fmt_patch_name_max = FORMAT_PATCH_NAME_MAX_DEFAULT;
5858
static const char *fmt_pretty;
59+
static int format_no_prefix;
5960

6061
static const char * const builtin_log_usage[] = {
6162
N_("git log [<options>] [<revision-range>] [[--] <path>...]"),
@@ -1084,6 +1085,10 @@ static int git_format_config(const char *var, const char *value, void *cb)
10841085
stdout_mboxrd = git_config_bool(var, value);
10851086
return 0;
10861087
}
1088+
if (!strcmp(var, "format.noprefix")) {
1089+
format_no_prefix = 1;
1090+
return 0;
1091+
}
10871092

10881093
/*
10891094
* 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)
20022007
s_r_opt.def = "HEAD";
20032008
s_r_opt.revarg_opt = REVARG_COMMITTISH;
20042009

2010+
if (format_no_prefix)
2011+
diff_set_noprefix(&rev.diffopt);
2012+
20052013
if (default_attach) {
20062014
rev.mime_boundary = default_attach;
20072015
rev.no_inline = 1;

t/t4014-format-patch.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,4 +2391,15 @@ test_expect_success 'format-patch does not respect diff.noprefix' '
23912391
grep "^--- a/blorp" actual
23922392
'
23932393

2394+
test_expect_success 'format-patch respects format.noprefix' '
2395+
git -c format.noprefix format-patch -1 --stdout >actual &&
2396+
grep "^--- blorp" actual
2397+
'
2398+
2399+
test_expect_success 'format-patch --default-prefix overrides format.noprefix' '
2400+
git -c format.noprefix \
2401+
format-patch -1 --default-prefix --stdout >actual &&
2402+
grep "^--- a/blorp" actual
2403+
'
2404+
23942405
test_done

0 commit comments

Comments
 (0)