Skip to content

Commit f67d2e8

Browse files
committed
Merge branch 'jk/format-patch-am'
* jk/format-patch-am: format-patch: preserve subject newlines with -k clean up calling conventions for pretty.c functions pretty: add pp_commit_easy function for simple callers mailinfo: always clean up rfc822 header folding t: test subject handling in format-patch / am pipeline Conflicts: builtin/branch.c builtin/log.c commit.h
2 parents 1c9d719 + 9553d2b commit f67d2e8

File tree

13 files changed

+174
-92
lines changed

13 files changed

+174
-92
lines changed

builtin/branch.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item,
399399
struct commit *commit = item->commit;
400400

401401
if (commit && !parse_commit(commit)) {
402-
struct pretty_print_context ctx = {0};
403-
pretty_print_commit(CMIT_FMT_ONELINE, commit,
404-
&subject, &ctx);
402+
pp_commit_easy(CMIT_FMT_ONELINE, commit, &subject);
405403
sub = subject.buf;
406404
}
407405

builtin/checkout.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,8 @@ static void show_local_changes(struct object *head, struct diff_options *opts)
306306
static void describe_detached_head(const char *msg, struct commit *commit)
307307
{
308308
struct strbuf sb = STRBUF_INIT;
309-
struct pretty_print_context ctx = {0};
310309
parse_commit(commit);
311-
pretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, &ctx);
310+
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
312311
fprintf(stderr, "%s %s... %s\n", msg,
313312
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
314313
strbuf_release(&sb);
@@ -623,14 +622,12 @@ static int clear_commit_marks_from_one_ref(const char *refname,
623622

624623
static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
625624
{
626-
struct pretty_print_context ctx = { 0 };
627-
628625
parse_commit(commit);
629626
strbuf_addstr(sb, " ");
630627
strbuf_addstr(sb,
631628
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
632629
strbuf_addch(sb, ' ');
633-
pretty_print_commit(CMIT_FMT_ONELINE, commit, sb, &ctx);
630+
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
634631
strbuf_addch(sb, '\n');
635632
}
636633

builtin/log.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,11 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
376376
static void show_tagger(char *buf, int len, struct rev_info *rev)
377377
{
378378
struct strbuf out = STRBUF_INIT;
379+
struct pretty_print_context pp = {0};
379380

380-
pp_user_info("Tagger", rev->commit_format, &out, buf, rev->date_mode,
381-
get_log_output_encoding());
381+
pp.fmt = rev->commit_format;
382+
pp.date_mode = rev->date_mode;
383+
pp_user_info(&pp, "Tagger", &out, buf, get_log_output_encoding());
382384
printf("%s", out.buf);
383385
strbuf_release(&out);
384386
}
@@ -762,17 +764,16 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
762764
int quiet)
763765
{
764766
const char *committer;
765-
const char *subject_start = NULL;
766767
const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n";
767768
const char *msg;
768-
const char *extra_headers = rev->extra_headers;
769769
struct shortlog log;
770770
struct strbuf sb = STRBUF_INIT;
771771
int i;
772772
const char *encoding = "UTF-8";
773773
struct diff_options opts;
774774
int need_8bit_cte = 0;
775775
struct commit *commit = NULL;
776+
struct pretty_print_context pp = {0};
776777

777778
if (rev->commit_format != CMIT_FMT_EMAIL)
778779
die(_("Cover letter needs email format"));
@@ -804,19 +805,19 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
804805
free(commit);
805806
}
806807

807-
log_write_email_headers(rev, head, &subject_start, &extra_headers,
808+
log_write_email_headers(rev, head, &pp.subject, &pp.after_subject,
808809
&need_8bit_cte);
809810

810811
for (i = 0; !need_8bit_cte && i < nr; i++)
811812
if (has_non_ascii(list[i]->buffer))
812813
need_8bit_cte = 1;
813814

814815
msg = body;
815-
pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822,
816-
encoding);
817-
pp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers,
818-
encoding, need_8bit_cte);
819-
pp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0);
816+
pp.fmt = CMIT_FMT_EMAIL;
817+
pp.date_mode = DATE_RFC2822;
818+
pp_user_info(&pp, NULL, &sb, committer, encoding);
819+
pp_title_line(&pp, &msg, &sb, encoding, need_8bit_cte);
820+
pp_remainder(&pp, &msg, &sb, 0);
820821
printf("%s\n", sb.buf);
821822

822823
strbuf_release(&sb);
@@ -1180,6 +1181,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
11801181
die (_("-n and -k are mutually exclusive."));
11811182
if (keep_subject && subject_prefix)
11821183
die (_("--subject-prefix and -k are mutually exclusive."));
1184+
rev.preserve_subject = keep_subject;
11831185

11841186
argc = setup_revisions(argc, argv, &rev, &s_r_opt);
11851187
if (argc > 1)
@@ -1410,8 +1412,7 @@ static void print_commit(char sign, struct commit *commit, int verbose,
14101412
find_unique_abbrev(commit->object.sha1, abbrev));
14111413
} else {
14121414
struct strbuf buf = STRBUF_INIT;
1413-
struct pretty_print_context ctx = {0};
1414-
pretty_print_commit(CMIT_FMT_ONELINE, commit, &buf, &ctx);
1415+
pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
14151416
printf("%c %s %s\n", sign,
14161417
find_unique_abbrev(commit->object.sha1, abbrev),
14171418
buf.buf);

builtin/mailinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static int read_one_header_line(struct strbuf *line, FILE *in)
400400
break;
401401
if (strbuf_getline(&continuation, in, '\n'))
402402
break;
403-
continuation.buf[0] = '\n';
403+
continuation.buf[0] = ' ';
404404
strbuf_rtrim(&continuation);
405405
strbuf_addbuf(line, &continuation);
406406
}

builtin/merge.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,14 @@ static void squash_message(void)
339339

340340
ctx.abbrev = rev.abbrev;
341341
ctx.date_mode = rev.date_mode;
342+
ctx.fmt = rev.commit_format;
342343

343344
strbuf_addstr(&out, "Squashed commit of the following:\n");
344345
while ((commit = get_revision(&rev)) != NULL) {
345346
strbuf_addch(&out, '\n');
346347
strbuf_addf(&out, "commit %s\n",
347348
sha1_to_hex(commit->object.sha1));
348-
pretty_print_commit(rev.commit_format, commit, &out, &ctx);
349+
pretty_print_commit(&ctx, commit, &out);
349350
}
350351
if (write(fd, out.buf, out.len) < 0)
351352
die_errno(_("Writing SQUASH_MSG"));

builtin/rev-list.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ static void show_commit(struct commit *commit, void *data)
104104
struct pretty_print_context ctx = {0};
105105
ctx.abbrev = revs->abbrev;
106106
ctx.date_mode = revs->date_mode;
107-
pretty_print_commit(revs->commit_format, commit, &buf, &ctx);
107+
ctx.fmt = revs->commit_format;
108+
pretty_print_commit(&ctx, commit, &buf);
108109
if (revs->graph) {
109110
if (buf.len) {
110111
if (revs->commit_format != CMIT_FMT_ONELINE)

builtin/shortlog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,8 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
138138
const char *author = NULL, *buffer;
139139
struct strbuf buf = STRBUF_INIT;
140140
struct strbuf ufbuf = STRBUF_INIT;
141-
struct pretty_print_context ctx = {0};
142141

143-
pretty_print_commit(CMIT_FMT_RAW, commit, &buf, &ctx);
142+
pp_commit_easy(CMIT_FMT_RAW, commit, &buf);
144143
buffer = buf.buf;
145144
while (*buffer && *buffer != '\n') {
146145
const char *eol = strchr(buffer, '\n');
@@ -159,11 +158,12 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
159158
sha1_to_hex(commit->object.sha1));
160159
if (log->user_format) {
161160
struct pretty_print_context ctx = {0};
161+
ctx.fmt = CMIT_FMT_USERFORMAT;
162162
ctx.abbrev = log->abbrev;
163163
ctx.subject = "";
164164
ctx.after_subject = "";
165165
ctx.date_mode = DATE_NORMAL;
166-
pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &ufbuf, &ctx);
166+
pretty_print_commit(&ctx, commit, &ufbuf);
167167
buffer = ufbuf.buf;
168168
} else if (*buffer) {
169169
buffer++;

builtin/show-branch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ static void show_one_commit(struct commit *commit, int no_name)
283283
struct commit_name *name = commit->util;
284284

285285
if (commit->object.parsed) {
286-
struct pretty_print_context ctx = {0};
287-
pretty_print_commit(CMIT_FMT_ONELINE, commit, &pretty, &ctx);
286+
pp_commit_easy(CMIT_FMT_ONELINE, commit, &pretty);
288287
pretty_str = pretty.buf;
289288
}
290289
if (!prefixcmp(pretty_str, "[PATCH] "))

commit.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ enum cmit_fmt {
6969
};
7070

7171
struct pretty_print_context {
72+
enum cmit_fmt fmt;
7273
int abbrev;
7374
const char *subject;
7475
const char *after_subject;
76+
int preserve_subject;
7577
enum date_mode date_mode;
7678
int need_8bit_cte;
7779
int show_notes;
@@ -96,20 +98,20 @@ extern void userformat_find_requirements(const char *fmt, struct userformat_want
9698
extern void format_commit_message(const struct commit *commit,
9799
const char *format, struct strbuf *sb,
98100
const struct pretty_print_context *context);
99-
extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
100-
struct strbuf *sb,
101-
const struct pretty_print_context *context);
102-
void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
103-
const char *line, enum date_mode dmode,
104-
const char *encoding);
105-
void pp_title_line(enum cmit_fmt fmt,
101+
extern void pretty_print_commit(const struct pretty_print_context *pp,
102+
const struct commit *commit,
103+
struct strbuf *sb);
104+
extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
105+
struct strbuf *sb);
106+
void pp_user_info(const struct pretty_print_context *pp,
107+
const char *what, struct strbuf *sb,
108+
const char *line, const char *encoding);
109+
void pp_title_line(const struct pretty_print_context *pp,
106110
const char **msg_p,
107111
struct strbuf *sb,
108-
const char *subject,
109-
const char *after_subject,
110112
const char *encoding,
111113
int need_8bit_cte);
112-
void pp_remainder(enum cmit_fmt fmt,
114+
void pp_remainder(const struct pretty_print_context *pp,
113115
const char **msg_p,
114116
struct strbuf *sb,
115117
int indent);

log-tree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,10 @@ void show_log(struct rev_info *opt)
485485
ctx.date_mode = opt->date_mode;
486486
ctx.abbrev = opt->diffopt.abbrev;
487487
ctx.after_subject = extra_headers;
488+
ctx.preserve_subject = opt->preserve_subject;
488489
ctx.reflog_info = opt->reflog_info;
489-
pretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx);
490+
ctx.fmt = opt->commit_format;
491+
pretty_print_commit(&ctx, commit, &msgbuf);
490492

491493
if (opt->add_signoff)
492494
append_signoff(&msgbuf, opt->add_signoff);

0 commit comments

Comments
 (0)