aboutsummaryrefslogtreecommitdiffstats
path: root/ref-filter.c
diff options
context:
space:
mode:
authorHariom Verma <hariom18599@gmail.com>2021-02-13 01:52:43 +0000
committerJunio C Hamano <gitster@pobox.com>2021-02-15 16:48:38 -0800
commitee82a487f68a7c86551fb59f6176812d63be61b6 (patch)
treeb1628f0a6af93dcf451a60e83ffdc23eb75ceb6d /ref-filter.c
parent636a0aeedfee5f3cce2ebf1fcc174a49ab9bb0c3 (diff)
downloadgit-ee82a487f68a7c86551fb59f6176812d63be61b6.tar.gz
ref-filter: use pretty.c logic for trailers
Now, ref-filter is using pretty.c logic for setting trailer options. New to ref-filter: :key=<K> - only show trailers with specified key. :valueonly[=val] - only show the value part. :separator=<SEP> - inserted between trailer lines. :key_value_separator=<SEP> - inserted between key and value in trailer lines Enhancement to existing options(now can take value and its optional): :only[=val] :unfold[=val] 'val' can be: true, on, yes or false, off, no. Mentored-by: Christian Couder <chriscool@tuxfamily.org> Mentored-by: Heba Waly <heba.waly@gmail.com> Signed-off-by: Hariom Verma <hariom18599@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/ref-filter.c b/ref-filter.c
index ee337df232..4dc4882cc7 100644
--- a/ref-filter.c
+++ b/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(&params, 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(&params, 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(&params, 0);
return 0;
}