From: Stephen Boyd <bebarino@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCHv2 1/3] format-patch: create patch filename in one function
Date: Sat, 21 Mar 2009 21:32:41 -0700 [thread overview]
Message-ID: <1237696363-6819-2-git-send-email-bebarino@gmail.com> (raw)
In-Reply-To: <1237696363-6819-1-git-send-email-bebarino@gmail.com>
reopen_stdout() usually takes the oneline description of a commit,
appends the patch suffix, prepends the output directory (if any) and
then reopens stdout as the resulting file. Now the patch filename (the
oneline description and the patch suffix) is created in
get_patch_filename() and passed to reopen_stdout() which prepends the
output directory and reopens stdout as that file.
The original function to get the oneline description,
get_oneline_for_filename(), has been renamed to get_patch_filename() to
reflect its new functionality.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
builtin-log.c | 49 +++++++++++++++++++++++++------------------------
1 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 8af55d2..cc6d663 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, "%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';
+ strcpy(filename + len, fmt_patch_suffix);
}
+ else
+ sprintf(filename, "%d", nr);
+
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, struct rev_info *rev)
+static int reopen_stdout(const char *oneline, struct rev_info *rev)
{
char filename[PATH_MAX];
int len = 0;
@@ -588,15 +587,7 @@ static int reopen_stdout(const char *oneline, int nr, struct rev_info *rev)
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-1);
if (!DIFF_OPT_TST(&rev->diffopt, QUIET))
fprintf(realstdout, "%s\n", filename + outdir_offset);
@@ -688,8 +679,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, rev))
+ if (!use_stdout && reopen_stdout(get_patch_filename(numbered_files ?
+ NULL : "cover-letter",
+ 0, 0), rev))
return;
head_sha1 = sha1_to_hex(head->object.sha1);
@@ -802,6 +794,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);
@@ -1106,9 +1099,17 @@ 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, &rev))
+ /*
+ * If we're outputting numbered files we don't need a subject
+ * line. Otherwise we want the subject line of the commit
+ * message which starts after the first double newline
+ * occurence in the commit buffer.
+ */
+ if (!numbered_files && (sol = strstr(commit->buffer, "\n\n")))
+ sol += 2;
+ if (!use_stdout && reopen_stdout(get_patch_filename(sol,
+ keep_subject,
+ rev.nr), &rev))
die("Failed to create output files");
shown = log_tree_commit(&rev, commit);
free(commit->buffer);
--
1.6.2
next prev parent reply other threads:[~2009-03-22 4:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-22 4:32 [PATCHv2 0/3] format-patch --attach/--inline use filename instead of SHA1 Stephen Boyd
2009-03-22 4:32 ` Stephen Boyd [this message]
2009-03-22 4:32 ` [PATCHv2 2/3] format-patch: --attach/inline uses " Stephen Boyd
2009-03-22 4:32 ` [PATCHv2 3/3] format-patch: --numbered-files and --stdout aren't mutually exclusive Stephen Boyd
2009-03-22 5:44 ` Junio C Hamano
2009-03-22 5:36 ` [PATCHv2 2/3] format-patch: --attach/inline uses filename instead of SHA1 Junio C Hamano
2009-03-22 5:31 ` [PATCHv2 1/3] format-patch: create patch filename in one function Junio C Hamano
2009-03-22 5:59 ` Stephen Boyd
2009-03-22 6:53 ` Junio C Hamano
2009-03-22 6:56 ` Stephen Boyd
2009-03-22 8:07 ` Junio C Hamano
2009-03-23 2:14 ` [PATCHv3 0/6] format-patch --attach/--inline uses filename not SHA1 Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 1/6] pretty.c: add %f format specifier to format_commit_message() Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 2/6] format-patch: construct patch filename in one function Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 3/6] format-patch: pass a commit to reopen_stdout() Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 4/6] format-patch: move get_patch_filename() into log-tree Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 5/6] format-patch: --attach/inline uses filename instead of SHA1 Stephen Boyd
2009-03-23 2:14 ` [PATCHv3 6/6] format-patch: --numbered-files and --stdout aren't mutually exclusive Stephen Boyd
2009-03-31 22:17 ` [PATCHv3 1/6] pretty.c: add %f format specifier to format_commit_message() René Scharfe
2009-03-31 23:24 ` [PATCH] format_sanitized_subject: Don't trim past initial length of strbuf Stephen Boyd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1237696363-6819-2-git-send-email-bebarino@gmail.com \
--to=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).