public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Brooke Kuhlmann <brooke@alchemists.io>
Cc: git@vger.kernel.org
Subject: Re: Fix issue with formatting multiple trailer keys
Date: Fri, 6 Sep 2024 18:34:02 -0400	[thread overview]
Message-ID: <20240906223402.GA1221600@coredump.intra.peff.net> (raw)
In-Reply-To: <EF5AE27D-B7CE-4337-B928-6073837218CA@alchemists.io>

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

  reply	other threads:[~2024-09-06 22:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-06 19:55 Fix issue with formatting multiple trailer keys Brooke Kuhlmann
2024-09-06 22:34 ` Jeff King [this message]
2024-09-06 23:09   ` Brooke Kuhlmann
2024-09-09 23:03     ` Jeff King
2024-09-10  2:22       ` Brooke Kuhlmann

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=20240906223402.GA1221600@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=brooke@alchemists.io \
    --cc=git@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox