From: Taylor Blau <me@ttaylorr.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, peff@peff.net, Taylor Blau <me@ttaylorr.com>
Subject: [PATCH v4 5/6] ref-filter.c: use trailer_opts to format trailers
Date: Sun, 1 Oct 2017 09:18:51 -0700 [thread overview]
Message-ID: <20171001161852.84571-5-me@ttaylorr.com> (raw)
In-Reply-To: <20171001161852.84571-1-me@ttaylorr.com>
Fill trailer_opts with "unfold" and "only" to match the sub-arguments
given to the "%(trailers)" atom. Then, let's use the filled trailer_opts
instance with 'format_trailers_from_commit' in order to format trailers
in the desired manner.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
Documentation/git-for-each-ref.txt | 5 ++++-
ref-filter.c | 32 +++++++++++++++++++++---------
t/t6300-for-each-ref.sh | 40 ++++++++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 10 deletions(-)
diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index 1279b9733..4a2c851e6 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -218,7 +218,10 @@ blank line. The optional GPG signature is `contents:signature`. The
first `N` lines of the message is obtained using `contents:lines=N`.
Additionally, the trailers as interpreted by linkgit:git-interpret-trailers[1]
are obtained as `trailers` (or by using the historical alias
-`contents:trailers`).
+`contents:trailers`). Non-trailer lines from the trailer block can be omitted
+with `trailers:only`. Whitespace-continuations can be removed from trailers so
+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
(`objectsize`, `authordate`, `committerdate`, `creatordate`, `taggerdate`).
diff --git a/ref-filter.c b/ref-filter.c
index bc591f4f3..43ed10a5e 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -82,6 +82,7 @@ static struct used_atom {
} remote_ref;
struct {
enum { C_BARE, C_BODY, C_BODY_DEP, C_LINES, C_SIG, C_SUB, C_TRAILERS } option;
+ struct process_trailer_options trailer_opts;
unsigned int nlines;
} contents;
struct {
@@ -182,9 +183,23 @@ static void subject_atom_parser(const struct ref_format *format, struct used_ato
static void trailers_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)
{
- if (arg)
- die(_("%%(trailers) does not take arguments"));
+ struct string_list params = STRING_LIST_INIT_DUP;
+ int i;
+
+ 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
+ die(_("unknown %%(trailers) argument: %s"), s);
+ }
+ }
atom->u.contents.option = C_TRAILERS;
+ string_list_clear(¶ms, 0);
}
static void contents_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg)
@@ -1042,7 +1057,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct obj
name++;
if (strcmp(name, "subject") &&
strcmp(name, "body") &&
- strcmp(name, "trailers") &&
+ !starts_with(name, "trailers") &&
!starts_with(name, "contents"))
continue;
if (!subpos)
@@ -1067,13 +1082,12 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct obj
append_lines(&s, subpos, contents_end - subpos, atom->u.contents.nlines);
v->s = strbuf_detach(&s, NULL);
} else if (atom->u.contents.option == C_TRAILERS) {
- struct trailer_info info;
+ struct strbuf s = STRBUF_INIT;
- /* Search for trailer info */
- trailer_info_get(&info, subpos);
- v->s = xmemdupz(info.trailer_start,
- info.trailer_end - info.trailer_start);
- trailer_info_release(&info);
+ /* Format the trailer info according to the trailer_opts given */
+ format_trailers_from_commit(&s, subpos, &atom->u.contents.trailer_opts);
+
+ v->s = strbuf_detach(&s, NULL);
} else if (atom->u.contents.option == C_BARE)
v->s = xstrdup(subpos);
}
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 39431908d..e4ce9c550 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -610,6 +610,9 @@ Acked-by: A U Thor
<author@example.com>
EOF
+unfold () {
+ perl -0pe 's/\n\s+/ /g'
+}
test_expect_success 'set up trailers for next test' '
echo "Some contents" > two &&
@@ -623,6 +626,43 @@ test_expect_success 'set up trailers for next test' '
EOF
'
+test_expect_success '%(trailers:unfold) unfolds trailers' '
+ git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
+ {
+ unfold <trailers
+ echo
+ } >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success '%(trailers:only) shows only "key: value" trailers' '
+ git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
+ {
+ grep -v patch.description <trailers &&
+ echo
+ } >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
+ git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
+ git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
+ test_cmp actual reverse &&
+ {
+ grep -v patch.description <trailers | unfold &&
+ echo
+ } >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success '%(trailers) rejects unknown trailers arguments' '
+ cat >expect <<-EOF &&
+ fatal: unknown %(trailers) argument: unsupported
+ EOF
+ test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'basic atom: head contents:trailers' '
git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
sanitize_pgp <actual >actual.clean &&
--
2.14.1.145.gb3622a4ee
next prev parent reply other threads:[~2017-10-01 16:19 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-30 6:22 [PATCH 0/5] Support %(trailers) arguments in for-each-ref(1) Taylor Blau
2017-09-30 6:22 ` [PATCH 1/5] pretty.c: delimit "%(trailers)" arguments with "," Taylor Blau
2017-09-30 6:49 ` Jeff King
2017-09-30 6:22 ` [PATCH 2/5] t6300: refactor %(trailers) tests Taylor Blau
2017-09-30 7:01 ` Jeff King
2017-09-30 6:22 ` [PATCH 3/5] ref-filter.c: add trailer options to used_atom Taylor Blau
2017-09-30 7:10 ` Jeff King
2017-09-30 6:22 ` [PATCH 4/5] ref-filter.c: use trailer_opts to format trailers Taylor Blau
2017-09-30 7:21 ` Jeff King
2017-10-01 9:08 ` Junio C Hamano
2017-10-01 9:00 ` Junio C Hamano
2017-10-02 5:05 ` Jeff King
2017-10-02 5:11 ` Taylor Blau
2017-09-30 6:22 ` [PATCH 5/5] ref-filter.c: parse trailers arguments with %(contents) atom Taylor Blau
2017-09-30 7:36 ` Jeff King
2017-09-30 7:38 ` [PATCH 0/5] Support %(trailers) arguments in for-each-ref(1) Jeff King
2017-09-30 18:41 ` [PATCH v2 0/6] " Taylor Blau
2017-09-30 18:46 ` [PATCH v2 1/6] pretty.c: delimit "%(trailers)" arguments with "," Taylor Blau
2017-09-30 18:46 ` [PATCH v2 2/6] t6300: refactor %(trailers) tests Taylor Blau
2017-09-30 18:46 ` [PATCH v2 3/6] doc: 'trailers' is the preferred way to format trailers Taylor Blau
2017-09-30 18:46 ` [PATCH v2 4/6] doc: use modern "`"-style code fencing Taylor Blau
2017-09-30 18:46 ` [PATCH v2 5/6] ref-filter.c: use trailer_opts to format trailers Taylor Blau
2017-09-30 18:46 ` [PATCH v2 6/6] ref-filter.c: parse trailers arguments with %(contents) atom Taylor Blau
2017-10-01 0:06 ` [PATCH v2 0/6] Support %(trailers) arguments in for-each-ref(1) Taylor Blau
2017-10-01 0:10 ` [PATCH v3 1/6] pretty.c: delimit "%(trailers)" arguments with "," Taylor Blau
2017-10-01 0:10 ` [PATCH v3 2/6] t6300: refactor %(trailers) tests Taylor Blau
2017-10-01 0:10 ` [PATCH v3 3/6] doc: 'trailers' is the preferred way to format trailers Taylor Blau
2017-10-01 0:10 ` [PATCH v3 4/6] doc: use modern "`"-style code fencing Taylor Blau
2017-10-01 0:10 ` [PATCH v3 5/6] ref-filter.c: use trailer_opts to format trailers Taylor Blau
2017-10-01 0:10 ` [PATCH v3 6/6] ref-filter.c: parse trailers arguments with %(contents) atom Taylor Blau
2017-10-01 16:17 ` [PATCH v4 0/6] Support %(trailers) arguments in for-each-ref(1) Taylor Blau
2017-10-01 16:18 ` [PATCH v4 1/6] pretty.c: delimit "%(trailers)" arguments with "," Taylor Blau
2017-10-01 16:18 ` [PATCH v4 2/6] t6300: refactor %(trailers) tests Taylor Blau
2017-10-02 0:12 ` Junio C Hamano
2017-10-01 16:18 ` [PATCH v4 3/6] doc: 'trailers' is the preferred way to format trailers Taylor Blau
2017-10-01 16:18 ` [PATCH v4 4/6] doc: use modern "`"-style code fencing Taylor Blau
2017-10-01 23:55 ` Junio C Hamano
2017-10-02 0:06 ` Taylor Blau
2017-10-02 1:35 ` Junio C Hamano
2017-10-02 4:53 ` Jeff King
2017-10-01 16:18 ` Taylor Blau [this message]
2017-10-02 0:13 ` [PATCH v4 5/6] ref-filter.c: use trailer_opts to format trailers Junio C Hamano
2017-10-01 16:18 ` [PATCH v4 6/6] ref-filter.c: parse trailers arguments with %(contents) atom Taylor Blau
2017-10-02 0:19 ` Junio C Hamano
2017-10-02 0:11 ` [PATCH v4 1/6] pretty.c: delimit "%(trailers)" arguments with "," Junio C Hamano
2017-10-02 5:00 ` Jeff King
2017-10-02 0:31 ` [PATCH v5 0/6] Support %(trailers) arguments in for-each-ref(1) Taylor Blau
2017-10-02 0:32 ` [PATCH v5 1/6] pretty.c: delimit "%(trailers)" arguments with "," Taylor Blau
2017-10-02 0:33 ` [PATCH v5 2/6] t6300: refactor %(trailers) tests Taylor Blau
2017-10-02 0:33 ` [PATCH v5 3/6] doc: 'trailers' is the preferred way to format trailers Taylor Blau
2017-10-02 0:33 ` [PATCH v5 4/6] doc: use modern "`"-style code quoting Taylor Blau
2017-10-02 0:33 ` [PATCH v5 5/6] ref-filter.c: use trailer_opts to format trailers Taylor Blau
2017-10-02 0:33 ` [PATCH v5 6/6] ref-filter.c: parse trailers arguments with %(contents) atom Taylor Blau
2017-10-02 4:26 ` Junio C Hamano
2017-10-02 4:51 ` Junio C Hamano
2017-10-02 5:13 ` Taylor Blau
2017-10-02 5:03 ` Jeff King
2017-10-02 5:12 ` Taylor Blau
2017-10-02 5:14 ` Jeff King
2017-10-02 5:23 ` [PATCH v6 0/7] Support %(trailers) arguments in for-each-ref(1) Taylor Blau
2017-10-02 5:25 ` [PATCH v6 1/7] pretty.c: delimit "%(trailers)" arguments with "," Taylor Blau
2017-10-02 5:25 ` [PATCH v6 2/7] t4205: unfold across multiple lines Taylor Blau
2017-10-02 5:25 ` [PATCH v6 3/7] doc: 'trailers' is the preferred way to format trailers Taylor Blau
2017-10-02 5:25 ` [PATCH v6 4/7] doc: use modern "`"-style code quoting Taylor Blau
2017-10-02 5:25 ` [PATCH v6 5/7] t6300: refactor %(trailers) tests Taylor Blau
2017-10-02 5:25 ` [PATCH v6 6/7] ref-filter.c: use trailer_opts to format trailers Taylor Blau
2017-10-02 5:25 ` [PATCH v6 7/7] ref-filter.c: parse trailers arguments with %(contents) atom Taylor Blau
2017-10-02 6:51 ` Jeff King
2017-10-02 9:52 ` Junio C Hamano
2017-10-02 15:49 ` Taylor Blau
2017-10-02 23:44 ` Junio C Hamano
2017-10-02 6:56 ` [PATCH v6 0/7] Support %(trailers) arguments in for-each-ref(1) Jeff King
2017-10-03 6:24 ` Junio C Hamano
2017-10-03 6:36 ` Jeff King
2017-10-03 6:40 ` Junio C Hamano
2017-10-02 8:07 ` Junio C Hamano
2017-10-02 12:15 ` Junio C Hamano
2017-10-02 16:07 ` Taylor Blau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171001161852.84571-5-me@ttaylorr.com \
--to=me@ttaylorr.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.