]> git.ipfire.org Git - thirdparty/git.git/commit
pretty format %(trailers): add a "keyonly"
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 9 Dec 2020 15:52:07 +0000 (16:52 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 9 Dec 2020 22:16:42 +0000 (14:16 -0800)
commit9d87d5ae026433a2993fdb757fc80dbdcb078310
tree342403fcb77eb8f7945f02ab653e9c21007a9d93
parent8b966a0506f8b5aef7c6038fe518db45bc4a1852
pretty format %(trailers): add a "keyonly"

Add support for a "keyonly". This allows for easier parsing out of the
key and value. Before if you didn't want to make assumptions about how
the key was formatted. You'd need to parse it out as e.g.:

    --pretty=format:'%H%x00%(trailers:separator=%x00%x00)' \
                       '%x00%(trailers:separator=%x00%x00,valueonly)'

And then proceed to deduce keys by looking at those two and
subtracting the value plus the hardcoded ": " separator from the
non-valueonly %(trailers) line. Now it's possible to simply do:

    --pretty=format:'%H%x00%(trailers:separator=%x00%x00,keyonly)' \
                    '%x00%(trailers:separator=%x00%x00,valueonly)'

Which at least reduces it to a state machine where you get N keys and
correlate them with N values. Even better would be to have a way to
change the ": " delimiter to something easily machine-readable (a key
might contain ": " too). A follow-up change will add support for that.

I don't really have a use-case for just "keyonly" myself. I suppose it
would be useful in some cases as "key=*" matches case-insensitively,
so a plain "keyonly" will give you the variants of the keys you
matched. I'm mainly adding it to fix the inconsistency with
"valueonly".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/pretty-formats.txt
pretty.c
t/t4205-log-pretty-formats.sh
trailer.c
trailer.h