Skip to content

Commit 0a24610

Browse files
committed
Merge branch 'rs/log-email-subject'
Code clean-up. * rs/log-email-subject: pretty: use fmt_output_email_subject() log-tree: factor out fmt_output_email_subject()
2 parents 44c3f09 + 6d167fd commit 0a24610

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
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
@@ -148,7 +148,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
148148

149149
ctx.fmt = CMIT_FMT_USERFORMAT;
150150
ctx.abbrev = log->abbrev;
151-
ctx.subject = "";
151+
ctx.print_email_subject = 1;
152152
ctx.after_subject = "";
153153
ctx.date_mode.type = DATE_NORMAL;
154154
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: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -332,35 +332,31 @@ 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,
336-
const char **subject_p,
337352
const char **extra_headers_p,
338353
int *need_8bit_cte_p)
339354
{
340-
const char *subject = NULL;
341355
const char *extra_headers = opt->extra_headers;
342356
const char *name = oid_to_hex(opt->zero_commit ?
343357
&null_oid : &commit->object.oid);
344358

345359
*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-
}
364360

365361
fprintf(opt->diffopt.file, "From %s Mon Sep 17 00:00:00 2001\n", name);
366362
graph_show_oneline(opt->graph);
@@ -417,7 +413,6 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
417413
opt->diffopt.stat_sep = buffer;
418414
strbuf_release(&filename);
419415
}
420-
*subject_p = subject;
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ 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);
2928

3029
#define FORMAT_PATCH_NAME_MAX 64
3130
void fmt_output_commit(struct strbuf *, struct commit *, struct rev_info *);
3231
void fmt_output_subject(struct strbuf *, const char *subject, struct rev_info *);
32+
void fmt_output_email_subject(struct strbuf *, struct rev_info *);
3333

3434
#endif

pretty.c

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

16091609
strbuf_grow(sb, title.len + 1024);
1610-
if (pp->subject) {
1611-
strbuf_addstr(sb, pp->subject);
1610+
if (pp->print_email_subject) {
1611+
if (pp->rev)
1612+
fmt_output_email_subject(sb, pp->rev);
16121613
if (needs_rfc2047_encoding(title.buf, title.len, RFC2047_SUBJECT))
16131614
add_rfc2047(sb, title.buf, title.len,
16141615
encoding, RFC2047_SUBJECT);
@@ -1818,7 +1819,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
18181819
}
18191820

18201821
pp_header(pp, encoding, commit, &msg, sb);
1821-
if (pp->fmt != CMIT_FMT_ONELINE && !pp->subject) {
1822+
if (pp->fmt != CMIT_FMT_ONELINE && !pp->print_email_subject) {
18221823
strbuf_addch(sb, '\n');
18231824
}
18241825

0 commit comments

Comments
 (0)