[PATCH] git format-patch --signature <string | file>

Subsystems: the rest

STALE3738d

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] git format-patch --signature <string | file>

From: Jeremiah Mahler <hidden>
Date: 2016-06-15 23:01:07

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 <redacted>
---
 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

Re: [PATCH] git format-patch --signature <string | file>

From: Jonathan Nieder <hidden>
Date: 2016-06-15 23:01:07

Hi,

Jeremiah Mahler wrote:
  # from a string
  $ git format-patch --signature "from a string" origin

  # or from a file
  $ git format-patch --signature ~/.signature origin
Interesting.  But... what if I want my patch to end with

	-- 
	/home/jrnieder/.signature

?  It seems safer to introduce a separate --signature-file option.

[...]
 builtin/log.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
Tests?

Thanks and hope that helps,
Jonathan

Re: [PATCH] git format-patch --signature <string | file>

From: Jeremiah Mahler <hidden>
Date: 2016-06-15 23:01:08

On Tue, May 13, 2014 at 09:07:12AM -0700, Jonathan Nieder wrote:
Hi,

Jeremiah Mahler wrote:
quoted
  # from a string
  $ git format-patch --signature "from a string" origin

  # or from a file
  $ git format-patch --signature ~/.signature origin
Interesting.  But... what if I want my patch to end with

	-- 
	/home/jrnieder/.signature

?  It seems safer to introduce a separate --signature-file option.
It is probably smarter to avoid that corner case entirely.
Good idea.
[...]
quoted
 builtin/log.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
Tests?
I added a test which checks that a valid patch is produced and that
the signature from the file appears in the output.
Thanks and hope that helps,
Jonathan
Attached is a revised patch.

-- 
Jeremiah Mahler
jmmahler@gmail.com
http://github.com/jmahler
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help