Skip to content

Commit 1a02a85

Browse files
committed
Merge branch 'bg/format-patch-doc-update'
* bg/format-patch-doc-update: format-patch: Add "--no-stat" as a synonym for "-p" format-patch documentation: Fix formatting format-patch documentation: Remove diff options that are not useful format-patch: Always generate a patch
2 parents aa43779 + 2cfa833 commit 1a02a85

File tree

4 files changed

+99
-50
lines changed

4 files changed

+99
-50
lines changed

Documentation/diff-options.txt

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ endif::git-format-patch[]
1414

1515
ifdef::git-format-patch[]
1616
-p::
17-
Generate patches without diffstat.
17+
--no-stat::
18+
Generate plain patches without any diffstats.
1819
endif::git-format-patch[]
1920

2021
ifndef::git-format-patch[]
@@ -27,58 +28,67 @@ endif::git-format-patch[]
2728
-U<n>::
2829
--unified=<n>::
2930
Generate diffs with <n> lines of context instead of
30-
the usual three. Implies "-p".
31+
the usual three.
32+
ifndef::git-format-patch[]
33+
Implies `-p`.
34+
endif::git-format-patch[]
3135

36+
ifndef::git-format-patch[]
3237
--raw::
3338
Generate the raw format.
3439
{git-diff-core? This is the default.}
40+
endif::git-format-patch[]
3541

42+
ifndef::git-format-patch[]
3643
--patch-with-raw::
37-
Synonym for "-p --raw".
44+
Synonym for `-p --raw`.
45+
endif::git-format-patch[]
3846

3947
--patience::
4048
Generate a diff using the "patience diff" algorithm.
4149

4250
--stat[=width[,name-width]]::
4351
Generate a diffstat. You can override the default
44-
output width for 80-column terminal by "--stat=width".
52+
output width for 80-column terminal by `--stat=width`.
4553
The width of the filename part can be controlled by
4654
giving another width to it separated by a comma.
4755

4856
--numstat::
49-
Similar to \--stat, but shows number of added and
57+
Similar to `\--stat`, but shows number of added and
5058
deleted lines in decimal notation and pathname without
5159
abbreviation, to make it more machine friendly. For
5260
binary files, outputs two `-` instead of saying
5361
`0 0`.
5462

5563
--shortstat::
56-
Output only the last line of the --stat format containing total
64+
Output only the last line of the `--stat` format containing total
5765
number of modified files, as well as number of added and deleted
5866
lines.
5967

6068
--dirstat[=limit]::
6169
Output the distribution of relative amount of changes (number of lines added or
6270
removed) for each sub-directory. Directories with changes below
6371
a cut-off percent (3% by default) are not shown. The cut-off percent
64-
can be set with "--dirstat=limit". Changes in a child directory is not
65-
counted for the parent directory, unless "--cumulative" is used.
72+
can be set with `--dirstat=limit`. Changes in a child directory is not
73+
counted for the parent directory, unless `--cumulative` is used.
6674

6775
--dirstat-by-file[=limit]::
68-
Same as --dirstat, but counts changed files instead of lines.
76+
Same as `--dirstat`, but counts changed files instead of lines.
6977

7078
--summary::
7179
Output a condensed summary of extended header information
7280
such as creations, renames and mode changes.
7381

82+
ifndef::git-format-patch[]
7483
--patch-with-stat::
75-
Synonym for "-p --stat".
76-
{git-format-patch? This is the default.}
84+
Synonym for `-p --stat`.
85+
endif::git-format-patch[]
7786

87+
ifndef::git-format-patch[]
7888
-z::
79-
NUL-line termination on output. This affects the --raw
89+
NUL-line termination on output. This affects the `--raw`
8090
output field terminator. Also output from commands such
81-
as "git-log" will be delimited with NUL between commits.
91+
as `git-log` will be delimited with NUL between commits.
8292

8393
--name-only::
8494
Show only names of changed files.
@@ -117,33 +127,36 @@ The regex can also be set via a diff driver or configuration option, see
117127
linkgit:gitattributes[1] or linkgit:git-config[1]. Giving it explicitly
118128
overrides any diff driver or configuration setting. Diff drivers
119129
override configuration settings.
130+
endif::git-format-patch[]
120131

121132
--no-renames::
122133
Turn off rename detection, even when the configuration
123134
file gives the default to do so.
124135

136+
ifndef::git-format-patch[]
125137
--check::
126138
Warn if changes introduce trailing whitespace
127139
or an indent that uses a space before a tab. Exits with
128140
non-zero status if problems are found. Not compatible with
129141
--exit-code.
142+
endif::git-format-patch[]
130143

131144
--full-index::
132145
Instead of the first handful of characters, show the full
133146
pre- and post-image blob object names on the "index"
134147
line when generating patch format output.
135148

136149
--binary::
137-
In addition to --full-index, output "binary diff" that
138-
can be applied with "git apply".
150+
In addition to `--full-index`, output a binary diff that
151+
can be applied with `git-apply`.
139152

140153
--abbrev[=<n>]::
141154
Instead of showing the full 40-byte hexadecimal object
142155
name in diff-raw format output and diff-tree header
143156
lines, show only a partial prefix. This is
144-
independent of --full-index option above, which controls
157+
independent of the `--full-index` option above, which controls
145158
the diff-patch output format. Non default number of
146-
digits can be specified with --abbrev=<n>.
159+
digits can be specified with `--abbrev=<n>`.
147160

148161
-B::
149162
Break complete rewrite changes into pairs of delete and create.
@@ -154,6 +167,7 @@ override configuration settings.
154167
-C::
155168
Detect copies as well as renames. See also `--find-copies-harder`.
156169

170+
ifndef::git-format-patch[]
157171
--diff-filter=[ACDMRTUXB*]::
158172
Select only files that are Added (`A`), Copied (`C`),
159173
Deleted (`D`), Modified (`M`), Renamed (`R`), have their
@@ -165,6 +179,7 @@ override configuration settings.
165179
paths are selected if there is any file that matches
166180
other criteria in the comparison; if there is no file
167181
that matches other criteria, nothing is selected.
182+
endif::git-format-patch[]
168183

169184
--find-copies-harder::
170185
For performance reasons, by default, `-C` option finds copies only
@@ -176,31 +191,34 @@ override configuration settings.
176191
`-C` option has the same effect.
177192

178193
-l<num>::
179-
-M and -C options require O(n^2) processing time where n
194+
The `-M` and `-C` options require O(n^2) processing time where n
180195
is the number of potential rename/copy targets. This
181196
option prevents rename/copy detection from running if
182197
the number of rename/copy targets exceeds the specified
183198
number.
184199

200+
ifndef::git-format-patch[]
185201
-S<string>::
186202
Look for differences that introduce or remove an instance of
187203
<string>. Note that this is different than the string simply
188204
appearing in diff output; see the 'pickaxe' entry in
189205
linkgit:gitdiffcore[7] for more details.
190206

191207
--pickaxe-all::
192-
When -S finds a change, show all the changes in that
208+
When `-S` finds a change, show all the changes in that
193209
changeset, not just the files that contain the change
194210
in <string>.
195211

196212
--pickaxe-regex::
197213
Make the <string> not a plain string but an extended POSIX
198214
regex to match.
215+
endif::git-format-patch[]
199216

200217
-O<orderfile>::
201218
Output the patch in the order specified in the
202219
<orderfile>, which has one shell glob pattern per line.
203220

221+
ifndef::git-format-patch[]
204222
-R::
205223
Swap two inputs; that is, show differences from index or
206224
on-disk file to tree contents.
@@ -212,6 +230,7 @@ override configuration settings.
212230
not in a subdirectory (e.g. in a bare repository), you
213231
can name which subdirectory to make the output relative
214232
to by giving a <path> as an argument.
233+
endif::git-format-patch[]
215234

216235
-a::
217236
--text::
@@ -236,13 +255,15 @@ override configuration settings.
236255
Show the context between diff hunks, up to the specified number
237256
of lines, thereby fusing hunks that are close to each other.
238257

258+
ifndef::git-format-patch[]
239259
--exit-code::
240260
Make the program exit with codes similar to diff(1).
241261
That is, it exits with 1 if there were differences and
242262
0 means no differences.
243263

244264
--quiet::
245-
Disable all output of the program. Implies --exit-code.
265+
Disable all output of the program. Implies `--exit-code`.
266+
endif::git-format-patch[]
246267

247268
--ext-diff::
248269
Allow an external diff helper to be executed. If you set an

Documentation/git-format-patch.txt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,28 @@ There are two ways to specify which commits to operate on.
4343

4444
The first rule takes precedence in the case of a single <commit>. To
4545
apply the second rule, i.e., format everything since the beginning of
46-
history up until <commit>, use the '\--root' option: "git format-patch
47-
\--root <commit>". If you want to format only <commit> itself, you
48-
can do this with "git format-patch -1 <commit>".
46+
history up until <commit>, use the '\--root' option: `git format-patch
47+
\--root <commit>`. If you want to format only <commit> itself, you
48+
can do this with `git format-patch -1 <commit>`.
4949

5050
By default, each output file is numbered sequentially from 1, and uses the
5151
first line of the commit message (massaged for pathname safety) as
52-
the filename. With the --numbered-files option, the output file names
52+
the filename. With the `--numbered-files` option, the output file names
5353
will only be numbers, without the first line of the commit appended.
5454
The names of the output files are printed to standard
55-
output, unless the --stdout option is specified.
55+
output, unless the `--stdout` option is specified.
5656

57-
If -o is specified, output files are created in <dir>. Otherwise
57+
If `-o` is specified, output files are created in <dir>. Otherwise
5858
they are created in the current working directory.
5959

6060
By default, the subject of a single patch is "[PATCH] First Line" and
6161
the subject when multiple patches are output is "[PATCH n/m] First
62-
Line". To force 1/1 to be added for a single patch, use -n. To omit
63-
patch numbers from the subject, use -N
62+
Line". To force 1/1 to be added for a single patch, use `-n`. To omit
63+
patch numbers from the subject, use `-N`.
6464

65-
If given --thread, 'git-format-patch' will generate In-Reply-To and
66-
References headers to make the second and subsequent patch mails appear
67-
as replies to the first mail; this also generates a Message-Id header to
65+
If given `--thread`, `git-format-patch` will generate `In-Reply-To` and
66+
`References` headers to make the second and subsequent patch mails appear
67+
as replies to the first mail; this also generates a `Message-Id` header to
6868
reference.
6969

7070
OPTIONS
@@ -112,7 +112,7 @@ include::diff-options.txt[]
112112
--attach[=<boundary>]::
113113
Create multipart/mixed attachment, the first part of
114114
which is the commit message and the patch itself in the
115-
second part, with "Content-Disposition: attachment".
115+
second part, with `Content-Disposition: attachment`.
116116

117117
--no-attach::
118118
Disable the creation of an attachment, overriding the
@@ -121,13 +121,13 @@ include::diff-options.txt[]
121121
--inline[=<boundary>]::
122122
Create multipart/mixed attachment, the first part of
123123
which is the commit message and the patch itself in the
124-
second part, with "Content-Disposition: inline".
124+
second part, with `Content-Disposition: inline`.
125125

126126
--thread[=<style>]::
127127
--no-thread::
128-
Controls addition of In-Reply-To and References headers to
128+
Controls addition of `In-Reply-To` and `References` headers to
129129
make the second and subsequent mails appear as replies to the
130-
first. Also controls generation of the Message-Id header to
130+
first. Also controls generation of the `Message-Id` header to
131131
reference.
132132
+
133133
The optional <style> argument can be either `shallow` or `deep`.
@@ -136,16 +136,16 @@ series, where the head is chosen from the cover letter, the
136136
`\--in-reply-to`, and the first patch mail, in this order. 'deep'
137137
threading makes every mail a reply to the previous one.
138138
+
139-
The default is --no-thread, unless the 'format.thread' configuration
140-
is set. If --thread is specified without a style, it defaults to the
139+
The default is `--no-thread`, unless the 'format.thread' configuration
140+
is set. If `--thread` is specified without a style, it defaults to the
141141
style specified by 'format.thread' if any, or else `shallow`.
142142
+
143143
Beware that the default for 'git send-email' is to thread emails
144-
itself. If you want 'git format-patch' to take care of hreading, you
145-
will want to ensure that threading is disabled for 'git send-email'.
144+
itself. If you want `git format-patch` to take care of threading, you
145+
will want to ensure that threading is disabled for `git send-email`.
146146

147147
--in-reply-to=Message-Id::
148-
Make the first mail (or all the mails with --no-thread) appear as a
148+
Make the first mail (or all the mails with `--no-thread`) appear as a
149149
reply to the given Message-Id, which avoids breaking threads to
150150
provide a new patch series.
151151

@@ -160,16 +160,16 @@ will want to ensure that threading is disabled for 'git send-email'.
160160
Instead of the standard '[PATCH]' prefix in the subject
161161
line, instead use '[<Subject-Prefix>]'. This
162162
allows for useful naming of a patch series, and can be
163-
combined with the --numbered option.
163+
combined with the `--numbered` option.
164164

165165
--cc=<email>::
166-
Add a "Cc:" header to the email headers. This is in addition
166+
Add a `Cc:` header to the email headers. This is in addition
167167
to any configured headers, and may be used multiple times.
168168

169169
--add-header=<header>::
170170
Add an arbitrary header to the email headers. This is in addition
171171
to any configured headers, and may be used multiple times.
172-
For example, --add-header="Organization: git-foo"
172+
For example, `--add-header="Organization: git-foo"`
173173

174174
--cover-letter::
175175
In addition to the patches, generate a cover letter file

builtin-log.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
927927
PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback },
928928
OPT_BOOLEAN(0, "no-binary", &no_binary_diff,
929929
"don't output binary diffs"),
930-
OPT_BOOLEAN('p', NULL, &use_patch_format,
931-
"show patch format instead of default (patch + stat)"),
932930
OPT_BOOLEAN(0, "ignore-if-in-upstream", &ignore_if_in_upstream,
933931
"don't include a patch matching a commit upstream"),
932+
{ OPTION_BOOLEAN, 'p', "no-stat", &use_patch_format, NULL,
933+
"show patch format instead of default (patch + stat)",
934+
PARSE_OPT_NONEG | PARSE_OPT_NOARG },
934935
OPT_GROUP("Messaging"),
935936
{ OPTION_CALLBACK, 0, "add-header", NULL, "header",
936937
"add email header", PARSE_OPT_NONEG,
@@ -1036,11 +1037,20 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
10361037
if (argc > 1)
10371038
die ("unrecognized argument: %s", argv[1]);
10381039

1039-
if (use_patch_format)
1040-
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
1041-
else if (!rev.diffopt.output_format ||
1042-
rev.diffopt.output_format == DIFF_FORMAT_PATCH)
1043-
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;
1040+
if (rev.diffopt.output_format & DIFF_FORMAT_NAME)
1041+
die("--name-only does not make sense");
1042+
if (rev.diffopt.output_format & DIFF_FORMAT_NAME_STATUS)
1043+
die("--name-status does not make sense");
1044+
if (rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)
1045+
die("--check does not make sense");
1046+
1047+
if (!use_patch_format &&
1048+
(!rev.diffopt.output_format ||
1049+
rev.diffopt.output_format == DIFF_FORMAT_PATCH))
1050+
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY;
1051+
1052+
/* Always generate a patch */
1053+
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
10441054

10451055
if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
10461056
DIFF_OPT_SET(&rev.diffopt, BINARY);

t/t4014-format-patch.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,4 +536,22 @@ test_expect_success 'format-patch --signoff' '
536536
grep "^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
537537
'
538538

539+
echo "fatal: --name-only does not make sense" > expect.name-only
540+
echo "fatal: --name-status does not make sense" > expect.name-status
541+
echo "fatal: --check does not make sense" > expect.check
542+
543+
test_expect_success 'options no longer allowed for format-patch' '
544+
test_must_fail git format-patch --name-only 2> output &&
545+
test_cmp expect.name-only output &&
546+
test_must_fail git format-patch --name-status 2> output &&
547+
test_cmp expect.name-status output &&
548+
test_must_fail git format-patch --check 2> output &&
549+
test_cmp expect.check output'
550+
551+
test_expect_success 'format-patch --numstat should produce a patch' '
552+
git format-patch --numstat --stdout master..side |
553+
grep "^diff --git a/" |
554+
wc -l |
555+
xargs test 6 = '
556+
539557
test_done

0 commit comments

Comments
 (0)