mirror of
https://github.com/git/git
synced 2024-10-01 06:05:20 +00:00
Merge branch 'jk/pretty-subject-cleanup'
Code clean-up in the "git log" machinery that implements custom log message formatting. * jk/pretty-subject-cleanup: format-patch: fix leak of empty header string format-patch: simplify after-subject MIME header handling format-patch: return an allocated string from log_write_email_headers() log: do not set up extra_headers for non-email formats pretty: drop print_email_subject flag pretty: split oneline and email subject printing shortlog: stop setting pp.print_email_subject
This commit is contained in:
commit
a031815a7d
|
@ -1297,7 +1297,7 @@ static void prepare_cover_text(struct pretty_print_context *pp,
|
||||||
subject = subject_sb.buf;
|
subject = subject_sb.buf;
|
||||||
|
|
||||||
do_pp:
|
do_pp:
|
||||||
pp_title_line(pp, &subject, sb, encoding, need_8bit_cte);
|
pp_email_subject(pp, &subject, sb, encoding, need_8bit_cte);
|
||||||
pp_remainder(pp, &body, sb, 0);
|
pp_remainder(pp, &body, sb, 0);
|
||||||
|
|
||||||
strbuf_release(&description_sb);
|
strbuf_release(&description_sb);
|
||||||
|
@ -1364,13 +1364,13 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
|
||||||
pp.fmt = CMIT_FMT_EMAIL;
|
pp.fmt = CMIT_FMT_EMAIL;
|
||||||
pp.date_mode.type = DATE_RFC2822;
|
pp.date_mode.type = DATE_RFC2822;
|
||||||
pp.rev = rev;
|
pp.rev = rev;
|
||||||
pp.print_email_subject = 1;
|
|
||||||
pp.encode_email_headers = rev->encode_email_headers;
|
pp.encode_email_headers = rev->encode_email_headers;
|
||||||
pp_user_info(&pp, NULL, &sb, committer, encoding);
|
pp_user_info(&pp, NULL, &sb, committer, encoding);
|
||||||
prepare_cover_text(&pp, description_file, branch_name, &sb,
|
prepare_cover_text(&pp, description_file, branch_name, &sb,
|
||||||
encoding, need_8bit_cte);
|
encoding, need_8bit_cte);
|
||||||
fprintf(rev->diffopt.file, "%s\n", sb.buf);
|
fprintf(rev->diffopt.file, "%s\n", sb.buf);
|
||||||
|
|
||||||
|
free(pp.after_subject);
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
|
|
||||||
shortlog_init(&log);
|
shortlog_init(&log);
|
||||||
|
|
|
@ -219,6 +219,7 @@ static void show_commit(struct commit *commit, void *data)
|
||||||
ctx.fmt = revs->commit_format;
|
ctx.fmt = revs->commit_format;
|
||||||
ctx.output_encoding = get_log_output_encoding();
|
ctx.output_encoding = get_log_output_encoding();
|
||||||
ctx.color = revs->diffopt.use_color;
|
ctx.color = revs->diffopt.use_color;
|
||||||
|
ctx.rev = revs;
|
||||||
pretty_print_commit(&ctx, commit, &buf);
|
pretty_print_commit(&ctx, commit, &buf);
|
||||||
if (buf.len) {
|
if (buf.len) {
|
||||||
if (revs->commit_format != CMIT_FMT_ONELINE)
|
if (revs->commit_format != CMIT_FMT_ONELINE)
|
||||||
|
|
|
@ -245,7 +245,6 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
|
||||||
|
|
||||||
ctx.fmt = CMIT_FMT_USERFORMAT;
|
ctx.fmt = CMIT_FMT_USERFORMAT;
|
||||||
ctx.abbrev = log->abbrev;
|
ctx.abbrev = log->abbrev;
|
||||||
ctx.print_email_subject = 1;
|
|
||||||
ctx.date_mode = log->date_mode;
|
ctx.date_mode = log->date_mode;
|
||||||
ctx.output_encoding = get_log_output_encoding();
|
ctx.output_encoding = get_log_output_encoding();
|
||||||
|
|
||||||
|
|
22
log-tree.c
22
log-tree.c
|
@ -470,16 +470,19 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
|
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
|
||||||
const char **extra_headers_p,
|
char **extra_headers_p,
|
||||||
int *need_8bit_cte_p,
|
int *need_8bit_cte_p,
|
||||||
int maybe_multipart)
|
int maybe_multipart)
|
||||||
{
|
{
|
||||||
const char *extra_headers = opt->extra_headers;
|
struct strbuf headers = STRBUF_INIT;
|
||||||
const char *name = oid_to_hex(opt->zero_commit ?
|
const char *name = oid_to_hex(opt->zero_commit ?
|
||||||
null_oid() : &commit->object.oid);
|
null_oid() : &commit->object.oid);
|
||||||
|
|
||||||
*need_8bit_cte_p = 0; /* unknown */
|
*need_8bit_cte_p = 0; /* unknown */
|
||||||
|
|
||||||
|
if (opt->extra_headers && *opt->extra_headers)
|
||||||
|
strbuf_addstr(&headers, opt->extra_headers);
|
||||||
|
|
||||||
fprintf(opt->diffopt.file, "From %s Mon Sep 17 00:00:00 2001\n", name);
|
fprintf(opt->diffopt.file, "From %s Mon Sep 17 00:00:00 2001\n", name);
|
||||||
graph_show_oneline(opt->graph);
|
graph_show_oneline(opt->graph);
|
||||||
if (opt->message_id) {
|
if (opt->message_id) {
|
||||||
|
@ -496,16 +499,13 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
|
||||||
graph_show_oneline(opt->graph);
|
graph_show_oneline(opt->graph);
|
||||||
}
|
}
|
||||||
if (opt->mime_boundary && maybe_multipart) {
|
if (opt->mime_boundary && maybe_multipart) {
|
||||||
static struct strbuf subject_buffer = STRBUF_INIT;
|
|
||||||
static struct strbuf buffer = STRBUF_INIT;
|
static struct strbuf buffer = STRBUF_INIT;
|
||||||
struct strbuf filename = STRBUF_INIT;
|
struct strbuf filename = STRBUF_INIT;
|
||||||
*need_8bit_cte_p = -1; /* NEVER */
|
*need_8bit_cte_p = -1; /* NEVER */
|
||||||
|
|
||||||
strbuf_reset(&subject_buffer);
|
|
||||||
strbuf_reset(&buffer);
|
strbuf_reset(&buffer);
|
||||||
|
|
||||||
strbuf_addf(&subject_buffer,
|
strbuf_addf(&headers,
|
||||||
"%s"
|
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: multipart/mixed;"
|
"Content-Type: multipart/mixed;"
|
||||||
" boundary=\"%s%s\"\n"
|
" boundary=\"%s%s\"\n"
|
||||||
|
@ -516,10 +516,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
|
||||||
"Content-Type: text/plain; "
|
"Content-Type: text/plain; "
|
||||||
"charset=UTF-8; format=fixed\n"
|
"charset=UTF-8; format=fixed\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n\n",
|
"Content-Transfer-Encoding: 8bit\n\n",
|
||||||
extra_headers ? extra_headers : "",
|
|
||||||
mime_boundary_leader, opt->mime_boundary,
|
mime_boundary_leader, opt->mime_boundary,
|
||||||
mime_boundary_leader, opt->mime_boundary);
|
mime_boundary_leader, opt->mime_boundary);
|
||||||
extra_headers = subject_buffer.buf;
|
|
||||||
|
|
||||||
if (opt->numbered_files)
|
if (opt->numbered_files)
|
||||||
strbuf_addf(&filename, "%d", opt->nr);
|
strbuf_addf(&filename, "%d", opt->nr);
|
||||||
|
@ -539,7 +537,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
|
||||||
opt->diffopt.stat_sep = buffer.buf;
|
opt->diffopt.stat_sep = buffer.buf;
|
||||||
strbuf_release(&filename);
|
strbuf_release(&filename);
|
||||||
}
|
}
|
||||||
*extra_headers_p = extra_headers;
|
*extra_headers_p = headers.len ? strbuf_detach(&headers, NULL) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
|
static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
|
||||||
|
@ -678,7 +676,6 @@ void show_log(struct rev_info *opt)
|
||||||
struct log_info *log = opt->loginfo;
|
struct log_info *log = opt->loginfo;
|
||||||
struct commit *commit = log->commit, *parent = log->parent;
|
struct commit *commit = log->commit, *parent = log->parent;
|
||||||
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : the_hash_algo->hexsz;
|
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : the_hash_algo->hexsz;
|
||||||
const char *extra_headers = opt->extra_headers;
|
|
||||||
struct pretty_print_context ctx = {0};
|
struct pretty_print_context ctx = {0};
|
||||||
|
|
||||||
opt->loginfo = NULL;
|
opt->loginfo = NULL;
|
||||||
|
@ -739,10 +736,9 @@ void show_log(struct rev_info *opt)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (cmit_fmt_is_mail(opt->commit_format)) {
|
if (cmit_fmt_is_mail(opt->commit_format)) {
|
||||||
log_write_email_headers(opt, commit, &extra_headers,
|
log_write_email_headers(opt, commit, &ctx.after_subject,
|
||||||
&ctx.need_8bit_cte, 1);
|
&ctx.need_8bit_cte, 1);
|
||||||
ctx.rev = opt;
|
ctx.rev = opt;
|
||||||
ctx.print_email_subject = 1;
|
|
||||||
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
|
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
|
||||||
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), opt->diffopt.file);
|
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), opt->diffopt.file);
|
||||||
if (opt->commit_format != CMIT_FMT_ONELINE)
|
if (opt->commit_format != CMIT_FMT_ONELINE)
|
||||||
|
@ -808,7 +804,6 @@ void show_log(struct rev_info *opt)
|
||||||
ctx.date_mode = opt->date_mode;
|
ctx.date_mode = opt->date_mode;
|
||||||
ctx.date_mode_explicit = opt->date_mode_explicit;
|
ctx.date_mode_explicit = opt->date_mode_explicit;
|
||||||
ctx.abbrev = opt->diffopt.abbrev;
|
ctx.abbrev = opt->diffopt.abbrev;
|
||||||
ctx.after_subject = extra_headers;
|
|
||||||
ctx.preserve_subject = opt->preserve_subject;
|
ctx.preserve_subject = opt->preserve_subject;
|
||||||
ctx.encode_email_headers = opt->encode_email_headers;
|
ctx.encode_email_headers = opt->encode_email_headers;
|
||||||
ctx.reflog_info = opt->reflog_info;
|
ctx.reflog_info = opt->reflog_info;
|
||||||
|
@ -857,6 +852,7 @@ void show_log(struct rev_info *opt)
|
||||||
|
|
||||||
strbuf_release(&msgbuf);
|
strbuf_release(&msgbuf);
|
||||||
free(ctx.notes_message);
|
free(ctx.notes_message);
|
||||||
|
free(ctx.after_subject);
|
||||||
|
|
||||||
if (cmit_fmt_is_mail(ctx.fmt) && opt->idiff_oid1) {
|
if (cmit_fmt_is_mail(ctx.fmt) && opt->idiff_oid1) {
|
||||||
struct diff_queue_struct dq;
|
struct diff_queue_struct dq;
|
||||||
|
|
|
@ -29,7 +29,7 @@ void format_decorations(struct strbuf *sb, const struct commit *commit,
|
||||||
int use_color, const struct decoration_options *opts);
|
int use_color, const struct decoration_options *opts);
|
||||||
void show_decorations(struct rev_info *opt, struct commit *commit);
|
void show_decorations(struct rev_info *opt, struct commit *commit);
|
||||||
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
|
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
|
||||||
const char **extra_headers_p,
|
char **extra_headers_p,
|
||||||
int *need_8bit_cte_p,
|
int *need_8bit_cte_p,
|
||||||
int maybe_multipart);
|
int maybe_multipart);
|
||||||
void load_ref_decorations(struct decoration_filter *filter, int flags);
|
void load_ref_decorations(struct decoration_filter *filter, int flags);
|
||||||
|
|
43
pretty.c
43
pretty.c
|
@ -2077,11 +2077,11 @@ static void pp_header(struct pretty_print_context *pp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pp_title_line(struct pretty_print_context *pp,
|
void pp_email_subject(struct pretty_print_context *pp,
|
||||||
const char **msg_p,
|
const char **msg_p,
|
||||||
struct strbuf *sb,
|
struct strbuf *sb,
|
||||||
const char *encoding,
|
const char *encoding,
|
||||||
int need_8bit_cte)
|
int need_8bit_cte)
|
||||||
{
|
{
|
||||||
static const int max_length = 78; /* per rfc2047 */
|
static const int max_length = 78; /* per rfc2047 */
|
||||||
struct strbuf title;
|
struct strbuf title;
|
||||||
|
@ -2091,19 +2091,14 @@ void pp_title_line(struct pretty_print_context *pp,
|
||||||
pp->preserve_subject ? "\n" : " ");
|
pp->preserve_subject ? "\n" : " ");
|
||||||
|
|
||||||
strbuf_grow(sb, title.len + 1024);
|
strbuf_grow(sb, title.len + 1024);
|
||||||
if (pp->print_email_subject) {
|
fmt_output_email_subject(sb, pp->rev);
|
||||||
if (pp->rev)
|
if (pp->encode_email_headers &&
|
||||||
fmt_output_email_subject(sb, pp->rev);
|
needs_rfc2047_encoding(title.buf, title.len))
|
||||||
if (pp->encode_email_headers &&
|
add_rfc2047(sb, title.buf, title.len,
|
||||||
needs_rfc2047_encoding(title.buf, title.len))
|
encoding, RFC2047_SUBJECT);
|
||||||
add_rfc2047(sb, title.buf, title.len,
|
else
|
||||||
encoding, RFC2047_SUBJECT);
|
strbuf_add_wrapped_bytes(sb, title.buf, title.len,
|
||||||
else
|
|
||||||
strbuf_add_wrapped_bytes(sb, title.buf, title.len,
|
|
||||||
-last_line_length(sb), 1, max_length);
|
-last_line_length(sb), 1, max_length);
|
||||||
} else {
|
|
||||||
strbuf_addbuf(sb, &title);
|
|
||||||
}
|
|
||||||
strbuf_addch(sb, '\n');
|
strbuf_addch(sb, '\n');
|
||||||
|
|
||||||
if (need_8bit_cte == 0) {
|
if (need_8bit_cte == 0) {
|
||||||
|
@ -2126,9 +2121,8 @@ void pp_title_line(struct pretty_print_context *pp,
|
||||||
if (pp->after_subject) {
|
if (pp->after_subject) {
|
||||||
strbuf_addstr(sb, pp->after_subject);
|
strbuf_addstr(sb, pp->after_subject);
|
||||||
}
|
}
|
||||||
if (cmit_fmt_is_mail(pp->fmt)) {
|
|
||||||
strbuf_addch(sb, '\n');
|
strbuf_addch(sb, '\n');
|
||||||
}
|
|
||||||
|
|
||||||
if (pp->in_body_headers.nr) {
|
if (pp->in_body_headers.nr) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -2320,7 +2314,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
|
||||||
}
|
}
|
||||||
|
|
||||||
pp_header(pp, encoding, commit, &msg, sb);
|
pp_header(pp, encoding, commit, &msg, sb);
|
||||||
if (pp->fmt != CMIT_FMT_ONELINE && !pp->print_email_subject) {
|
if (pp->fmt != CMIT_FMT_ONELINE && !cmit_fmt_is_mail(pp->fmt)) {
|
||||||
strbuf_addch(sb, '\n');
|
strbuf_addch(sb, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2328,8 +2322,11 @@ void pretty_print_commit(struct pretty_print_context *pp,
|
||||||
msg = skip_blank_lines(msg);
|
msg = skip_blank_lines(msg);
|
||||||
|
|
||||||
/* These formats treat the title line specially. */
|
/* These formats treat the title line specially. */
|
||||||
if (pp->fmt == CMIT_FMT_ONELINE || cmit_fmt_is_mail(pp->fmt))
|
if (pp->fmt == CMIT_FMT_ONELINE) {
|
||||||
pp_title_line(pp, &msg, sb, encoding, need_8bit_cte);
|
msg = format_subject(sb, msg, " ");
|
||||||
|
strbuf_addch(sb, '\n');
|
||||||
|
} else if (cmit_fmt_is_mail(pp->fmt))
|
||||||
|
pp_email_subject(pp, &msg, sb, encoding, need_8bit_cte);
|
||||||
|
|
||||||
beginning_of_body = sb->len;
|
beginning_of_body = sb->len;
|
||||||
if (pp->fmt != CMIT_FMT_ONELINE)
|
if (pp->fmt != CMIT_FMT_ONELINE)
|
||||||
|
|
11
pretty.h
11
pretty.h
|
@ -35,11 +35,10 @@ struct pretty_print_context {
|
||||||
*/
|
*/
|
||||||
enum cmit_fmt fmt;
|
enum cmit_fmt fmt;
|
||||||
int abbrev;
|
int abbrev;
|
||||||
const char *after_subject;
|
char *after_subject;
|
||||||
int preserve_subject;
|
int preserve_subject;
|
||||||
struct date_mode date_mode;
|
struct date_mode date_mode;
|
||||||
unsigned date_mode_explicit:1;
|
unsigned date_mode_explicit:1;
|
||||||
int print_email_subject;
|
|
||||||
int expand_tabs_in_log;
|
int expand_tabs_in_log;
|
||||||
int need_8bit_cte;
|
int need_8bit_cte;
|
||||||
char *notes_message;
|
char *notes_message;
|
||||||
|
@ -96,13 +95,13 @@ void pp_user_info(struct pretty_print_context *pp, const char *what,
|
||||||
const char *encoding);
|
const char *encoding);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Format title line of commit message taken from "msg_p" and
|
* Format subject line of commit message taken from "msg_p" and
|
||||||
* put it into "sb".
|
* put it into "sb".
|
||||||
* First line of "msg_p" is also affected.
|
* First line of "msg_p" is also affected.
|
||||||
*/
|
*/
|
||||||
void pp_title_line(struct pretty_print_context *pp, const char **msg_p,
|
void pp_email_subject(struct pretty_print_context *pp, const char **msg_p,
|
||||||
struct strbuf *sb, const char *encoding,
|
struct strbuf *sb, const char *encoding,
|
||||||
int need_8bit_cte);
|
int need_8bit_cte);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get current state of commit message from "msg_p" and continue formatting
|
* Get current state of commit message from "msg_p" and continue formatting
|
||||||
|
|
Loading…
Reference in a new issue