From 058761f1c19b58afd6906672fc013327eb2096c6 Mon Sep 17 00:00:00 2001 From: Ævar Arnfjörð Bjarmason Date: Wed, 9 Dec 2020 16:52:08 +0100 Subject: pretty format %(trailers): add a "key_value_separator" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a "key_value_separator" option to the "%(trailers)" pretty format, to go along with the existing "separator" argument. In combination these two options make it trivial to produce machine-readable (e.g. \0 and \0\0-delimited) format output. As elaborated on in a previous commit which added "keyonly" it was needlessly tedious to extract structured data from "%(trailers)" before the addition of this "key_value_separator" option. As seen by the test being added here extracting this data now becomes trivial. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- trailer.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'trailer.c') diff --git a/trailer.c b/trailer.c index 889b419a4f..249ed618ed 100644 --- a/trailer.c +++ b/trailer.c @@ -1132,7 +1132,8 @@ static void format_trailer_info(struct strbuf *out, /* If we want the whole block untouched, we can take the fast path. */ if (!opts->only_trailers && !opts->unfold && !opts->filter && - !opts->separator && !opts->key_only && !opts->value_only) { + !opts->separator && !opts->key_only && !opts->value_only && + !opts->key_value_separator) { strbuf_add(out, info->trailer_start, info->trailer_end - info->trailer_start); return; @@ -1155,8 +1156,12 @@ static void format_trailer_info(struct strbuf *out, strbuf_addbuf(out, opts->separator); if (!opts->value_only) strbuf_addbuf(out, &tok); - if (!opts->key_only && !opts->value_only) - strbuf_addstr(out, ": "); + if (!opts->key_only && !opts->value_only) { + if (opts->key_value_separator) + strbuf_addbuf(out, opts->key_value_separator); + else + strbuf_addstr(out, ": "); + } if (!opts->key_only) strbuf_addbuf(out, &val); if (!opts->separator) -- cgit v1.3-5-g9baa