Skip to content

Commit

Permalink
Merge branch 'jk/format-patch-am'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed May 31, 2011
2 parents 1c9d719 + 9553d2b commit f67d2e8
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 92 deletions.
4 changes: 1 addition & 3 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item,
struct commit *commit = item->commit;

if (commit && !parse_commit(commit)) {
struct pretty_print_context ctx = {0};
pretty_print_commit(CMIT_FMT_ONELINE, commit,
&subject, &ctx);
pp_commit_easy(CMIT_FMT_ONELINE, commit, &subject);
sub = subject.buf;
}

Expand Down
7 changes: 2 additions & 5 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,8 @@ static void show_local_changes(struct object *head, struct diff_options *opts)
static void describe_detached_head(const char *msg, struct commit *commit)
{
struct strbuf sb = STRBUF_INIT;
struct pretty_print_context ctx = {0};
parse_commit(commit);
pretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, &ctx);
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
fprintf(stderr, "%s %s... %s\n", msg,
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
strbuf_release(&sb);
Expand Down Expand Up @@ -623,14 +622,12 @@ static int clear_commit_marks_from_one_ref(const char *refname,

static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
{
struct pretty_print_context ctx = { 0 };

parse_commit(commit);
strbuf_addstr(sb, " ");
strbuf_addstr(sb,
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
strbuf_addch(sb, ' ');
pretty_print_commit(CMIT_FMT_ONELINE, commit, sb, &ctx);
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
strbuf_addch(sb, '\n');
}

Expand Down
25 changes: 13 additions & 12 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,11 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
static void show_tagger(char *buf, int len, struct rev_info *rev)
{
struct strbuf out = STRBUF_INIT;
struct pretty_print_context pp = {0};

pp_user_info("Tagger", rev->commit_format, &out, buf, rev->date_mode,
get_log_output_encoding());
pp.fmt = rev->commit_format;
pp.date_mode = rev->date_mode;
pp_user_info(&pp, "Tagger", &out, buf, get_log_output_encoding());
printf("%s", out.buf);
strbuf_release(&out);
}
Expand Down Expand Up @@ -762,17 +764,16 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
int quiet)
{
const char *committer;
const char *subject_start = NULL;
const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n";
const char *msg;
const char *extra_headers = rev->extra_headers;
struct shortlog log;
struct strbuf sb = STRBUF_INIT;
int i;
const char *encoding = "UTF-8";
struct diff_options opts;
int need_8bit_cte = 0;
struct commit *commit = NULL;
struct pretty_print_context pp = {0};

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

log_write_email_headers(rev, head, &subject_start, &extra_headers,
log_write_email_headers(rev, head, &pp.subject, &pp.after_subject,
&need_8bit_cte);

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

msg = body;
pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822,
encoding);
pp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers,
encoding, need_8bit_cte);
pp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0);
pp.fmt = CMIT_FMT_EMAIL;
pp.date_mode = DATE_RFC2822;
pp_user_info(&pp, NULL, &sb, committer, encoding);
pp_title_line(&pp, &msg, &sb, encoding, need_8bit_cte);
pp_remainder(&pp, &msg, &sb, 0);
printf("%s\n", sb.buf);

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

argc = setup_revisions(argc, argv, &rev, &s_r_opt);
if (argc > 1)
Expand Down Expand Up @@ -1410,8 +1412,7 @@ static void print_commit(char sign, struct commit *commit, int verbose,
find_unique_abbrev(commit->object.sha1, abbrev));
} else {
struct strbuf buf = STRBUF_INIT;
struct pretty_print_context ctx = {0};
pretty_print_commit(CMIT_FMT_ONELINE, commit, &buf, &ctx);
pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
printf("%c %s %s\n", sign,
find_unique_abbrev(commit->object.sha1, abbrev),
buf.buf);
Expand Down
2 changes: 1 addition & 1 deletion builtin/mailinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ static int read_one_header_line(struct strbuf *line, FILE *in)
break;
if (strbuf_getline(&continuation, in, '\n'))
break;
continuation.buf[0] = '\n';
continuation.buf[0] = ' ';
strbuf_rtrim(&continuation);
strbuf_addbuf(line, &continuation);
}
Expand Down
3 changes: 2 additions & 1 deletion builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,14 @@ static void squash_message(void)

ctx.abbrev = rev.abbrev;
ctx.date_mode = rev.date_mode;
ctx.fmt = rev.commit_format;

strbuf_addstr(&out, "Squashed commit of the following:\n");
while ((commit = get_revision(&rev)) != NULL) {
strbuf_addch(&out, '\n');
strbuf_addf(&out, "commit %s\n",
sha1_to_hex(commit->object.sha1));
pretty_print_commit(rev.commit_format, commit, &out, &ctx);
pretty_print_commit(&ctx, commit, &out);
}
if (write(fd, out.buf, out.len) < 0)
die_errno(_("Writing SQUASH_MSG"));
Expand Down
3 changes: 2 additions & 1 deletion builtin/rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ static void show_commit(struct commit *commit, void *data)
struct pretty_print_context ctx = {0};
ctx.abbrev = revs->abbrev;
ctx.date_mode = revs->date_mode;
pretty_print_commit(revs->commit_format, commit, &buf, &ctx);
ctx.fmt = revs->commit_format;
pretty_print_commit(&ctx, commit, &buf);
if (revs->graph) {
if (buf.len) {
if (revs->commit_format != CMIT_FMT_ONELINE)
Expand Down
6 changes: 3 additions & 3 deletions builtin/shortlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
const char *author = NULL, *buffer;
struct strbuf buf = STRBUF_INIT;
struct strbuf ufbuf = STRBUF_INIT;
struct pretty_print_context ctx = {0};

pretty_print_commit(CMIT_FMT_RAW, commit, &buf, &ctx);
pp_commit_easy(CMIT_FMT_RAW, commit, &buf);
buffer = buf.buf;
while (*buffer && *buffer != '\n') {
const char *eol = strchr(buffer, '\n');
Expand All @@ -159,11 +158,12 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
sha1_to_hex(commit->object.sha1));
if (log->user_format) {
struct pretty_print_context ctx = {0};
ctx.fmt = CMIT_FMT_USERFORMAT;
ctx.abbrev = log->abbrev;
ctx.subject = "";
ctx.after_subject = "";
ctx.date_mode = DATE_NORMAL;
pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &ufbuf, &ctx);
pretty_print_commit(&ctx, commit, &ufbuf);
buffer = ufbuf.buf;
} else if (*buffer) {
buffer++;
Expand Down
3 changes: 1 addition & 2 deletions builtin/show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ static void show_one_commit(struct commit *commit, int no_name)
struct commit_name *name = commit->util;

if (commit->object.parsed) {
struct pretty_print_context ctx = {0};
pretty_print_commit(CMIT_FMT_ONELINE, commit, &pretty, &ctx);
pp_commit_easy(CMIT_FMT_ONELINE, commit, &pretty);
pretty_str = pretty.buf;
}
if (!prefixcmp(pretty_str, "[PATCH] "))
Expand Down
22 changes: 12 additions & 10 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ enum cmit_fmt {
};

struct pretty_print_context {
enum cmit_fmt fmt;
int abbrev;
const char *subject;
const char *after_subject;
int preserve_subject;
enum date_mode date_mode;
int need_8bit_cte;
int show_notes;
Expand All @@ -96,20 +98,20 @@ extern void userformat_find_requirements(const char *fmt, struct userformat_want
extern void format_commit_message(const struct commit *commit,
const char *format, struct strbuf *sb,
const struct pretty_print_context *context);
extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
struct strbuf *sb,
const struct pretty_print_context *context);
void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
const char *line, enum date_mode dmode,
const char *encoding);
void pp_title_line(enum cmit_fmt fmt,
extern void pretty_print_commit(const struct pretty_print_context *pp,
const struct commit *commit,
struct strbuf *sb);
extern void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,
struct strbuf *sb);
void pp_user_info(const struct pretty_print_context *pp,
const char *what, struct strbuf *sb,
const char *line, const char *encoding);
void pp_title_line(const struct pretty_print_context *pp,
const char **msg_p,
struct strbuf *sb,
const char *subject,
const char *after_subject,
const char *encoding,
int need_8bit_cte);
void pp_remainder(enum cmit_fmt fmt,
void pp_remainder(const struct pretty_print_context *pp,
const char **msg_p,
struct strbuf *sb,
int indent);
Expand Down
4 changes: 3 additions & 1 deletion log-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,10 @@ void show_log(struct rev_info *opt)
ctx.date_mode = opt->date_mode;
ctx.abbrev = opt->diffopt.abbrev;
ctx.after_subject = extra_headers;
ctx.preserve_subject = opt->preserve_subject;
ctx.reflog_info = opt->reflog_info;
pretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx);
ctx.fmt = opt->commit_format;
pretty_print_commit(&ctx, commit, &msgbuf);

if (opt->add_signoff)
append_signoff(&msgbuf, opt->add_signoff);
Expand Down
Loading

0 comments on commit f67d2e8

Please sign in to comment.