[PATCH] format-patch: resurrect extra headers from config

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Once again, if you have

	[format]
		headers = "Origamization: EvilEmpire\n"

format-patch will add these headers just after the "Subject:" line.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@xxxxxx>
---
 builtin-log.c |   20 ++++++++++++++++++++
 log-tree.c    |    8 +++++---
 revision.h    |    1 +
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index ac4822d..6612f4c 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -85,6 +85,23 @@ static int istitlechar(char c)
 		(c >= '0' && c <= '9') || c == '.' || c == '_';
 }
 
+static char *extra_headers = NULL;
+static int extra_headers_size = 0;
+
+static int git_format_config(const char *var, const char *value)
+{
+	if (!strcmp(var, "format.headers")) {
+		int len = strlen(value);
+		extra_headers_size += len + 1;
+		extra_headers = realloc(extra_headers, extra_headers_size);
+		extra_headers[extra_headers_size - len - 1] = 0;
+		strcat(extra_headers, value);
+		return 0;
+	}
+	return git_default_config(var, value);
+}
+
+
 static FILE *realstdout = NULL;
 static char *output_directory = NULL;
 
@@ -162,6 +179,9 @@ int cmd_format_patch(int argc, const cha
 	rev.ignore_merges = 1;
 	rev.diffopt.output_format = DIFF_FORMAT_PATCH;
 
+	git_config(git_format_config);
+	rev.extra_headers = extra_headers;
+
 	/*
 	 * Parse the arguments before setup_revisions(), or something
 	 * like "git fmt-patch -o a123 HEAD^.." may fail; a123 is
diff --git a/log-tree.c b/log-tree.c
index e86e16b..ebb49f2 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -51,7 +51,7 @@ void show_log(struct rev_info *opt, stru
 	int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
 	const char *extra;
 	int len;
-	char *subject = NULL, *after_subject = NULL;
+	const char *subject = NULL, *extra_headers = opt->extra_headers;
 
 	opt->loginfo = NULL;
 	if (!opt->verbose_header) {
@@ -100,6 +100,7 @@ void show_log(struct rev_info *opt, stru
 			static char subject_buffer[1024];
 			static char buffer[1024];
 			snprintf(subject_buffer, sizeof(subject_buffer) - 1,
+				 "%s"
 				 "MIME-Version: 1.0\n"
 				 "Content-Type: multipart/mixed;\n"
 				 " boundary=\"%s%s\"\n"
@@ -110,9 +111,10 @@ void show_log(struct rev_info *opt, stru
 				 "Content-Type: text/plain; "
 				 "charset=UTF-8; format=fixed\n"
 				 "Content-Transfer-Encoding: 8bit\n\n",
+				 extra_headers ? extra_headers : "",
 				 mime_boundary_leader, opt->mime_boundary,
 				 mime_boundary_leader, opt->mime_boundary);
-			after_subject = subject_buffer;
+			extra_headers = subject_buffer;
 
 			snprintf(buffer, sizeof(buffer) - 1,
 				 "--%s%s\n"
@@ -141,7 +143,7 @@ void show_log(struct rev_info *opt, stru
 	/*
 	 * And then the pretty-printed message itself
 	 */
-	len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, after_subject);
+	len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, extra_headers);
 
 	if (opt->add_signoff)
 		len = append_signoff(this_header, sizeof(this_header), len,
diff --git a/revision.h b/revision.h
index 75796bc..7d85b0f 100644
--- a/revision.h
+++ b/revision.h
@@ -61,6 +61,7 @@ struct rev_info {
 	int		nr, total;
 	const char	*mime_boundary;
 	const char	*add_signoff;
+	const char	*extra_headers;
 
 	/* special limits */
 	int max_count;
-- 
1.3.3.g83f2b-dirty

-
: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]