format-patch: add "--signature-file=<file>" option
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 Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
c6076e2b4a
commit
7022650f61
@ -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) {
|
||||
|
Reference in New Issue
Block a user