Skip to content

Commit 8ffc8dc

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b9e3c2 commit 8ffc8dc

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

log-tree.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -332,35 +332,33 @@ void fmt_output_commit(struct strbuf *filename,
332332
strbuf_release(&subject);
333333
}
334334

335+
void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
336+
{
337+
if (opt->total > 0) {
338+
strbuf_addf(sb, "Subject: [%s%s%0*d/%d] ",
339+
opt->subject_prefix,
340+
*opt->subject_prefix ? " " : "",
341+
digits_in_number(opt->total),
342+
opt->nr, opt->total);
343+
} else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
344+
strbuf_addf(sb, "Subject: [%s] ",
345+
opt->subject_prefix);
346+
} else {
347+
strbuf_addstr(sb, "Subject: ");
348+
}
349+
}
350+
335351
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
336352
const char **subject_p,
337353
const char **extra_headers_p,
338354
int *need_8bit_cte_p)
339355
{
340-
const char *subject = NULL;
356+
static struct strbuf subject = STRBUF_INIT;
341357
const char *extra_headers = opt->extra_headers;
342358
const char *name = oid_to_hex(opt->zero_commit ?
343359
&null_oid : &commit->object.oid);
344360

345361
*need_8bit_cte_p = 0; /* unknown */
346-
if (opt->total > 0) {
347-
static char buffer[64];
348-
snprintf(buffer, sizeof(buffer),
349-
"Subject: [%s%s%0*d/%d] ",
350-
opt->subject_prefix,
351-
*opt->subject_prefix ? " " : "",
352-
digits_in_number(opt->total),
353-
opt->nr, opt->total);
354-
subject = buffer;
355-
} else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
356-
static char buffer[256];
357-
snprintf(buffer, sizeof(buffer),
358-
"Subject: [%s] ",
359-
opt->subject_prefix);
360-
subject = buffer;
361-
} else {
362-
subject = "Subject: ";
363-
}
364362

365363
fprintf(opt->diffopt.file, "From %s Mon Sep 17 00:00:00 2001\n", name);
366364
graph_show_oneline(opt->graph);
@@ -417,7 +415,9 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
417415
opt->diffopt.stat_sep = buffer;
418416
strbuf_release(&filename);
419417
}
420-
*subject_p = subject;
418+
strbuf_reset(&subject);
419+
fmt_output_email_subject(&subject, opt);
420+
*subject_p = subject.buf;
421421
*extra_headers_p = extra_headers;
422422
}
423423

log-tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ void load_ref_decorations(int flags);
3030
#define FORMAT_PATCH_NAME_MAX 64
3131
void fmt_output_commit(struct strbuf *, struct commit *, struct rev_info *);
3232
void fmt_output_subject(struct strbuf *, const char *subject, struct rev_info *);
33+
void fmt_output_email_subject(struct strbuf *, struct rev_info *);
3334

3435
#endif

0 commit comments

Comments
 (0)