format-patch: add an option to suppress commit hash
Oftentimes, patches created by git format-patch will be stored in version control or compared with diff. In these cases, two otherwise identical patches can have different commit hashes, leading to diff noise. Teach git format-patch a --zero-commit option that instead produces an all-zero hash to avoid this diff noise. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Dec 15, 2015 at 01:52 UTC
3a30aa17879b08f96262abb9a22c7bbe8f56e4c9
5 files changed
+19
-1
Documentation/git-format-patch.txt
+4
@@ -256,6 +256,10 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
256
using this option cannot be applied properly, but they are
257
still useful for code review.
258
259
+--zero-commit::
260
+ Output an all-zero hash in each patch's From header instead
261
+ of the hash of the commit.
262
+
263
--root::
264
Treat the revision argument as a <revision range>, even if it
265
is just a single commit (that would normally be treated as a
builtin/log.c
+5
@@ -1196,6 +1196,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1196
int cover_letter = -1;
1197
int boundary_count = 0;
1198
int no_binary_diff = 0;
1199
+ int zero_commit = 0;
1200
struct commit *origin = NULL;
1201
const char *in_reply_to = NULL;
1202
struct patch_ids ids;
@@ -1236,6 +1237,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1237
PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback },
1238
OPT_BOOL(0, "no-binary", &no_binary_diff,
1239
N_("don't output binary diffs")),
1240
+ OPT_BOOL(0, "zero-commit", &zero_commit,
1241
+ N_("output all-zero hash in From header")),
1242
OPT_BOOL(0, "ignore-if-in-upstream", &ignore_if_in_upstream,
1243
N_("don't include a patch matching a commit upstream")),
1244
{ OPTION_SET_INT, 'p', "no-stat", &use_patch_format, NULL,
@@ -1380,6 +1383,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1383
/* Always generate a patch */
1384
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
1385
1386
+ rev.zero_commit = zero_commit;
1387
+
1388
if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
1389
DIFF_OPT_SET(&rev.diffopt, BINARY);
1390
log-tree.c
+2
-1
@@ -342,7 +342,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
342
{
343
const char *subject = NULL;
344
const char *extra_headers = opt->extra_headers;
345
- const char *name = oid_to_hex(&commit->object.oid);
345
+ const char *name = oid_to_hex(opt->zero_commit ?
346
+ &null_oid : &commit->object.oid);
347
348
*need_8bit_cte_p = 0; /* unknown */
349
if (opt->total > 0) {
revision.h
+1
@@ -135,6 +135,7 @@ struct rev_info {
135
pretty_given:1,
136
abbrev_commit:1,
137
abbrev_commit_given:1,
138
+ zero_commit:1,
139
use_terminator:1,
140
missing_newline:1,
141
date_mode_explicit:1,
t/t4014-format-patch.sh
+7
@@ -1431,4 +1431,11 @@ test_expect_success 'cover letter auto user override' '
1431
test_line_count = 2 list
1432
'
1433
1434
+test_expect_success 'format-patch --zero-commit' '
1435
+ git format-patch --zero-commit --stdout v2..v1 >patch2 &&
1436
+ grep "^From " patch2 | sort | uniq >actual &&
1437
+ echo "From $_z40 Mon Sep 17 00:00:00 2001" >expect &&
1438
+ test_cmp expect actual
1439
+'
1440
+
1441
test_done