From: "René Scharfe" <l.s.r@web.de>
To: Jeff King <peff@peff.net>, Adrian Dudau <Adrian.Dudau@enea.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: [PATCH 1/2] log-tree: factor out fmt_output_email_subject()
Date: Wed, 1 Mar 2017 12:36:38 +0100 [thread overview]
Message-ID: <e3de1725-99c3-d5a2-2cab-a05aa8546efb@web.de> (raw)
In-Reply-To: <20170228181719.t67abnnnsdcx2xfd@sigill.intra.peff.net>
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>
---
log-tree.c | 40 ++++++++++++++++++++--------------------
log-tree.h | 1 +
2 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/log-tree.c b/log-tree.c
index 8c2415747a..44febb75ab 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;
}
diff --git a/log-tree.h b/log-tree.h
index c8116e60cd..dd75dd7770 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -30,5 +30,6 @@ void load_ref_decorations(int flags);
#define FORMAT_PATCH_NAME_MAX 64
void fmt_output_commit(struct strbuf *, struct commit *, struct rev_info *);
void fmt_output_subject(struct strbuf *, const char *subject, struct rev_info *);
+void fmt_output_email_subject(struct strbuf *, struct rev_info *);
#endif
--
2.12.0
next prev parent reply other threads:[~2017-03-01 11:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-28 15:59 format-patch subject-prefix gets truncated when using the --numbered flag Adrian Dudau
2017-02-28 17:42 ` Junio C Hamano
2017-02-28 19:33 ` Junio C Hamano
2017-02-28 22:44 ` Jeff King
2017-02-28 18:17 ` Jeff King
2017-03-01 11:36 ` René Scharfe [this message]
2017-03-01 11:37 ` [PATCH 2/2] pretty: use fmt_output_email_subject() René Scharfe
2017-03-01 15:41 ` René Scharfe
2017-03-01 18:08 ` Junio C Hamano
2017-03-01 19:32 ` Jeff King
2017-03-01 19:38 ` Junio C Hamano
2017-03-01 19:43 ` Jeff King
2017-03-01 19:22 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e3de1725-99c3-d5a2-2cab-a05aa8546efb@web.de \
--to=l.s.r@web.de \
--cc=Adrian.Dudau@enea.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).