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>
This commit is contained in:

committed by
Junio C Hamano

parent
636a0aeedf
commit
ee82a487f6
@ -260,11 +260,9 @@ contents:lines=N::
|
|||||||
The first `N` lines of the message.
|
The first `N` lines of the message.
|
||||||
|
|
||||||
Additionally, the trailers as interpreted by linkgit:git-interpret-trailers[1]
|
Additionally, the trailers as interpreted by linkgit:git-interpret-trailers[1]
|
||||||
are obtained as `trailers` (or by using the historical alias
|
are obtained as `trailers[:options]` (or by using the historical alias
|
||||||
`contents:trailers`). Non-trailer lines from the trailer block can be omitted
|
`contents:trailers[:options]`). For valid [:option] values see `trailers`
|
||||||
with `trailers:only`. Whitespace-continuations can be removed from trailers so
|
section of linkgit:git-log[1].
|
||||||
that each trailer appears on a line by itself with its full content with
|
|
||||||
`trailers:unfold`. Both can be used together as `trailers:unfold,only`.
|
|
||||||
|
|
||||||
For sorting purposes, fields with numeric values sort in numeric order
|
For sorting purposes, fields with numeric values sort in numeric order
|
||||||
(`objectsize`, `authordate`, `committerdate`, `creatordate`, `taggerdate`).
|
(`objectsize`, `authordate`, `committerdate`, `creatordate`, `taggerdate`).
|
||||||
|
36
ref-filter.c
36
ref-filter.c
@ -67,6 +67,12 @@ struct refname_atom {
|
|||||||
int lstrip, rstrip;
|
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 {
|
static struct expand_data {
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
enum object_type type;
|
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,
|
static int trailers_atom_parser(const struct ref_format *format, struct used_atom *atom,
|
||||||
const char *arg, struct strbuf *err)
|
const char *arg, struct strbuf *err)
|
||||||
{
|
{
|
||||||
struct string_list params = STRING_LIST_INIT_DUP;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
atom->u.contents.trailer_opts.no_divider = 1;
|
atom->u.contents.trailer_opts.no_divider = 1;
|
||||||
|
|
||||||
if (arg) {
|
if (arg) {
|
||||||
string_list_split(¶ms, arg, ',', -1);
|
const char *argbuf = xstrfmt("%s)", arg);
|
||||||
for (i = 0; i < params.nr; i++) {
|
char *invalid_arg = NULL;
|
||||||
const char *s = params.items[i].string;
|
|
||||||
if (!strcmp(s, "unfold"))
|
if (format_set_trailers_options(&atom->u.contents.trailer_opts,
|
||||||
atom->u.contents.trailer_opts.unfold = 1;
|
&ref_trailer_buf.filter_list,
|
||||||
else if (!strcmp(s, "only"))
|
&ref_trailer_buf.sepbuf,
|
||||||
atom->u.contents.trailer_opts.only_trailers = 1;
|
&ref_trailer_buf.kvsepbuf,
|
||||||
else {
|
&argbuf, &invalid_arg)) {
|
||||||
strbuf_addf(err, _("unknown %%(trailers) argument: %s"), s);
|
if (!invalid_arg)
|
||||||
string_list_clear(¶ms, 0);
|
strbuf_addf(err, _("expected %%(trailers:key=<value>)"));
|
||||||
return -1;
|
else
|
||||||
}
|
strbuf_addf(err, _("unknown %%(trailers) argument: %s"), invalid_arg);
|
||||||
|
free((char *)invalid_arg);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
atom->u.contents.option = C_TRAILERS;
|
atom->u.contents.option = C_TRAILERS;
|
||||||
string_list_clear(¶ms, 0);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -837,6 +837,24 @@ test_trailer_option '%(trailers:only) shows only "key: value" trailers' \
|
|||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:only=no,only=true) shows only "key: value" trailers' \
|
||||||
|
'trailers:only=no,only=true' <<-EOF
|
||||||
|
$(grep -v patch.description <trailers)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:only=yes) shows only "key: value" trailers' \
|
||||||
|
'trailers:only=yes' <<-EOF
|
||||||
|
$(grep -v patch.description <trailers)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:only=no) shows all trailers' \
|
||||||
|
'trailers:only=no' <<-EOF
|
||||||
|
$(cat trailers)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
test_trailer_option '%(trailers:only) and %(trailers:unfold) work together' \
|
test_trailer_option '%(trailers:only) and %(trailers:unfold) work together' \
|
||||||
'trailers:only,unfold' <<-EOF
|
'trailers:only,unfold' <<-EOF
|
||||||
$(grep -v patch.description <trailers | unfold)
|
$(grep -v patch.description <trailers | unfold)
|
||||||
@ -849,6 +867,78 @@ test_trailer_option '%(trailers:unfold) and %(trailers:only) work together' \
|
|||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:key=foo) shows that trailer' \
|
||||||
|
'trailers:key=Signed-off-by' <<-EOF
|
||||||
|
Signed-off-by: A U Thor <author@example.com>
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:key=foo) is case insensitive' \
|
||||||
|
'trailers:key=SiGned-oFf-bY' <<-EOF
|
||||||
|
Signed-off-by: A U Thor <author@example.com>
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:key=foo:) trailing colon also works' \
|
||||||
|
'trailers:key=Signed-off-by:' <<-EOF
|
||||||
|
Signed-off-by: A U Thor <author@example.com>
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:key=foo) multiple keys' \
|
||||||
|
'trailers:key=Reviewed-by:,key=Signed-off-by' <<-EOF
|
||||||
|
Reviewed-by: A U Thor <author@example.com>
|
||||||
|
Signed-off-by: A U Thor <author@example.com>
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:key=nonexistent) becomes empty' \
|
||||||
|
'trailers:key=Shined-off-by:' <<-EOF
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:key=foo) handles multiple lines even if folded' \
|
||||||
|
'trailers:key=Acked-by' <<-EOF
|
||||||
|
$(grep -v patch.description <trailers | grep -v Signed-off-by | grep -v Reviewed-by)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:key=foo,unfold) properly unfolds' \
|
||||||
|
'trailers:key=Signed-Off-by,unfold' <<-EOF
|
||||||
|
$(unfold <trailers | grep Signed-off-by)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:key=foo,only=no) also includes nontrailer lines' \
|
||||||
|
'trailers:key=Signed-off-by,only=no' <<-EOF
|
||||||
|
Signed-off-by: A U Thor <author@example.com>
|
||||||
|
$(grep patch.description <trailers)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:key=foo,valueonly) shows only value' \
|
||||||
|
'trailers:key=Signed-off-by,valueonly' <<-EOF
|
||||||
|
A U Thor <author@example.com>
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:separator) changes separator' \
|
||||||
|
'trailers:separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
|
||||||
|
Reviewed-by: A U Thor <author@example.com>,Signed-off-by: A U Thor <author@example.com>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:key_value_separator) changes key-value separator' \
|
||||||
|
'trailers:key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
|
||||||
|
Reviewed-by,A U Thor <author@example.com>
|
||||||
|
Signed-off-by,A U Thor <author@example.com>
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:separator,key_value_separator) changes both separators' \
|
||||||
|
'trailers:separator=%x2C,key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
|
||||||
|
Reviewed-by,A U Thor <author@example.com>,Signed-off-by,A U Thor <author@example.com>
|
||||||
|
EOF
|
||||||
|
|
||||||
test_failing_trailer_option () {
|
test_failing_trailer_option () {
|
||||||
title=$1 option=$2
|
title=$1 option=$2
|
||||||
cat >expect
|
cat >expect
|
||||||
@ -866,6 +956,11 @@ test_failing_trailer_option '%(trailers) rejects unknown trailers arguments' \
|
|||||||
fatal: unknown %(trailers) argument: unsupported
|
fatal: unknown %(trailers) argument: unsupported
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
test_failing_trailer_option '%(trailers:key) without value is error' \
|
||||||
|
'trailers:key' <<-\EOF
|
||||||
|
fatal: expected %(trailers:key=<value>)
|
||||||
|
EOF
|
||||||
|
|
||||||
test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
|
test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
|
||||||
cat >expect <<-EOF &&
|
cat >expect <<-EOF &&
|
||||||
fatal: unrecognized %(contents) argument: trailersonly
|
fatal: unrecognized %(contents) argument: trailersonly
|
||||||
|
Reference in New Issue
Block a user