From: Jeremiah Mahler <jmmahler@gmail.com>
To: git@vger.kernel.org
Cc: Jeremiah Mahler <jmmahler@gmail.com>
Subject: [PATCH] git format-patch --signature <string | file>
Date: Tue, 13 May 2014 01:21:36 -0700 [thread overview]
Message-ID: <1399969296-31598-1-git-send-email-jmmahler@gmail.com> (raw)
Improved format-patch --signature option so that it can
read from a file as well as from a string.
# from a string
$ git format-patch --signature "from a string" origin
# or from a file
$ git format-patch --signature ~/.signature origin
Now signatures with newlines or other special characters
can be easily included.
Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
---
builtin/log.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index 39e8836..5988f8f 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1147,6 +1147,27 @@ static int from_callback(const struct option *opt, const char *arg, int unset)
return 0;
}
+static int signature_callback(const struct option *opt, const char *arg,
+ int unset)
+{
+ const char **signature = opt->value;
+ static char buf[1024];
+ size_t sz;
+ FILE *fp;
+
+ fp = fopen(arg, "r");
+ if (fp) {
+ sz = sizeof(buf);
+ sz = fread(buf, 1, sz - 1, fp);
+ buf[sz] = '\0';
+ *signature = buf;
+ fclose(fp);
+ } else {
+ *signature = arg;
+ }
+ return 0;
+}
+
int cmd_format_patch(int argc, const char **argv, const char *prefix)
{
struct commit *commit;
@@ -1228,8 +1249,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
{ OPTION_CALLBACK, 0, "thread", &thread, N_("style"),
N_("enable message threading, styles: shallow, deep"),
PARSE_OPT_OPTARG, thread_callback },
- OPT_STRING(0, "signature", &signature, N_("signature"),
- N_("add a signature")),
+ { OPTION_CALLBACK, 0, "signature", &signature, N_("signature-file"),
+ N_("add a signature from a string or a file"),
+ PARSE_OPT_NONEG, signature_callback },
OPT__QUIET(&quiet, N_("don't print the patch filenames")),
OPT_END()
};
--
Jeremiah Mahler
jmmahler@gmail.com
http://github.com/jmahler
next reply other threads:[~2014-05-13 8:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-13 8:21 Jeremiah Mahler [this message]
2014-05-13 16:07 ` [PATCH] git format-patch --signature <string | file> Jonathan Nieder
2014-05-14 1:53 ` Jeremiah Mahler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1399969296-31598-1-git-send-email-jmmahler@gmail.com \
--to=jmmahler@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).