{"thread":{"id":"36647","subject":"[PATCH] git format-patch --signature <string | file>","startedAt":"2014-05-13T08:21:36Z","lastAt":"2014-05-14T01:53:56Z","messageCount":3,"participants":["Jeremiah Mahler","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"241340","messageId":"1399969296-31598-1-git-send-email-jmmahler@gmail.com","threadId":"36647","inReplyTo":null,"subject":"[PATCH] git format-patch --signature <string | file>","fromName":"Jeremiah Mahler","fromEmail":"jmmahler@gmail.com","sentAt":"2014-05-13T08:21:36Z","receivedAt":"2014-05-13T08:21:36Z","isPatch":true,"sender":{"key":"jmmahler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/154028?v=4"},"body":"Improved format-patch --signature option so that it can\nread from a file as well as from a string.\n\n  # from a string\n  $ git format-patch --signature \"from a string\" origin\n\n  # or from a file\n  $ git format-patch --signature ~/.signature origin\n\nNow signatures with newlines or other special characters\ncan be easily included.\n\nSigned-off-by: Jeremiah Mahler <jmmahler@gmail.com>\n---\n builtin/log.c | 26 ++++++++++++++++++++++++--\n 1 file changed, 24 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 39e8836..5988f8f 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1147,6 +1147,27 @@ static int from_callback(const struct option *opt, const char *arg, int unset)\n \treturn 0;\n }\n \n+static int signature_callback(const struct option *opt, const char *arg,\n+\t\t\t\t\t\t\tint unset)\n+{\n+\tconst char **signature = opt->value;\n+\tstatic char buf[1024];\n+\tsize_t sz;\n+\tFILE *fp;\n+\n+\tfp = fopen(arg, \"r\");\n+\tif (fp) {\n+\t\tsz = sizeof(buf);\n+\t\tsz = fread(buf, 1, sz - 1, fp);\n+\t\tbuf[sz] = '\\0';\n+\t\t*signature = buf;\n+\t\tfclose(fp);\n+\t} else {\n+\t\t*signature = arg;\n+\t}\n+\treturn 0;\n+}\n+\n int cmd_format_patch(int argc, const char **argv, const char *prefix)\n {\n \tstruct commit *commit;\n@@ -1228,8 +1249,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t{ OPTION_CALLBACK, 0, \"thread\", &thread, N_(\"style\"),\n \t\t\t    N_(\"enable message threading, styles: shallow, deep\"),\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\t{ OPTION_CALLBACK, 0, \"signature\", &signature, N_(\"signature-file\"),\n+\t\t\t\tN_(\"add a signature from a string or a file\"),\n+\t\t\t    PARSE_OPT_NONEG, signature_callback },\n \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\n \t\tOPT_END()\n \t};\n-- \nJeremiah Mahler\njmmahler@gmail.com\nhttp://github.com/jmahler\n"},{"id":"241376","messageId":"20140513160712.GA30685@google.com","threadId":"36647","inReplyTo":"1399969296-31598-1-git-send-email-jmmahler@gmail.com","subject":"Re: [PATCH] git format-patch --signature <string | file>","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2014-05-13T16:07:12Z","receivedAt":"2014-05-13T16:07:12Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nJeremiah Mahler wrote:\n\n>   # from a string\n>   $ git format-patch --signature \"from a string\" origin\n>\n>   # or from a file\n>   $ git format-patch --signature ~/.signature origin\n\nInteresting.  But... what if I want my patch to end with\n\n\t-- \n\t/home/jrnieder/.signature\n\n?  It seems safer to introduce a separate --signature-file option.\n\n[...]\n>  builtin/log.c | 26 ++++++++++++++++++++++++--\n>  1 file changed, 24 insertions(+), 2 deletions(-)\n\nTests?\n\nThanks and hope that helps,\nJonathan\n"},{"id":"241478","messageId":"20140514015356.GA21893@hudson.localdomain","threadId":"36647","inReplyTo":"20140513160712.GA30685@google.com","subject":"Re: [PATCH] git format-patch --signature <string | file>","fromName":"Jeremiah Mahler","fromEmail":"jmmahler@gmail.com","sentAt":"2014-05-14T01:53:56Z","receivedAt":"2014-05-14T01:53:56Z","isPatch":true,"sender":{"key":"jmmahler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/154028?v=4"},"body":"\nOn Tue, May 13, 2014 at 09:07:12AM -0700, Jonathan Nieder wrote:\n> Hi,\n> \n> Jeremiah Mahler wrote:\n> \n> >   # from a string\n> >   $ git format-patch --signature \"from a string\" origin\n> >\n> >   # or from a file\n> >   $ git format-patch --signature ~/.signature origin\n> \n> Interesting.  But... what if I want my patch to end with\n> \n> \t-- \n> \t/home/jrnieder/.signature\n> \n> ?  It seems safer to introduce a separate --signature-file option.\n> \n\nIt is probably smarter to avoid that corner case entirely.\nGood idea.\n\n> [...]\n> >  builtin/log.c | 26 ++++++++++++++++++++++++--\n> >  1 file changed, 24 insertions(+), 2 deletions(-)\n> \n> Tests?\n> \n\nI added a test which checks that a valid patch is produced and that\nthe signature from the file appears in the output.\n\n> Thanks and hope that helps,\n> Jonathan\n\nAttached is a revised patch.\n\n-- \nJeremiah Mahler\njmmahler@gmail.com\nhttp://github.com/jmahler\n\n\n>From e5cbeaf50d85236d6dd53e64f8f7cf466b1acecd Mon Sep 17 00:00:00 2001\nFrom: Jeremiah Mahler <jmmahler@gmail.com>\nDate: Tue, 13 May 2014 18:10:53 -0700\nSubject: [PATCH] format-patch --signature-file <file>\n\nAdded feature that allows a signature file to be used with format-patch.\n\n  $ git format-patch --signature-file ~/.signature origin\n\nNow signatures with newlines and other special characters can\nbe easily included.\n\nSigned-off-by: Jeremiah Mahler <jmmahler@gmail.com>\n---\n builtin/log.c           | 24 ++++++++++++++++++++++++\n t/t4014-format-patch.sh | 13 +++++++++++++\n 2 files changed, 37 insertions(+)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 39e8836..1ec733b 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1147,6 +1147,27 @@ static int from_callback(const struct option *opt, const char *arg, int unset)\n \treturn 0;\n }\n \n+static int signature_file_callback(const struct option *opt, const char *arg,\n+\t\t\t\t\t\t\tint unset)\n+{\n+\tconst char **signature = opt->value;\n+\tstatic char buf[1024];\n+\tsize_t sz;\n+\tFILE *fp;\n+\n+\tfp = fopen(arg, \"r\");\n+\tif (fp) {\n+\t\tsz = sizeof(buf);\n+\t\tsz = fread(buf, 1, sz - 1, fp);\n+\t\tbuf[sz] = '\\0';\n+\t\t*signature = buf;\n+\t\tfclose(fp);\n+\t} else {\n+\t\t*signature = arg;\n+\t}\n+\treturn 0;\n+}\n+\n int cmd_format_patch(int argc, const char **argv, const char *prefix)\n {\n \tstruct commit *commit;\n@@ -1230,6 +1251,9 @@ 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\t{ OPTION_CALLBACK, 0, \"signature-file\", &signature, N_(\"signature-file\"),\n+\t\t\t\tN_(\"add a signature from contents of a file\"),\n+\t\t\t    PARSE_OPT_NONEG, signature_file_callback },\n \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\n \t\tOPT_END()\n \t};\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 9c80633..19b67e3 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -762,6 +762,19 @@ test_expect_success 'format-patch --signature=\"\" suppresses signatures' '\n \t! grep \"^-- \\$\" output\n '\n \n+cat > expect << EOF\n+Test User <test.email@kernel.org>\n+http://git.kernel.org/cgit/git/git.git\n+git.kernel.org/?p=git/git.git;a=summary\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+\tfgrep -x -f output expect >output2 &&\n+\tdiff expect output2\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\n\n"}]}