Skip to content

Commit 6d167fd

Browse files
rscharfegitster
authored andcommitted
pretty: use fmt_output_email_subject()
Add the email-style subject prefix (e.g. "Subject: [PATCH] ") directly when it's needed instead of letting log_write_email_headers() prepare it in a static buffer in advance. This simplifies storage ownership and code flow. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ffc8dc commit 6d167fd

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

builtin/log.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
989989
open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
990990
return;
991991

992-
log_write_email_headers(rev, head, &pp.subject, &pp.after_subject,
993-
&need_8bit_cte);
992+
log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte);
994993

995994
for (i = 0; !need_8bit_cte && i < nr; i++) {
996995
const char *buf = get_commit_buffer(list[i], NULL);
@@ -1005,6 +1004,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
10051004
msg = body;
10061005
pp.fmt = CMIT_FMT_EMAIL;
10071006
pp.date_mode.type = DATE_RFC2822;
1007+
pp.rev = rev;
1008+
pp.print_email_subject = 1;
10081009
pp_user_info(&pp, NULL, &sb, committer, encoding);
10091010
pp_title_line(&pp, &msg, &sb, encoding, need_8bit_cte);
10101011
pp_remainder(&pp, &msg, &sb, 0);

builtin/shortlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
143143

144144
ctx.fmt = CMIT_FMT_USERFORMAT;
145145
ctx.abbrev = log->abbrev;
146-
ctx.subject = "";
146+
ctx.print_email_subject = 1;
147147
ctx.after_subject = "";
148148
ctx.date_mode.type = DATE_NORMAL;
149149
ctx.output_encoding = get_log_output_encoding();

commit.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,24 @@ static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
142142
return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD);
143143
}
144144

145+
struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
146+
145147
struct pretty_print_context {
146148
/*
147149
* Callers should tweak these to change the behavior of pp_* functions.
148150
*/
149151
enum cmit_fmt fmt;
150152
int abbrev;
151-
const char *subject;
152153
const char *after_subject;
153154
int preserve_subject;
154155
struct date_mode date_mode;
155156
unsigned date_mode_explicit:1;
157+
int print_email_subject;
156158
int expand_tabs_in_log;
157159
int need_8bit_cte;
158160
char *notes_message;
159161
struct reflog_walk_info *reflog_info;
162+
struct rev_info *rev;
160163
const char *output_encoding;
161164
struct string_list *mailmap;
162165
int color;
@@ -175,7 +178,6 @@ struct userformat_want {
175178
};
176179

177180
extern int has_non_ascii(const char *text);
178-
struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
179181
extern const char *logmsg_reencode(const struct commit *commit,
180182
char **commit_encoding,
181183
const char *output_encoding);

log-tree.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,9 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
349349
}
350350

351351
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
352-
const char **subject_p,
353352
const char **extra_headers_p,
354353
int *need_8bit_cte_p)
355354
{
356-
static struct strbuf subject = STRBUF_INIT;
357355
const char *extra_headers = opt->extra_headers;
358356
const char *name = oid_to_hex(opt->zero_commit ?
359357
&null_oid : &commit->object.oid);
@@ -415,9 +413,6 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
415413
opt->diffopt.stat_sep = buffer;
416414
strbuf_release(&filename);
417415
}
418-
strbuf_reset(&subject);
419-
fmt_output_email_subject(&subject, opt);
420-
*subject_p = subject.buf;
421416
*extra_headers_p = extra_headers;
422417
}
423418

@@ -602,8 +597,10 @@ void show_log(struct rev_info *opt)
602597
*/
603598

604599
if (cmit_fmt_is_mail(opt->commit_format)) {
605-
log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
600+
log_write_email_headers(opt, commit, &extra_headers,
606601
&ctx.need_8bit_cte);
602+
ctx.rev = opt;
603+
ctx.print_email_subject = 1;
607604
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
608605
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), opt->diffopt.file);
609606
if (opt->commit_format != CMIT_FMT_ONELINE)

log-tree.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ void format_decorations_extended(struct strbuf *sb, const struct commit *commit,
2222
format_decorations_extended((strbuf), (commit), (color), " (", ", ", ")")
2323
void show_decorations(struct rev_info *opt, struct commit *commit);
2424
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
25-
const char **subject_p,
2625
const char **extra_headers_p,
2726
int *need_8bit_cte_p);
2827
void load_ref_decorations(int flags);

pretty.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,8 +1590,9 @@ void pp_title_line(struct pretty_print_context *pp,
15901590
pp->preserve_subject ? "\n" : " ");
15911591

15921592
strbuf_grow(sb, title.len + 1024);
1593-
if (pp->subject) {
1594-
strbuf_addstr(sb, pp->subject);
1593+
if (pp->print_email_subject) {
1594+
if (pp->rev)
1595+
fmt_output_email_subject(sb, pp->rev);
15951596
if (needs_rfc2047_encoding(title.buf, title.len, RFC2047_SUBJECT))
15961597
add_rfc2047(sb, title.buf, title.len,
15971598
encoding, RFC2047_SUBJECT);
@@ -1801,7 +1802,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
18011802
}
18021803

18031804
pp_header(pp, encoding, commit, &msg, sb);
1804-
if (pp->fmt != CMIT_FMT_ONELINE && !pp->subject) {
1805+
if (pp->fmt != CMIT_FMT_ONELINE && !pp->print_email_subject) {
18051806
strbuf_addch(sb, '\n');
18061807
}
18071808

0 commit comments

Comments
 (0)