Skip to contentSkip to conversation

format-patch --signature-file=<file>

PATCH New Jeremiah Mahler 1 participant 3 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

v9 cover format-patch --signature-file=<file>

v9 of patch to add format-patch --signature-file <file> option.

This revision includes more suggestions from Junio C Hamano.

- Reworded patch description. Using "special characters" is not a feature of this patch.

- Changed patch description to follow gitcli(7) guidlines. "--signature-file=name" instead of "--signature-file name"

- Reduced set of crucial test cases.

--signature-file works

format.signaturefile works

--no-signature suppresses format.signaturefile

--signature-file overrides format.signaturefile

--signature overrides format.signaturefile

- Note, the control logic had to be re-worked to satisfy these test cases.

Jeff King (1):
format-patch: make newline after signature conditional

Jeremiah Mahler (1):
format-patch --signature-file=<file>

 Documentation/config.txt           |  4 +++
 Documentation/git-format-patch.txt |  4 +++
 builtin/log.c                      | 26 ++++++++++++++--
 t/t4014-format-patch.sh            | 61 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 93 insertions(+), 2 deletions(-)
Signature · 3 lines
Jeremiah Mahler
[email protected]
http://github.com/jmahler
#1 lore raw

PATCH v9 1/2 format-patch: make newline after signature conditional

From: Jeff King <[email protected]>

When we print an email signature, we print the divider "-- \n", then the signature string, then two newlines. Traditionally the signature is a one-liner (and the default is just the git version), so the extra newline makes sense.

But one could easily specify a longer, multi-line signature, like:

git format-patch --signature='
this is my long signature

it has multiple lines
' ...

We should notice that it already has its own trailing newline, and suppress one of ours.

---
 builtin/log.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
builtin/log.c +7 -2
index 39e8836..5acc048 100644
@@ -844,8 +844,13 @@ static void gen_message_id(struct rev_info *info, char *base)
 
 static void print_signature(void)
 {
-	if (signature && *signature)
-		printf("-- \n%s\n\n", signature);
+	if (!signature || !*signature)
+		return;
+
+	printf("-- \n%s", signature);
+	if (signature[strlen(signature)-1] != '\n')
+		putchar('\n');
+	putchar('\n');
 }
 
 static void add_branch_description(struct strbuf *buf, const char *branch_name)
Signature · 3 lines
Jeremiah Mahler
[email protected]
http://github.com/jmahler
#2 lore raw

PATCH v9 2/2 format-patch --signature-file=<file>

In reply to Jeremiah Mahler

Add an option to format-patch for reading a signature from a file.

  $ git format-patch -1 --signature-file=$HOME/.signature

The config variable format.signaturefile can also be used to make this the default.

  $ git config format.signaturefile $HOME/.signature
  $ git format-patch -1
---
 Documentation/config.txt           |  4 +++
 Documentation/git-format-patch.txt |  4 +++
 builtin/log.c                      | 17 +++++++++++
 t/t4014-format-patch.sh            | 61 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+)
Documentation/config.txt +4 -0
index 1932e9b..140ed77 100644
@@ -1114,6 +1114,10 @@ format.signature::
 	Set this variable to the empty string ("") to suppress
 	signature generation.
 
+format.signaturefile::
+	Works just like format.signature except the contents of the
+	file specified by this variable will be used as the signature.
+
 format.suffix::
 	The default for format-patch is to output files with the suffix
 	`.patch`. Use this variable to change that suffix (make sure to
Documentation/git-format-patch.txt +4 -0
index 5c0a4ab..c0fd470 100644
@@ -14,6 +14,7 @@ SYNOPSIS
 		   [(--attach|--inline)[=<boundary>] | --no-attach]
 		   [-s | --signoff]
 		   [--signature=<signature> | --no-signature]
+		   [--signature-file=<file>]
 		   [-n | --numbered | -N | --no-numbered]
 		   [--start-number <n>] [--numbered-files]
 		   [--in-reply-to=Message-Id] [--suffix=.<sfx>]
@@ -233,6 +234,9 @@ configuration options in linkgit:git-notes[1] to use this workflow).
 	signature option is omitted the signature defaults to the Git version
 	number.
 
+--signature-file=<file>::
+	Works just like --signature except the signature is read from a file.
+
 --suffix=.<sfx>::
 	Instead of using `.patch` as the suffix for generated
 	filenames, use specified suffix.  A common alternative is
builtin/log.c +17 -0
index 5acc048..56cad39 100644
@@ -673,6 +673,7 @@ static void add_header(const char *value)
 static int thread;
 static int do_signoff;
 static const char *signature = git_version_string;
+static const char *signature_file;
 static int config_cover_letter;
 
 enum {
@@ -742,6 +743,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
 	}
 	if (!strcmp(var, "format.signature"))
 		return git_config_string(&signature, var, value);
+	if (!strcmp(var, "format.signaturefile"))
+		return git_config_pathname(&signature_file, var, value);
 	if (!strcmp(var, "format.coverletter")) {
 		if (value && !strcasecmp(value, "auto")) {
 			config_cover_letter = COVER_AUTO;
@@ -1235,6 +1238,8 @@ 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")),
+		OPT_FILENAME(0, "signature-file", &signature_file,
+				N_("add a signature from a file")),
 		OPT__QUIET(&quiet, N_("don't print the patch filenames")),
 		OPT_END()
 	};
@@ -1452,6 +1457,18 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			cover_letter = (config_cover_letter == COVER_ON);
 	}
 
+	if (!signature) {
+		/* --no-signature inhibits all signatures */
+	} else if (signature && signature != git_version_string) {
+		/* non-default signature already set */
+	} else if (signature_file) {
+		struct strbuf buf = STRBUF_INIT;
+
+		if (strbuf_read_file(&buf, signature_file, 128) < 0)
+			die_errno(_("unable to read signature file '%s'"), signature_file);
+		signature = strbuf_detach(&buf, NULL);
+	}
+
 	if (in_reply_to || thread || cover_letter)
 		rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
 	if (in_reply_to) {
t/t4014-format-patch.sh +61 -0

67 lines not on this page · raw message

Signature · 3 lines
Jeremiah Mahler
[email protected]
http://github.com/jmahler