[PATCH 2/3] format-patch: create patch filename in get_patch_filename()

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

 



reopen_stdout() used to take the oneline description of a commit, append
the patch suffix, prepend the output directory (if any) and then point
stdout to that file. Now the patch filename (the oneline description and
the patch suffix) is created in get_patch_filename() and passed to
reopen_stdout()

Signed-off-by: Stephen Boyd <bebarino@xxxxxxxxx>
---
 builtin-log.c |   48 ++++++++++++++++++++++++------------------------
 1 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index c72e35a..f2a687f 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -519,21 +519,17 @@ static int git_format_config(const char *var,
const char *value, void *cb)
 }


-static const char *get_oneline_for_filename(struct commit *commit,
-					    int keep_subject)
+static const char *get_patch_filename(char* sol, int keep_subject, int nr)
 {
 	static char filename[PATH_MAX];
-	char *sol;
 	int len = 0;
 	int suffix_len = strlen(fmt_patch_suffix) + 1;

-	sol = strstr(commit->buffer, "\n\n");
-	if (!sol)
-		filename[0] = '\0';
-	else {
+	if (sol)
+	{
 		int j, space = 0;

-		sol += 2;
+		len += sprintf(filename + len, "%04d-", nr);
 		/* strip [PATCH] or [PATCH blabla] */
 		if (!keep_subject && !prefixcmp(sol, "[PATCH")) {
 			char *eos = strchr(sol + 6, ']');
@@ -564,8 +560,11 @@ static const char
*get_oneline_for_filename(struct commit *commit,
 		while (filename[len - 1] == '.'
 		       || filename[len - 1] == '-')
 			len--;
-		filename[len] = '\0';
 	}
+	else
+		len += sprintf(filename + len, "%d", nr);
+	strcpy(filename + len, fmt_patch_suffix);
+
 	return filename;
 }

@@ -573,7 +572,7 @@ static FILE *realstdout = NULL;
 static const char *output_directory = NULL;
 static int outdir_offset;

-static int reopen_stdout(const char *oneline, int nr)
+static int reopen_stdout(const char *oneline)
 {
 	char filename[PATH_MAX];
 	int len = 0;
@@ -588,15 +587,7 @@ static int reopen_stdout(const char *oneline, int nr)
 		if (filename[len - 1] != '/')
 			filename[len++] = '/';
 	}
-
-	if (!oneline)
-		len += sprintf(filename + len, "%d", nr);
-	else {
-		len += sprintf(filename + len, "%04d-", nr);
-		len += snprintf(filename + len, sizeof(filename) - len - 1
-				- suffix_len, "%s", oneline);
-		strcpy(filename + len, fmt_patch_suffix);
-	}
+	strncpy(filename+len, oneline, PATH_MAX-len);

 	fprintf(realstdout, "%s\n", filename + outdir_offset);
 	if (freopen(filename, "w", stdout) == NULL)
@@ -686,8 +677,9 @@ static void make_cover_letter(struct rev_info
*rev, int use_stdout,
 	if (rev->commit_format != CMIT_FMT_EMAIL)
 		die("Cover letter needs email format");

-	if (!use_stdout && reopen_stdout(numbered_files ?
-				NULL : "cover-letter", 0))
+	if (!use_stdout && reopen_stdout(get_patch_filename(numbered_files ?
+							NULL : "cover-letter",
+							0, 0)))
 		return;

 	head_sha1 = sha1_to_hex(head->object.sha1);
@@ -800,6 +792,7 @@ int cmd_format_patch(int argc, const char **argv,
const char *prefix)
 	struct patch_ids ids;
 	char *add_signoff = NULL;
 	struct strbuf buf = STRBUF_INIT;
+	char *sol = NULL;

 	git_config(git_format_config, NULL);
 	init_revisions(&rev, prefix);
@@ -1104,9 +1097,16 @@ int cmd_format_patch(int argc, const char
**argv, const char *prefix)
 			}
 			gen_message_id(&rev, sha1_to_hex(commit->object.sha1));
 		}
-		if (!use_stdout && reopen_stdout(numbered_files ? NULL :
-				get_oneline_for_filename(commit, keep_subject),
-				rev.nr))
+		/*
+		 * We want the subject line of the commit message which starts
+		 * after the first double newline occurence in the commit
+		 * buffer. If we're outputting numbered files we don't need a
+		 * subject line.
+		 */
+		sol = numbered_files ? NULL : strstr(commit->buffer, "\n\n")+2;
+		if (!use_stdout && reopen_stdout(get_patch_filename(sol,
+								keep_subject,
+								rev.nr)))
 			die("Failed to create output files");
 		shown = log_tree_commit(&rev, commit);
 		free(commit->buffer);
-- 
1.6.2
--
To unsubscribe from this list: 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]

  Powered by Linux