git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Fix issue with formatting multiple trailer keys

From
Brooke Kuhlmann <brooke@alchemists.io>
Date
Sep 6, 2024, 23:09 UTC
Message-ID
<5A3FD50B-46F1-4000-8AAD-895A4CB4F33F@alchemists.io>
In-Reply-To
<20240906223402.GA1221600@coredump.intra.peff.net>
Use of a custom separator is a nifty trick. Thanks. A little unintuitive but works. Definitely would be neat if you patch this to work without the custom separator, though.
Thanks for the help. Will look forward to picking up the next patched version of Git.
Show 58 quoted lines
> On Sep 6, 2024, at 4:34 PM, Jeff King <peff@peff.net> wrote:
> 
> On Fri, Sep 06, 2024 at 01:55:46PM -0600, Brooke Kuhlmann wrote:
> 
>> ``` 
>> git tag --list \
>>        --format="%(refname:short) %(taggerdate:short) %(taggername) %(subject) %(trailers:key=Files) %(trailers:key=Duration)"
>> ```
>> 
>> ...I get this output:
>> 
>> 0.0.0 2024-09-06 Brooke Kuhlmann Version 0.0.0 Files: 1
>> Duration: 1
>> Files: 1
>> Duration: 1
>> 
>> 0.0.1 2024-09-06 Brooke Kuhlmann Version 0.0.1 Files: 1
>> Duration: 1
>> Files: 1
>> Duration: 1
>> 
>> Notice, when logging trailer information for commits and tags, I get
>> unexpected new line characters showing up in the output. I expect to
>> see all information printed on the same line without any new lines
>> showing up.
>> 
>> Also, I want to point out that when listing tag trailers, I get the
>> "Duration" key showing up twice. I'm not sure if that's related or not
>> but seems like very weird behavior.
> 
> There are two things going on here:
> 
>  1. Some of the trailer options are stored in a global, rather than a
>     per-placeholder basis. This includes the list of keys to show. So
>     you basically end up with a filter list that includes _both_ keys,
>     and that list is used for both %(trailers) items.
> 
>     IMHO this is a bug, and I have a patch (which I'll send along with
>     the one I mentioned in the other thread) to fix it.
> 
>     In the meantime you can work around it by specifying both keys in
>     a single invocation, like:
> 
>       %(trailers:key=Files,key=Duration)
> 
>     Obviously that doesn't work if you don't want them adjacent in the
>     final output.
> 
>  2. By default, each trailer is terminated with a newline. But you can
>     specify your own separator, like so:
> 
>       %(trailers:key=Files,key=Duration,separator= )
> 
>     See the documentation for the trailers placeholder in "git help
>     log". Depending on your trailers, "valueonly" might also be useful
>     for this kind of formatting.
> 
> -Peff
Previous: Jeff KingNext: Jeff King
Message 3 of 5 in “Fix issue with formatting multiple trailer keys”
  1. Brooke KuhlmannSep 6, 2024
  2. Jeff KingSep 6, 2024
  3. Brooke KuhlmannSep 6, 2024
  4. Jeff KingSep 9, 2024
  5. Brooke KuhlmannSep 10, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.