{"thread":{"id":"36747","subject":"[PATCH v9 0/2] format-patch --signature-file=<file>","startedAt":"2014-05-24T04:08:12Z","lastAt":"2014-05-24T04:08:14Z","messageCount":3,"participants":["Jeremiah Mahler"],"isPatch":true,"patchVersion":9,"patchTotal":2},"messages":[{"id":"242632","messageId":"cover.1400904004.git.jmmahler@gmail.com","threadId":"36747","inReplyTo":null,"subject":"[PATCH v9 0/2] format-patch --signature-file=<file>","fromName":"Jeremiah Mahler","fromEmail":"jmmahler@gmail.com","sentAt":"2014-05-24T04:08:12Z","receivedAt":"2014-05-24T04:08:12Z","isPatch":true,"sender":{"key":"jmmahler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/154028?v=4"},"body":"v9 of patch to add format-patch --signature-file <file> option.\n\nThis revision includes more suggestions from Junio C Hamano.\n\n  - Reworded patch description.  Using \"special characters\" is\n\tnot a feature of this patch.\n\n  - Changed patch description to follow gitcli(7) guidlines.\n    \"--signature-file=name\" instead of \"--signature-file name\"\n\n  - Reduced set of crucial test cases.\n\n    --signature-file works\n\n    format.signaturefile works\n\n    --no-signature suppresses format.signaturefile\n\n    --signature-file overrides format.signaturefile\n\n    --signature overrides format.signaturefile\n\n  - Note, the control logic had to be re-worked to satisfy these test cases.\n\n\nJeff King (1):\n  format-patch: make newline after signature conditional\n\nJeremiah Mahler (1):\n  format-patch --signature-file=<file>\n\n Documentation/config.txt           |  4 +++\n Documentation/git-format-patch.txt |  4 +++\n builtin/log.c                      | 26 ++++++++++++++--\n t/t4014-format-patch.sh            | 61 ++++++++++++++++++++++++++++++++++++++\n 4 files changed, 93 insertions(+), 2 deletions(-)\n\n-- \nJeremiah Mahler\njmmahler@gmail.com\nhttp://github.com/jmahler\n"},{"id":"242633","messageId":"d74db966b42529b7d222745b2950e97ba5f46822.1400904004.git.jmmahler@gmail.com","threadId":"36747","inReplyTo":"cover.1400904004.git.jmmahler@gmail.com","subject":"[PATCH v9 1/2] format-patch: make newline after signature conditional","fromName":"Jeremiah Mahler","fromEmail":"jmmahler@gmail.com","sentAt":"2014-05-24T04:08:13Z","receivedAt":"2014-05-24T04:08:13Z","isPatch":true,"sender":{"key":"jmmahler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/154028?v=4"},"body":"From: Jeff King <peff@peff.net>\n\nWhen we print an email signature, we print the divider \"--\n\\n\", then the signature string, then two newlines.\nTraditionally the signature is a one-liner (and the default\nis just the git version), so the extra newline makes sense.\n\nBut one could easily specify a longer, multi-line signature,\nlike:\n\n  git format-patch --signature='\n  this is my long signature\n\n  it has multiple lines\n  ' ...\n\nWe should notice that it already has its own trailing\nnewline, and suppress one of ours.\n\nSigned-off-by: Jeff King <peff@peff.net>\nSigned-off-by: Jeremiah Mahler <jmmahler@gmail.com>\n---\n builtin/log.c | 9 +++++++--\n 1 file changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 39e8836..5acc048 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -844,8 +844,13 @@ static void gen_message_id(struct rev_info *info, char *base)\n \n static void print_signature(void)\n {\n-\tif (signature && *signature)\n-\t\tprintf(\"-- \\n%s\\n\\n\", signature);\n+\tif (!signature || !*signature)\n+\t\treturn;\n+\n+\tprintf(\"-- \\n%s\", signature);\n+\tif (signature[strlen(signature)-1] != '\\n')\n+\t\tputchar('\\n');\n+\tputchar('\\n');\n }\n \n static void add_branch_description(struct strbuf *buf, const char *branch_name)\n-- \nJeremiah Mahler\njmmahler@gmail.com\nhttp://github.com/jmahler\n"},{"id":"242634","messageId":"a09491f3ec7ccfc5176fe05e6ad5c514d0489dcb.1400904004.git.jmmahler@gmail.com","threadId":"36747","inReplyTo":"cover.1400904004.git.jmmahler@gmail.com","subject":"[PATCH v9 2/2] format-patch --signature-file=<file>","fromName":"Jeremiah Mahler","fromEmail":"jmmahler@gmail.com","sentAt":"2014-05-24T04:08:14Z","receivedAt":"2014-05-24T04:08:14Z","isPatch":true,"sender":{"key":"jmmahler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/154028?v=4"},"body":"Add an option to format-patch for reading a signature from a file.\n\n  $ git format-patch -1 --signature-file=$HOME/.signature\n\nThe config variable `format.signaturefile` can also be used to make\nthis the default.\n\n  $ git config format.signaturefile $HOME/.signature\n\n  $ git format-patch -1\n\nSigned-off-by: Jeremiah Mahler <jmmahler@gmail.com>\n---\n Documentation/config.txt           |  4 +++\n Documentation/git-format-patch.txt |  4 +++\n builtin/log.c                      | 17 +++++++++++\n t/t4014-format-patch.sh            | 61 ++++++++++++++++++++++++++++++++++++++\n 4 files changed, 86 insertions(+)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 1932e9b..140ed77 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1114,6 +1114,10 @@ format.signature::\n \tSet this variable to the empty string (\"\") to suppress\n \tsignature generation.\n \n+format.signaturefile::\n+\tWorks just like format.signature except the contents of the\n+\tfile specified by this variable will be used as the signature.\n+\n format.suffix::\n \tThe default for format-patch is to output files with the suffix\n \t`.patch`. Use this variable to change that suffix (make sure to\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex 5c0a4ab..c0fd470 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -14,6 +14,7 @@ SYNOPSIS\n \t\t   [(--attach|--inline)[=<boundary>] | --no-attach]\n \t\t   [-s | --signoff]\n \t\t   [--signature=<signature> | --no-signature]\n+\t\t   [--signature-file=<file>]\n \t\t   [-n | --numbered | -N | --no-numbered]\n \t\t   [--start-number <n>] [--numbered-files]\n \t\t   [--in-reply-to=Message-Id] [--suffix=.<sfx>]\n@@ -233,6 +234,9 @@ configuration options in linkgit:git-notes[1] to use this workflow).\n \tsignature option is omitted the signature defaults to the Git version\n \tnumber.\n \n+--signature-file=<file>::\n+\tWorks just like --signature except the signature is read from a file.\n+\n --suffix=.<sfx>::\n \tInstead of using `.patch` as the suffix for generated\n \tfilenames, use specified suffix.  A common alternative is\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 5acc048..56cad39 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -673,6 +673,7 @@ static void add_header(const char *value)\n static int thread;\n static int do_signoff;\n static const char *signature = git_version_string;\n+static const char *signature_file;\n static int config_cover_letter;\n \n enum {\n@@ -742,6 +743,8 @@ static int git_format_config(const char *var, const char *value, void *cb)\n \t}\n \tif (!strcmp(var, \"format.signature\"))\n \t\treturn git_config_string(&signature, var, value);\n+\tif (!strcmp(var, \"format.signaturefile\"))\n+\t\treturn git_config_pathname(&signature_file, var, value);\n \tif (!strcmp(var, \"format.coverletter\")) {\n \t\tif (value && !strcasecmp(value, \"auto\")) {\n \t\t\tconfig_cover_letter = COVER_AUTO;\n@@ -1235,6 +1238,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t    PARSE_OPT_OPTARG, thread_callback },\n \t\tOPT_STRING(0, \"signature\", &signature, N_(\"signature\"),\n \t\t\t    N_(\"add a signature\")),\n+\t\tOPT_FILENAME(0, \"signature-file\", &signature_file,\n+\t\t\t\tN_(\"add a signature from a file\")),\n \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\n \t\tOPT_END()\n \t};\n@@ -1452,6 +1457,18 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\tcover_letter = (config_cover_letter == COVER_ON);\n \t}\n \n+\tif (!signature) {\n+\t\t/* --no-signature inhibits all signatures */\n+\t} else if (signature && signature != git_version_string) {\n+\t\t/* non-default signature already set */\n+\t} else if (signature_file) {\n+\t\tstruct strbuf buf = STRBUF_INIT;\n+\n+\t\tif (strbuf_read_file(&buf, signature_file, 128) < 0)\n+\t\t\tdie_errno(_(\"unable to read signature file '%s'\"), signature_file);\n+\t\tsignature = strbuf_detach(&buf, NULL);\n+\t}\n+\n \tif (in_reply_to || thread || cover_letter)\n \t\trev.ref_message_ids = xcalloc(1, sizeof(struct string_list));\n \tif (in_reply_to) {\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 9c80633..ae25353 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -762,6 +762,67 @@ test_expect_success 'format-patch --signature=\"\" suppresses signatures' '\n \t! grep \"^-- \\$\" output\n '\n \n+test_expect_success 'prepare mail-signature input' '\n+\tcat >mail-signature <<-\\EOF\n+\n+\tTest User <test.email@kernel.org>\n+\thttp://git.kernel.org/cgit/git/git.git\n+\n+\tgit.kernel.org/?p=git/git.git;a=summary\n+\n+\tEOF\n+'\n+\n+test_expect_success '--signature-file=file works' '\n+\tgit format-patch --stdout --signature-file=mail-signature -1 >output &&\n+\tcheck_patch output &&\n+\tsed -e \"1,/^-- \\$/d\" <output >actual &&\n+\t{\n+\t\tcat mail-signature && echo\n+\t} >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'format.signaturefile works' '\n+\ttest_config format.signaturefile mail-signature &&\n+\tgit format-patch --stdout -1 >output &&\n+\tcheck_patch output &&\n+\tsed -e \"1,/^-- \\$/d\" <output >actual &&\n+\t{\n+\t\tcat mail-signature && echo\n+\t} >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success '--no-signature suppresses format.signaturefile ' '\n+\ttest_config format.signaturefile mail-signature &&\n+\tgit format-patch --stdout --no-signature -1 >output &&\n+\tcheck_patch output &&\n+\t! grep \"^-- \\$\" output\n+'\n+\n+test_expect_success '--signature-file overrides format.signaturefile' '\n+\tcat >other-mail-signature <<-\\EOF\n+\tUse this other signature instead of mail-signature.\n+\tEOF\n+\ttest_config format.signaturefile mail-signature &&\n+\tgit format-patch --stdout \\\n+\t\t\t--signature-file=other-mail-signature -1 >output &&\n+\tcheck_patch output &&\n+\tsed -e \"1,/^-- \\$/d\" <output >actual &&\n+\t{\n+\t\tcat other-mail-signature && echo\n+\t} >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success '--signature overrides format.signaturefile' '\n+\ttest_config format.signaturefile mail-signature &&\n+\tgit format-patch --stdout --signature=\"my sig\" -1 >output &&\n+\tcheck_patch output &&\n+\tgrep \"my sig\" output\n+'\n+\n test_expect_success TTY 'format-patch --stdout paginates' '\n \trm -f pager_used &&\n \ttest_terminal env GIT_PAGER=\"wc >pager_used\" git format-patch --stdout --all &&\n-- \nJeremiah Mahler\njmmahler@gmail.com\nhttp://github.com/jmahler\n"}]}