Merge branch 'hv/trailer-formatting'
The logic to handle "trailer" related placeholders in the "--format=" mechanisms in the "log" family and "for-each-ref" family is getting unified. * hv/trailer-formatting: ref-filter: use pretty.c logic for trailers pretty.c: capture invalid trailer argument pretty.c: refactor trailer logic to `format_set_trailers_options()` t6300: use function to test trailer options
This commit is contained in:
36
ref-filter.c
36
ref-filter.c
@ -67,6 +67,12 @@ struct refname_atom {
|
||||
int lstrip, rstrip;
|
||||
};
|
||||
|
||||
static struct ref_trailer_buf {
|
||||
struct string_list filter_list;
|
||||
struct strbuf sepbuf;
|
||||
struct strbuf kvsepbuf;
|
||||
} ref_trailer_buf = {STRING_LIST_INIT_NODUP, STRBUF_INIT, STRBUF_INIT};
|
||||
|
||||
static struct expand_data {
|
||||
struct object_id oid;
|
||||
enum object_type type;
|
||||
@ -313,28 +319,26 @@ static int subject_atom_parser(const struct ref_format *format, struct used_atom
|
||||
static int trailers_atom_parser(const struct ref_format *format, struct used_atom *atom,
|
||||
const char *arg, struct strbuf *err)
|
||||
{
|
||||
struct string_list params = STRING_LIST_INIT_DUP;
|
||||
int i;
|
||||
|
||||
atom->u.contents.trailer_opts.no_divider = 1;
|
||||
|
||||
if (arg) {
|
||||
string_list_split(¶ms, arg, ',', -1);
|
||||
for (i = 0; i < params.nr; i++) {
|
||||
const char *s = params.items[i].string;
|
||||
if (!strcmp(s, "unfold"))
|
||||
atom->u.contents.trailer_opts.unfold = 1;
|
||||
else if (!strcmp(s, "only"))
|
||||
atom->u.contents.trailer_opts.only_trailers = 1;
|
||||
else {
|
||||
strbuf_addf(err, _("unknown %%(trailers) argument: %s"), s);
|
||||
string_list_clear(¶ms, 0);
|
||||
return -1;
|
||||
}
|
||||
const char *argbuf = xstrfmt("%s)", arg);
|
||||
char *invalid_arg = NULL;
|
||||
|
||||
if (format_set_trailers_options(&atom->u.contents.trailer_opts,
|
||||
&ref_trailer_buf.filter_list,
|
||||
&ref_trailer_buf.sepbuf,
|
||||
&ref_trailer_buf.kvsepbuf,
|
||||
&argbuf, &invalid_arg)) {
|
||||
if (!invalid_arg)
|
||||
strbuf_addf(err, _("expected %%(trailers:key=<value>)"));
|
||||
else
|
||||
strbuf_addf(err, _("unknown %%(trailers) argument: %s"), invalid_arg);
|
||||
free((char *)invalid_arg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
atom->u.contents.option = C_TRAILERS;
|
||||
string_list_clear(¶ms, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user