Skip to content

Commit fbe959d

Browse files
committed
Merge branch 'bc/format-patch-null-from-line'
"format-patch" has learned a new option to zero-out the commit object name on the mbox "From " line. * bc/format-patch-null-from-line: format-patch: check that header line has expected format format-patch: add an option to suppress commit hash sha1_file.c: introduce a null_oid constant
2 parents 5498c57 + 06dfc9e commit fbe959d

File tree

7 files changed

+28
-1
lines changed

7 files changed

+28
-1
lines changed

Documentation/git-format-patch.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
256256
using this option cannot be applied properly, but they are
257257
still useful for code review.
258258

259+
--zero-commit::
260+
Output an all-zero hash in each patch's From header instead
261+
of the hash of the commit.
262+
259263
--root::
260264
Treat the revision argument as a <revision range>, even if it
261265
is just a single commit (that would normally be treated as a

builtin/log.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
11961196
int cover_letter = -1;
11971197
int boundary_count = 0;
11981198
int no_binary_diff = 0;
1199+
int zero_commit = 0;
11991200
struct commit *origin = NULL;
12001201
const char *in_reply_to = NULL;
12011202
struct patch_ids ids;
@@ -1236,6 +1237,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
12361237
PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback },
12371238
OPT_BOOL(0, "no-binary", &no_binary_diff,
12381239
N_("don't output binary diffs")),
1240+
OPT_BOOL(0, "zero-commit", &zero_commit,
1241+
N_("output all-zero hash in From header")),
12391242
OPT_BOOL(0, "ignore-if-in-upstream", &ignore_if_in_upstream,
12401243
N_("don't include a patch matching a commit upstream")),
12411244
{ 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)
13801383
/* Always generate a patch */
13811384
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
13821385

1386+
rev.zero_commit = zero_commit;
1387+
13831388
if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
13841389
DIFF_OPT_SET(&rev.diffopt, BINARY);
13851390

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ extern const char *find_unique_abbrev(const unsigned char *sha1, int len);
831831
extern int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len);
832832

833833
extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];
834+
extern const struct object_id null_oid;
834835

835836
static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
836837
{

log-tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
342342
{
343343
const char *subject = NULL;
344344
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);
346347

347348
*need_8bit_cte_p = 0; /* unknown */
348349
if (opt->total > 0) {

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct rev_info {
135135
pretty_given:1,
136136
abbrev_commit:1,
137137
abbrev_commit_given:1,
138+
zero_commit:1,
138139
use_terminator:1,
139140
missing_newline:1,
140141
date_mode_explicit:1,

sha1_file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
static inline uintmax_t sz_fmt(size_t s) { return s; }
3737

3838
const unsigned char null_sha1[20];
39+
const struct object_id null_oid;
3940

4041
/*
4142
* This is meant to hold a *small* number of objects that you would

t/t4014-format-patch.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,4 +1431,18 @@ test_expect_success 'cover letter auto user override' '
14311431
test_line_count = 2 list
14321432
'
14331433

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_expect_success 'From line has expected format' '
1442+
git format-patch --stdout v2..v1 >patch2 &&
1443+
grep "^From " patch2 >from &&
1444+
grep "^From $_x40 Mon Sep 17 00:00:00 2001$" patch2 >filtered &&
1445+
test_cmp from filtered
1446+
'
1447+
14341448
test_done

0 commit comments

Comments
 (0)