{"thread":{"id":"41001","subject":"[PATCH v3 1/3] Introduce a null_oid constant.","startedAt":"2015-12-15T01:52:02Z","lastAt":"2015-12-15T01:52:05Z","messageCount":4,"participants":["brian m. carlson"],"isPatch":true,"patchVersion":3,"patchTotal":3},"messages":[{"id":"274478","messageId":"1450144325-182108-1-git-send-email-sandals@crustytoothpaste.net","threadId":"41001","inReplyTo":null,"subject":"[PATCH v3 0/3] format-patch: introduce option to suppress commit hashes","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-12-15T01:52:02Z","receivedAt":"2015-12-15T01:52:02Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"git format-patch is often used to create patches that are then stored in\nversion control or displayed with diff.  Having the commit hash in the\n\"From \" line usually just creates diff noise in these cases, so this\nseries introduces --zero-commit to set that to all zeros.\n\nChanges from v2:\n* Improve the tests to be more idiomatic and avoid hard-coding line\n  counts.\n\nbrian m. carlson (3):\n  Introduce a null_oid constant.\n  format-patch: add an option to suppress commit hash\n  format-patch: check that header line has expected format\n\n Documentation/git-format-patch.txt |  4 ++++\n builtin/log.c                      |  5 +++++\n cache.h                            |  1 +\n log-tree.c                         |  3 ++-\n revision.h                         |  1 +\n sha1_file.c                        |  1 +\n t/t4014-format-patch.sh            | 14 ++++++++++++++\n 7 files changed, 28 insertions(+), 1 deletion(-)\n\n-- \n2.7.0.rc0.194.g1187e4e.dirty\n"},{"id":"274476","messageId":"1450144325-182108-2-git-send-email-sandals@crustytoothpaste.net","threadId":"41001","inReplyTo":"1450144325-182108-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v3 1/3] Introduce a null_oid constant.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-12-15T01:52:03Z","receivedAt":"2015-12-15T01:52:03Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"null_oid is the struct object_id equivalent to null_sha1.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h     | 1 +\n sha1_file.c | 1 +\n 2 files changed, 2 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex 5ab6cb50..c63fcc11 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -831,6 +831,7 @@ extern const char *find_unique_abbrev(const unsigned char *sha1, int len);\n extern int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len);\n \n extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];\n+extern const struct object_id null_oid;\n \n static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)\n {\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 27ce7b70..a54deb05 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -36,6 +36,7 @@\n static inline uintmax_t sz_fmt(size_t s) { return s; }\n \n const unsigned char null_sha1[20];\n+const struct object_id null_oid;\n \n /*\n  * This is meant to hold a *small* number of objects that you would\n-- \n2.7.0.rc0.194.g1187e4e.dirty\n"},{"id":"274477","messageId":"1450144325-182108-3-git-send-email-sandals@crustytoothpaste.net","threadId":"41001","inReplyTo":"1450144325-182108-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v3 2/3] format-patch: add an option to suppress commit hash","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-12-15T01:52:04Z","receivedAt":"2015-12-15T01:52:04Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Oftentimes, patches created by git format-patch will be stored in\nversion control or compared with diff.  In these cases, two otherwise\nidentical patches can have different commit hashes, leading to diff\nnoise.  Teach git format-patch a --zero-commit option that instead\nproduces an all-zero hash to avoid this diff noise.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n Documentation/git-format-patch.txt | 4 ++++\n builtin/log.c                      | 5 +++++\n log-tree.c                         | 3 ++-\n revision.h                         | 1 +\n t/t4014-format-patch.sh            | 7 +++++++\n 5 files changed, 19 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex 40356491..e3cdaeb9 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -256,6 +256,10 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.\n \tusing this option cannot be applied properly, but they are\n \tstill useful for code review.\n \n+--zero-commit::\n+  Output an all-zero hash in each patch's From header instead\n+  of the hash of the commit.\n+\n --root::\n \tTreat the revision argument as a <revision range>, even if it\n \tis just a single commit (that would normally be treated as a\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 069bd3a9..e00cea75 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1196,6 +1196,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \tint cover_letter = -1;\n \tint boundary_count = 0;\n \tint no_binary_diff = 0;\n+\tint zero_commit = 0;\n \tstruct commit *origin = NULL;\n \tconst char *in_reply_to = NULL;\n \tstruct patch_ids ids;\n@@ -1236,6 +1237,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t    PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback },\n \t\tOPT_BOOL(0, \"no-binary\", &no_binary_diff,\n \t\t\t N_(\"don't output binary diffs\")),\n+\t\tOPT_BOOL(0, \"zero-commit\", &zero_commit,\n+\t\t\t N_(\"output all-zero hash in From header\")),\n \t\tOPT_BOOL(0, \"ignore-if-in-upstream\", &ignore_if_in_upstream,\n \t\t\t N_(\"don't include a patch matching a commit upstream\")),\n \t\t{ OPTION_SET_INT, 'p', \"no-stat\", &use_patch_format, NULL,\n@@ -1380,6 +1383,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t/* Always generate a patch */\n \trev.diffopt.output_format |= DIFF_FORMAT_PATCH;\n \n+\trev.zero_commit = zero_commit;\n+\n \tif (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)\n \t\tDIFF_OPT_SET(&rev.diffopt, BINARY);\n \ndiff --git a/log-tree.c b/log-tree.c\nindex 35e78017..f70a30e1 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -342,7 +342,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n {\n \tconst char *subject = NULL;\n \tconst char *extra_headers = opt->extra_headers;\n-\tconst char *name = oid_to_hex(&commit->object.oid);\n+\tconst char *name = oid_to_hex(opt->zero_commit ?\n+\t\t\t\t      &null_oid : &commit->object.oid);\n \n \t*need_8bit_cte_p = 0; /* unknown */\n \tif (opt->total > 0) {\ndiff --git a/revision.h b/revision.h\nindex 5bc96868..23857c0e 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -135,6 +135,7 @@ struct rev_info {\n \t\t\tpretty_given:1,\n \t\t\tabbrev_commit:1,\n \t\t\tabbrev_commit_given:1,\n+\t\t\tzero_commit:1,\n \t\t\tuse_terminator:1,\n \t\t\tmissing_newline:1,\n \t\t\tdate_mode_explicit:1,\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 890db117..2737ca63 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1431,4 +1431,11 @@ test_expect_success 'cover letter auto user override' '\n \ttest_line_count = 2 list\n '\n \n+test_expect_success 'format-patch --zero-commit' '\n+\tgit format-patch --zero-commit --stdout v2..v1 >patch2 &&\n+\tgrep \"^From \" patch2 | sort | uniq >actual &&\n+\techo \"From $_z40 Mon Sep 17 00:00:00 2001\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.7.0.rc0.194.g1187e4e.dirty\n"},{"id":"274479","messageId":"1450144325-182108-4-git-send-email-sandals@crustytoothpaste.net","threadId":"41001","inReplyTo":"1450144325-182108-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v3 3/3] format-patch: check that header line has expected format","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-12-15T01:52:05Z","receivedAt":"2015-12-15T01:52:05Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"The format of the \"From \" header line is very specific to allow\nutilities to detect Git-style patches.  Add a test that the patches\ncreated are in the expected format.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n t/t4014-format-patch.sh | 7 +++++++\n 1 file changed, 7 insertions(+)\n\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 2737ca63..646c4750 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1438,4 +1438,11 @@ test_expect_success 'format-patch --zero-commit' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'From line has expected format' '\n+\tgit format-patch --stdout v2..v1 >patch2 &&\n+\tgrep \"^From \" patch2 >from &&\n+\tgrep \"^From $_x40 Mon Sep 17 00:00:00 2001$\" patch2 >filtered &&\n+\ttest_cmp from filtered\n+'\n+\n test_done\n-- \n2.7.0.rc0.194.g1187e4e.dirty\n"}]}