{"thread":{"id":"36726","subject":"[PATCH v7 0/2] format-patch --signature-file <file>","startedAt":"2014-05-21T21:07:50Z","lastAt":"2014-05-21T21:59:36Z","messageCount":5,"participants":["Jeremiah Mahler","Junio C Hamano"],"isPatch":true,"patchVersion":7,"patchTotal":2},"messages":[{"id":"242410","messageId":"1400706472-13471-1-git-send-email-jmmahler@gmail.com","threadId":"36726","inReplyTo":null,"subject":"[PATCH v7 0/2] format-patch --signature-file <file>","fromName":"Jeremiah Mahler","fromEmail":"jmmahler@gmail.com","sentAt":"2014-05-21T21:07:50Z","receivedAt":"2014-05-21T21:07:50Z","isPatch":true,"sender":{"key":"jmmahler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/154028?v=4"},"body":"v7 of patch to add format-patch --signature-file <file> option.\n\nThis revision includes a patch from Jeff King to fix the odd number\nspaces produced by print_signature().\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                      | 25 +++++++++++++++++++++++--\n t/t4014-format-patch.sh            | 32 ++++++++++++++++++++++++++++++++\n 4 files changed, 63 insertions(+), 2 deletions(-)\n\n-- \nJeremiah Mahler\njmmahler@gmail.com\nhttp://github.com/jmahler\n"},{"id":"242411","messageId":"1400706472-13471-2-git-send-email-jmmahler@gmail.com","threadId":"36726","inReplyTo":"1400706472-13471-1-git-send-email-jmmahler@gmail.com","subject":"[PATCH v7 1/2] format-patch: make newline after signature conditional","fromName":"Jeremiah Mahler","fromEmail":"jmmahler@gmail.com","sentAt":"2014-05-21T21:07:51Z","receivedAt":"2014-05-21T21:07:51Z","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":"242412","messageId":"1400706472-13471-3-git-send-email-jmmahler@gmail.com","threadId":"36726","inReplyTo":"1400706472-13471-1-git-send-email-jmmahler@gmail.com","subject":"[PATCH v7 2/2] format-patch --signature-file <file>","fromName":"Jeremiah Mahler","fromEmail":"jmmahler@gmail.com","sentAt":"2014-05-21T21:07:52Z","receivedAt":"2014-05-21T21:07:52Z","isPatch":true,"sender":{"key":"jmmahler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/154028?v=4"},"body":"Added option that allows a signature file to be used with format-patch\nso that signatures with newlines and other special characters can be\neasily included.\n\n  $ git format-patch --signature-file ~/.signature -1\n\nThe config variable format.signaturefile is also provided so that it\ncan be added by default.\n\n  $ git config format.signaturefile ~/.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                      | 16 ++++++++++++++++\n t/t4014-format-patch.sh            | 32 ++++++++++++++++++++++++++++++++\n 4 files changed, 56 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..28d22fd 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,17 @@ 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_file) {\n+\t\tif (signature && signature != git_version_string)\n+\t\t\tdie(_(\"cannot specify both signature and signature-file\"));\n+\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..e604f65 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -762,6 +762,38 @@ test_expect_success 'format-patch --signature=\"\" suppresses signatures' '\n \t! grep \"^-- \\$\" output\n '\n \n+cat >expect <<-\\EOF\n+\n+Test User <test.email@kernel.org>\n+http://git.kernel.org/cgit/git/git.git\n+\n+git.kernel.org/?p=git/git.git;a=summary\n+\n+EOF\n+\n+test_expect_success 'format-patch --signature-file=file' '\n+\tgit format-patch --stdout --signature-file=expect -1 >output &&\n+\tcheck_patch output &&\n+\tsed -n -e \"/^-- $/,\\$p\" <output | sed -e \"1 d\" | sed -e \"\\$d\" >output2 &&\n+\ttest_cmp expect output2\n+'\n+\n+test_expect_success 'format-patch with format.signaturefile config' '\n+\ttest_config format.signaturefile expect &&\n+\tgit format-patch --stdout -1 >output &&\n+\tcheck_patch output &&\n+\tsed -n -e \"/^-- $/,\\$p\" <output | sed -e \"1 d\" | sed -e \"\\$d\" >output2 &&\n+\ttest_cmp expect output2\n+'\n+\n+test_expect_success 'format-patch --signature and --signature-file die' '\n+\ttest_must_fail git format-patch --stdout --signature=\"foo\" --signature-file=expect -1 >output\n+'\n+\n+test_expect_success 'format-patch --no-signature and --signature-file OK' '\n+\tgit format-patch --stdout --no-signature --signature-file=expect -1\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"},{"id":"242415","messageId":"xmqq1tvmq129.fsf@gitster.dls.corp.google.com","threadId":"36726","inReplyTo":"1400706472-13471-2-git-send-email-jmmahler@gmail.com","subject":"Re: [PATCH v7 1/2] format-patch: make newline after signature conditional","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-21T21:22:38Z","receivedAt":"2014-05-21T21:22:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeremiah Mahler <jmmahler@gmail.com> writes:\n\n> From: Jeff King <peff@peff.net>\n>\n> When we print an email signature, we print the divider \"--\n> \\n\", then the signature string, then two newlines.\n> Traditionally the signature is a one-liner (and the default\n> is just the git version), so the extra newline makes sense.\n>\n> But one could easily specify a longer, multi-line signature,\n> like:\n>\n>   git format-patch --signature='\n>   this is my long signature\n>\n>   it has multiple lines\n>   ' ...\n>\n> We should notice that it already has its own trailing\n> newline, and suppress one of ours.\n\nThat is a half-good example; the first line being a blank is\nmisleading, as we are not doing anything about that, though.\n\nOther than that, the patch looks OK to me.  If anybody complains we\ncan fix it later to do more cleansing.\n\n> Signed-off-by: Jeff King <peff@peff.net>\n> Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>\n> ---\n>  builtin/log.c | 9 +++++++--\n>  1 file changed, 7 insertions(+), 2 deletions(-)\n>\n> diff --git a/builtin/log.c b/builtin/log.c\n> index 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"},{"id":"242423","messageId":"xmqqk39eoks7.fsf@gitster.dls.corp.google.com","threadId":"36726","inReplyTo":"1400706472-13471-3-git-send-email-jmmahler@gmail.com","subject":"Re: [PATCH v7 2/2] format-patch --signature-file <file>","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-21T21:59:36Z","receivedAt":"2014-05-21T21:59:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeremiah Mahler <jmmahler@gmail.com> writes:\n\n> +\tif (signature_file) {\n> +\t\tif (signature && signature != git_version_string)\n> +\t\t\tdie(_(\"cannot specify both signature and signature-file\"));\n> +\n> +\t\tstruct strbuf buf = STRBUF_INIT;\n\nbuiltin/log.c:1460:3: error: ISO C90 forbids mixed declarations and\ncode [-Werror=declaration-after-statement]\n"}]}