summaryrefslogtreecommitdiff
path: root/log-tree.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-03-01 11:36:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-01 17:54:42 (GMT)
commit8ffc8dc6bab4cf3d2364dd54b2de6c3afdb48610 (patch)
treed8d037bb65dd3873c87b1defb2546a589597984f /log-tree.c
parent3b9e3c2cede15057af3ff8076c45ad5f33829436 (diff)
downloadgit-8ffc8dc6bab4cf3d2364dd54b2de6c3afdb48610.zip
git-8ffc8dc6bab4cf3d2364dd54b2de6c3afdb48610.tar.gz
git-8ffc8dc6bab4cf3d2364dd54b2de6c3afdb48610.tar.bz2
log-tree: factor out fmt_output_email_subject()
Use a strbuf to store the subject prefix string and move its construction into its own function. This gets rid of two arbitrary length limits and allows the string to be added by callers directly. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'log-tree.c')
-rw-r--r--log-tree.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/log-tree.c b/log-tree.c
index 8c24157..44febb7 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -332,35 +332,33 @@ void fmt_output_commit(struct strbuf *filename,
strbuf_release(&subject);
}
+void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
+{
+ if (opt->total > 0) {
+ strbuf_addf(sb, "Subject: [%s%s%0*d/%d] ",
+ opt->subject_prefix,
+ *opt->subject_prefix ? " " : "",
+ digits_in_number(opt->total),
+ opt->nr, opt->total);
+ } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
+ strbuf_addf(sb, "Subject: [%s] ",
+ opt->subject_prefix);
+ } else {
+ strbuf_addstr(sb, "Subject: ");
+ }
+}
+
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
const char **subject_p,
const char **extra_headers_p,
int *need_8bit_cte_p)
{
- const char *subject = NULL;
+ static struct strbuf subject = STRBUF_INIT;
const char *extra_headers = opt->extra_headers;
const char *name = oid_to_hex(opt->zero_commit ?
&null_oid : &commit->object.oid);
*need_8bit_cte_p = 0; /* unknown */
- if (opt->total > 0) {
- static char buffer[64];
- snprintf(buffer, sizeof(buffer),
- "Subject: [%s%s%0*d/%d] ",
- opt->subject_prefix,
- *opt->subject_prefix ? " " : "",
- digits_in_number(opt->total),
- opt->nr, opt->total);
- subject = buffer;
- } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
- static char buffer[256];
- snprintf(buffer, sizeof(buffer),
- "Subject: [%s] ",
- opt->subject_prefix);
- subject = buffer;
- } else {
- subject = "Subject: ";
- }
fprintf(opt->diffopt.file, "From %s Mon Sep 17 00:00:00 2001\n", name);
graph_show_oneline(opt->graph);
@@ -417,7 +415,9 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
opt->diffopt.stat_sep = buffer;
strbuf_release(&filename);
}
- *subject_p = subject;
+ strbuf_reset(&subject);
+ fmt_output_email_subject(&subject, opt);
+ *subject_p = subject.buf;
*extra_headers_p = extra_headers;
}