Merge branch 'jk/trailers-parse'

"git interpret-trailers" has been taught a "--parse" and a few
other options to make it easier for scripts to grab existing
trailer lines from a commit log message.

* jk/trailers-parse:
  doc/interpret-trailers: fix "the this" typo
  pretty: support normalization options for %(trailers)
  t4205: refactor %(trailers) tests
  pretty: move trailer formatting to trailer.c
  interpret-trailers: add --parse convenience option
  interpret-trailers: add an option to unfold values
  interpret-trailers: add an option to show only existing trailers
  interpret-trailers: add an option to show only the trailers
  trailer: put process_trailers() options into a struct
This commit is contained in:
Junio C Hamano
2017-08-26 22:55:04 -07:00
8 changed files with 314 additions and 52 deletions

View File

@ -871,16 +871,6 @@ const char *format_subject(struct strbuf *sb, const char *msg,
return msg;
}
static void format_trailers(struct strbuf *sb, const char *msg)
{
struct trailer_info info;
trailer_info_get(&info, msg);
strbuf_add(sb, info.trailer_start,
info.trailer_end - info.trailer_start);
trailer_info_release(&info);
}
static void parse_commit_message(struct format_commit_context *c)
{
const char *msg = c->message + c->message_off;
@ -1074,6 +1064,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
const struct commit *commit = c->commit;
const char *msg = c->message;
struct commit_list *p;
const char *arg;
int ch;
/* these are independent of the commit */
@ -1292,9 +1283,18 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
return 1;
}
if (starts_with(placeholder, "(trailers)")) {
format_trailers(sb, msg + c->subject_off);
return strlen("(trailers)");
if (skip_prefix(placeholder, "(trailers", &arg)) {
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
while (*arg == ':') {
if (skip_prefix(arg, ":only", &arg))
opts.only_trailers = 1;
else if (skip_prefix(arg, ":unfold", &arg))
opts.unfold = 1;
}
if (*arg == ')') {
format_trailers_from_commit(sb, msg + c->subject_off, &opts);
return arg - placeholder + 1;
}
}
return 0; /* unknown placeholder */