* [PATCH] git format-patch --signature <string | file>
@ 2014-05-13 8:21 Jeremiah Mahler
2014-05-13 16:07 ` Jonathan Nieder
0 siblings, 1 reply; 3+ messages in thread
From: Jeremiah Mahler @ 2014-05-13 8:21 UTC (permalink / raw)
To: git; +Cc: Jeremiah Mahler
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] git format-patch --signature <string | file>
2014-05-13 8:21 [PATCH] git format-patch --signature <string | file> Jeremiah Mahler
@ 2014-05-13 16:07 ` Jonathan Nieder
2014-05-14 1:53 ` Jeremiah Mahler
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Nieder @ 2014-05-13 16:07 UTC (permalink / raw)
To: Jeremiah Mahler; +Cc: git
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] git format-patch --signature <string | file>
2014-05-13 16:07 ` Jonathan Nieder
@ 2014-05-14 1:53 ` Jeremiah Mahler
0 siblings, 0 replies; 3+ messages in thread
From: Jeremiah Mahler @ 2014-05-14 1:53 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 903 bytes --]
On Tue, May 13, 2014 at 09:07:12AM -0700, Jonathan Nieder wrote:
> 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.
>
It is probably smarter to avoid that corner case entirely.
Good idea.
> [...]
> > 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
[-- Attachment #2: 0001-format-patch-signature-file-file.patch --]
[-- Type: text/x-diff, Size: 2698 bytes --]
>From e5cbeaf50d85236d6dd53e64f8f7cf466b1acecd Mon Sep 17 00:00:00 2001
From: Jeremiah Mahler <jmmahler@gmail.com>
Date: Tue, 13 May 2014 18:10:53 -0700
Subject: [PATCH] format-patch --signature-file <file>
Added feature that allows a signature file to be used with format-patch.
$ git format-patch --signature-file ~/.signature origin
Now signatures with newlines and other special characters can
be easily included.
Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
---
builtin/log.c | 24 ++++++++++++++++++++++++
t/t4014-format-patch.sh | 13 +++++++++++++
2 files changed, 37 insertions(+)
diff --git a/builtin/log.c b/builtin/log.c
index 39e8836..1ec733b 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_file_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;
@@ -1230,6 +1251,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
PARSE_OPT_OPTARG, thread_callback },
OPT_STRING(0, "signature", &signature, N_("signature"),
N_("add a signature")),
+ { OPTION_CALLBACK, 0, "signature-file", &signature, N_("signature-file"),
+ N_("add a signature from contents of a file"),
+ PARSE_OPT_NONEG, signature_file_callback },
OPT__QUIET(&quiet, N_("don't print the patch filenames")),
OPT_END()
};
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 9c80633..19b67e3 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -762,6 +762,19 @@ test_expect_success 'format-patch --signature="" suppresses signatures' '
! grep "^-- \$" output
'
+cat > expect << EOF
+Test User <test.email@kernel.org>
+http://git.kernel.org/cgit/git/git.git
+git.kernel.org/?p=git/git.git;a=summary
+EOF
+
+test_expect_success 'format-patch --signature-file file' '
+ git format-patch --stdout --signature-file expect -1 >output &&
+ check_patch output &&
+ fgrep -x -f output expect >output2 &&
+ diff expect output2
+'
+
test_expect_success TTY 'format-patch --stdout paginates' '
rm -f pager_used &&
test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all &&
--
Jeremiah Mahler
jmmahler@gmail.com
http://github.com/jmahler
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-05-14 1:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-13 8:21 [PATCH] git format-patch --signature <string | file> Jeremiah Mahler
2014-05-13 16:07 ` Jonathan Nieder
2014-05-14 1:53 ` Jeremiah Mahler
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).