Merge branch 'bc/format-patch-null-from-line'
authorJunio C Hamano <gitster@pobox.com>
Mon, 21 Dec 2015 18:59:07 +0000 (10:59 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Dec 2015 18:59:08 +0000 (10:59 -0800)
"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

Documentation/git-format-patch.txt
builtin/log.c
cache.h
log-tree.c
revision.h
sha1_file.c
t/t4014-format-patch.sh
index 4035649117f594b7262dced2d387401d2d596ad6..e3cdaeb9586017aa86aa15fec8a13371993906e3 100644 (file)
@@ -256,6 +256,10 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
        using this option cannot be applied properly, but they are
        still useful for code review.
 
+--zero-commit::
+  Output an all-zero hash in each patch's From header instead
+  of the hash of the commit.
+
 --root::
        Treat the revision argument as a <revision range>, even if it
        is just a single commit (that would normally be treated as a
index 069bd3a909045af432213b21eb4b98bdd29a3443..e00cea75cca8bbde28ba45359c28b5a13a1b75e7 100644 (file)
@@ -1196,6 +1196,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        int cover_letter = -1;
        int boundary_count = 0;
        int no_binary_diff = 0;
+       int zero_commit = 0;
        struct commit *origin = NULL;
        const char *in_reply_to = NULL;
        struct patch_ids ids;
@@ -1236,6 +1237,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                            PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback },
                OPT_BOOL(0, "no-binary", &no_binary_diff,
                         N_("don't output binary diffs")),
+               OPT_BOOL(0, "zero-commit", &zero_commit,
+                        N_("output all-zero hash in From header")),
                OPT_BOOL(0, "ignore-if-in-upstream", &ignore_if_in_upstream,
                         N_("don't include a patch matching a commit upstream")),
                { 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)
        /* Always generate a patch */
        rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
 
+       rev.zero_commit = zero_commit;
+
        if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
                DIFF_OPT_SET(&rev.diffopt, BINARY);
 
diff --git a/cache.h b/cache.h
index 5ab6cb50a61e24dc418b351db8acc648b740c244..c63fcc113a6e511a53f0170a07bd5dbbf12cc120 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -831,6 +831,7 @@ extern const char *find_unique_abbrev(const unsigned char *sha1, int len);
 extern int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len);
 
 extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];
+extern const struct object_id null_oid;
 
 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
 {
index 35e780170a2529cf528f4edfcd6bac9dcab5591f..f70a30e12702fa68c77f6b2490692f3861ad32e7 100644 (file)
@@ -342,7 +342,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 {
        const char *subject = NULL;
        const char *extra_headers = opt->extra_headers;
-       const char *name = oid_to_hex(&commit->object.oid);
+       const char *name = oid_to_hex(opt->zero_commit ?
+                                     &null_oid : &commit->object.oid);
 
        *need_8bit_cte_p = 0; /* unknown */
        if (opt->total > 0) {
index 5bc9686846045182c3d2393a98e3018df2f05af4..23857c0ed1d7a304c848842711a920e678fd506d 100644 (file)
@@ -135,6 +135,7 @@ struct rev_info {
                        pretty_given:1,
                        abbrev_commit:1,
                        abbrev_commit_given:1,
+                       zero_commit:1,
                        use_terminator:1,
                        missing_newline:1,
                        date_mode_explicit:1,
index 2c68766ebf0cab5f13f684ac3e26061b93bda44a..73ccd49a465b1cf8b668edf8c13ea75d6b8de718 100644 (file)
@@ -36,6 +36,7 @@
 static inline uintmax_t sz_fmt(size_t s) { return s; }
 
 const unsigned char null_sha1[20];
+const struct object_id null_oid;
 
 /*
  * This is meant to hold a *small* number of objects that you would
index 890db1174f75172ee6b342e26cbbc58e3e4cd03f..646c4750ec6d3003379da34ee29f247d45cf5b57 100755 (executable)
@@ -1431,4 +1431,18 @@ test_expect_success 'cover letter auto user override' '
        test_line_count = 2 list
 '
 
+test_expect_success 'format-patch --zero-commit' '
+       git format-patch --zero-commit --stdout v2..v1 >patch2 &&
+       grep "^From " patch2 | sort | uniq >actual &&
+       echo "From $_z40 Mon Sep 17 00:00:00 2001" >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'From line has expected format' '
+       git format-patch --stdout v2..v1 >patch2 &&
+       grep "^From " patch2 >from &&
+       grep "^From $_x40 Mon Sep 17 00:00:00 2001$" patch2 >filtered &&
+       test_cmp from filtered
+'
+
 test_done