Skip to content

Commit d5a90d6

Browse files
peffgitster
authored andcommitted
pretty: drop print_email_subject flag
With one exception, the print_email_subject flag is set if and only if the commit format is email based: - in make_cover_letter() we set it along with CMIT_FMT_EMAIL explicitly - in show_log(), we set it if cmit_fmt_is_mail() is true. That covers format-patch as well as "git log --format=email" (or mboxrd). The one exception is "rev-list --format=email", which somewhat nonsensically prints the author and date as email headers, but no subject, like: $ git rev-list --format=email HEAD commit 64fc4c2cdd4db2645eaabb47aa4bac820b03cdba From: Jeff King <[email protected]> Date: Tue, 19 Mar 2024 19:39:26 -0400 this is the subject this is the body It's doubtful that this is a useful format at all (the "commit" lines replace the "From" lines that would make it work as an actual mbox). But I think that printing the subject as a header (like this patch does) is the least surprising thing to do. So let's drop this field, making the code a little simpler and easier to reason about. Note that we do need to set the "rev" field of the pretty_print_context in rev-list, since that is used to check for subject_prefix, etc. It's not possible to set those fields via rev-list, so we'll always just print "Subject: ". But unless we pass in our rev_info, fmt_output_email_subject() would segfault trying to figure it out. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 69aff62 commit d5a90d6

File tree

5 files changed

+9
-16
lines changed

5 files changed

+9
-16
lines changed

builtin/log.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,6 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
13641364
pp.fmt = CMIT_FMT_EMAIL;
13651365
pp.date_mode.type = DATE_RFC2822;
13661366
pp.rev = rev;
1367-
pp.print_email_subject = 1;
13681367
pp.encode_email_headers = rev->encode_email_headers;
13691368
pp_user_info(&pp, NULL, &sb, committer, encoding);
13701369
prepare_cover_text(&pp, description_file, branch_name, &sb,

builtin/rev-list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static void show_commit(struct commit *commit, void *data)
219219
ctx.fmt = revs->commit_format;
220220
ctx.output_encoding = get_log_output_encoding();
221221
ctx.color = revs->diffopt.use_color;
222+
ctx.rev = revs;
222223
pretty_print_commit(&ctx, commit, &buf);
223224
if (buf.len) {
224225
if (revs->commit_format != CMIT_FMT_ONELINE)

log-tree.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,6 @@ void show_log(struct rev_info *opt)
742742
log_write_email_headers(opt, commit, &extra_headers,
743743
&ctx.need_8bit_cte, 1);
744744
ctx.rev = opt;
745-
ctx.print_email_subject = 1;
746745
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
747746
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), opt->diffopt.file);
748747
if (opt->commit_format != CMIT_FMT_ONELINE)

pretty.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,19 +2091,14 @@ void pp_email_subject(struct pretty_print_context *pp,
20912091
pp->preserve_subject ? "\n" : " ");
20922092

20932093
strbuf_grow(sb, title.len + 1024);
2094-
if (pp->print_email_subject) {
2095-
if (pp->rev)
2096-
fmt_output_email_subject(sb, pp->rev);
2097-
if (pp->encode_email_headers &&
2098-
needs_rfc2047_encoding(title.buf, title.len))
2099-
add_rfc2047(sb, title.buf, title.len,
2100-
encoding, RFC2047_SUBJECT);
2101-
else
2102-
strbuf_add_wrapped_bytes(sb, title.buf, title.len,
2094+
fmt_output_email_subject(sb, pp->rev);
2095+
if (pp->encode_email_headers &&
2096+
needs_rfc2047_encoding(title.buf, title.len))
2097+
add_rfc2047(sb, title.buf, title.len,
2098+
encoding, RFC2047_SUBJECT);
2099+
else
2100+
strbuf_add_wrapped_bytes(sb, title.buf, title.len,
21032101
-last_line_length(sb), 1, max_length);
2104-
} else {
2105-
strbuf_addbuf(sb, &title);
2106-
}
21072102
strbuf_addch(sb, '\n');
21082103

21092104
if (need_8bit_cte == 0) {
@@ -2319,7 +2314,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
23192314
}
23202315

23212316
pp_header(pp, encoding, commit, &msg, sb);
2322-
if (pp->fmt != CMIT_FMT_ONELINE && !pp->print_email_subject) {
2317+
if (pp->fmt != CMIT_FMT_ONELINE && !cmit_fmt_is_mail(pp->fmt)) {
23232318
strbuf_addch(sb, '\n');
23242319
}
23252320

pretty.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct pretty_print_context {
3939
int preserve_subject;
4040
struct date_mode date_mode;
4141
unsigned date_mode_explicit:1;
42-
int print_email_subject;
4342
int expand_tabs_in_log;
4443
int need_8bit_cte;
4544
char *notes_message;

0 commit comments

Comments
 (0)