{"thread":{"id":"62074","subject":"Fix issue with formatting multiple trailer keys","startedAt":"2024-09-06T19:55:59Z","lastAt":"2024-09-10T02:22:55Z","messageCount":5,"participants":["Brooke Kuhlmann","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"502357","messageId":"EF5AE27D-B7CE-4337-B928-6073837218CA@alchemists.io","threadId":"62074","inReplyTo":null,"subject":"Fix issue with formatting multiple trailer keys","fromName":"Brooke Kuhlmann","fromEmail":"brooke@alchemists.io","sentAt":"2024-09-06T19:55:46Z","receivedAt":"2024-09-06T19:55:59Z","isPatch":false,"sender":{"key":"brooke@alchemists.io","avatar":"https://gravatar.com/avatar/4bd27d52fe87760d2bde1d384f0139eb81013709a0cf27ce654d48a7852727fa?d=mp&s=160"},"body":"Hello. 👋\n\nI'm seeing strange issues with log/listing trailer information for commits and tags and I think I'm experiencing a bug where when I attempt to list commits and tags with specific trailer keys, I get new lines showing up in my output.\n\nHere's my steps to recreate using a simple Bash script:\n\n``` \nmkdir demo\ncd demo\ngit init\n\ntouch one.txt\ngit add .\ngit commit --message \"Added one\" --trailer Milestone=patch --trailer Issue=111\ngit tag 0.0.0 --message \"Version 0.0.0\" --no-sign --trailer Files:1 --trailer Duration:1\n\ntouch two.txt\ngit add .\ngit commit --message \"Added two\" --trailer Milestone=patch --trailer Issue=222\ngit tag 0.0.1 --message \"Version 0.0.1\" --no-sign --trailer Files:1 --trailer Duration:1\n```\n\nNotice that I'm using trailers for my commits *and* tags. Here's what my git log looks like:\n\n``` \ngit log --pretty=format:\"%h %an% %s %d %cr. %(trailers:key=Milestone) %(trailers:key=Issue)\"\n```\n\nThe above produces this output:\n\n08a07b717bef Brooke KuhlmannAdded two  (HEAD -> main, tag: 0.0.1) 5 minutes ago. Milestone: patch\n Issue: 222\n\n01c4c182c85e Brooke KuhlmannAdded one  (tag: 0.0.0) 5 minutes ago. Milestone: patch\n Issue: 111\n\n...and if I list my tags using this command:\n\n``` \ngit tag --list \\\n        --format=\"%(refname:short) %(taggerdate:short) %(taggername) %(subject) %(trailers:key=Files) %(trailers:key=Duration)\"\n```\n\n...I get this output:\n\n0.0.0 2024-09-06 Brooke Kuhlmann Version 0.0.0 Files: 1\nDuration: 1\n Files: 1\nDuration: 1\n\n0.0.1 2024-09-06 Brooke Kuhlmann Version 0.0.1 Files: 1\nDuration: 1\n Files: 1\nDuration: 1\n\nNotice, 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.\n\nAlso, 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."},{"id":"502372","messageId":"20240906223402.GA1221600@coredump.intra.peff.net","threadId":"62074","inReplyTo":"EF5AE27D-B7CE-4337-B928-6073837218CA@alchemists.io","subject":"Re: Fix issue with formatting multiple trailer keys","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2024-09-06T22:34:02Z","receivedAt":"2024-09-06T22:34:04Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Sep 06, 2024 at 01:55:46PM -0600, Brooke Kuhlmann wrote:\n\n> ``` \n> git tag --list \\\n>         --format=\"%(refname:short) %(taggerdate:short) %(taggername) %(subject) %(trailers:key=Files) %(trailers:key=Duration)\"\n> ```\n> \n> ...I get this output:\n> \n> 0.0.0 2024-09-06 Brooke Kuhlmann Version 0.0.0 Files: 1\n> Duration: 1\n>  Files: 1\n> Duration: 1\n> \n> 0.0.1 2024-09-06 Brooke Kuhlmann Version 0.0.1 Files: 1\n> Duration: 1\n>  Files: 1\n> Duration: 1\n> \n> Notice, when logging trailer information for commits and tags, I get\n> unexpected new line characters showing up in the output. I expect to\n> see all information printed on the same line without any new lines\n> showing up.\n> \n> Also, I want to point out that when listing tag trailers, I get the\n> \"Duration\" key showing up twice. I'm not sure if that's related or not\n> but seems like very weird behavior.\n\nThere are two things going on here:\n\n  1. Some of the trailer options are stored in a global, rather than a\n     per-placeholder basis. This includes the list of keys to show. So\n     you basically end up with a filter list that includes _both_ keys,\n     and that list is used for both %(trailers) items.\n\n     IMHO this is a bug, and I have a patch (which I'll send along with\n     the one I mentioned in the other thread) to fix it.\n\n     In the meantime you can work around it by specifying both keys in\n     a single invocation, like:\n\n       %(trailers:key=Files,key=Duration)\n\n     Obviously that doesn't work if you don't want them adjacent in the\n     final output.\n\n  2. By default, each trailer is terminated with a newline. But you can\n     specify your own separator, like so:\n\n       %(trailers:key=Files,key=Duration,separator= )\n\n     See the documentation for the trailers placeholder in \"git help\n     log\". Depending on your trailers, \"valueonly\" might also be useful\n     for this kind of formatting.\n\n-Peff\n"},{"id":"502377","messageId":"5A3FD50B-46F1-4000-8AAD-895A4CB4F33F@alchemists.io","threadId":"62074","inReplyTo":"20240906223402.GA1221600@coredump.intra.peff.net","subject":"Re: Fix issue with formatting multiple trailer keys","fromName":"Brooke Kuhlmann","fromEmail":"brooke@alchemists.io","sentAt":"2024-09-06T23:09:08Z","receivedAt":"2024-09-06T23:09:21Z","isPatch":false,"sender":{"key":"brooke@alchemists.io","avatar":"https://gravatar.com/avatar/4bd27d52fe87760d2bde1d384f0139eb81013709a0cf27ce654d48a7852727fa?d=mp&s=160"},"body":"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.\n\nThanks for the help. Will look forward to picking up the next patched version of Git.\n\n> On Sep 6, 2024, at 4:34 PM, Jeff King <peff@peff.net> wrote:\n> \n> On Fri, Sep 06, 2024 at 01:55:46PM -0600, Brooke Kuhlmann wrote:\n> \n>> ``` \n>> git tag --list \\\n>>        --format=\"%(refname:short) %(taggerdate:short) %(taggername) %(subject) %(trailers:key=Files) %(trailers:key=Duration)\"\n>> ```\n>> \n>> ...I get this output:\n>> \n>> 0.0.0 2024-09-06 Brooke Kuhlmann Version 0.0.0 Files: 1\n>> Duration: 1\n>> Files: 1\n>> Duration: 1\n>> \n>> 0.0.1 2024-09-06 Brooke Kuhlmann Version 0.0.1 Files: 1\n>> Duration: 1\n>> Files: 1\n>> Duration: 1\n>> \n>> Notice, when logging trailer information for commits and tags, I get\n>> unexpected new line characters showing up in the output. I expect to\n>> see all information printed on the same line without any new lines\n>> showing up.\n>> \n>> Also, I want to point out that when listing tag trailers, I get the\n>> \"Duration\" key showing up twice. I'm not sure if that's related or not\n>> but seems like very weird behavior.\n> \n> There are two things going on here:\n> \n>  1. Some of the trailer options are stored in a global, rather than a\n>     per-placeholder basis. This includes the list of keys to show. So\n>     you basically end up with a filter list that includes _both_ keys,\n>     and that list is used for both %(trailers) items.\n> \n>     IMHO this is a bug, and I have a patch (which I'll send along with\n>     the one I mentioned in the other thread) to fix it.\n> \n>     In the meantime you can work around it by specifying both keys in\n>     a single invocation, like:\n> \n>       %(trailers:key=Files,key=Duration)\n> \n>     Obviously that doesn't work if you don't want them adjacent in the\n>     final output.\n> \n>  2. By default, each trailer is terminated with a newline. But you can\n>     specify your own separator, like so:\n> \n>       %(trailers:key=Files,key=Duration,separator= )\n> \n>     See the documentation for the trailers placeholder in \"git help\n>     log\". Depending on your trailers, \"valueonly\" might also be useful\n>     for this kind of formatting.\n> \n> -Peff\n\n\n"},{"id":"502479","messageId":"20240909230331.GA921644@coredump.intra.peff.net","threadId":"62074","inReplyTo":"5A3FD50B-46F1-4000-8AAD-895A4CB4F33F@alchemists.io","subject":"Re: Fix issue with formatting multiple trailer keys","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2024-09-09T23:03:31Z","receivedAt":"2024-09-09T23:03:32Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Sep 06, 2024 at 05:09:08PM -0600, Brooke Kuhlmann wrote:\n\n> Use of a custom separator is a nifty trick. Thanks. A little\n> unintuitive but works. Definitely would be neat if you patch this to\n> work without the custom separator, though.\n\nThe separator will always be required (even if you use multiple\n%(trailer) blocks), because it overrides the default of terminating with\na newline. And we can't switch that default without breaking\ncompatibility for existing users.\n\nSo I think after my series you'll have:\n\n  %(trailers:key=Files,separator=) %(trailers:key=Duration,separator=)\n\nor similar.\n\n-Peff\n"},{"id":"502491","messageId":"EF941B20-86A7-44C9-846F-1B447D86B07E@alchemists.io","threadId":"62074","inReplyTo":"20240909230331.GA921644@coredump.intra.peff.net","subject":"Re: Fix issue with formatting multiple trailer keys","fromName":"Brooke Kuhlmann","fromEmail":"brooke@alchemists.io","sentAt":"2024-09-10T02:22:43Z","receivedAt":"2024-09-10T02:22:55Z","isPatch":false,"sender":{"key":"brooke@alchemists.io","avatar":"https://gravatar.com/avatar/4bd27d52fe87760d2bde1d384f0139eb81013709a0cf27ce654d48a7852727fa?d=mp&s=160"},"body":"OK, thanks. Yeah, that backwards compatibility stipulation is a bit rough in this case but makes sense. Your patch does mean that you could potentially use different separators for each key which might be useful. The other nice thing about your patch is you'll be able to easily apply different colors to each key if desired so that's a nice win too.\n\nFor the moment, in case it helps, I ended up crafting a Bash function for local use that looks like this;\n\n----- SNIPPET-----\n# Label: Git Tag List\n# Description: List tags in tabular form.\ngtl() {\n  local format=\"\\\n%(color:yellow)%(refname:short)%(color:reset)|%(taggerdate:short)\\\n|%(color:blue)%(color:bold)%(taggername)%(color:reset)|%(subject)\\\n|%(color:green)%(trailers:key=Commits,key=Files,key=Deletions,\\\nkey=Insertions,key=Duration,separator=|)%(color:reset)\"\n\n  git tag --list --color --format=\"$format\" | column -s \"|\" -t\n}\n----- SNIPPET-----\n\nThis allows me to list all the keys I need and use a pipe as a separator for column formatting. I think that's quite nice while not making the format string anymore complex than it needs to be.\n\n\n> On Sep 9, 2024, at 5:03 PM, Jeff King <peff@peff.net> wrote:\n> \n> On Fri, Sep 06, 2024 at 05:09:08PM -0600, Brooke Kuhlmann wrote:\n> \n>> Use of a custom separator is a nifty trick. Thanks. A little\n>> unintuitive but works. Definitely would be neat if you patch this to\n>> work without the custom separator, though.\n> \n> The separator will always be required (even if you use multiple\n> %(trailer) blocks), because it overrides the default of terminating with\n> a newline. And we can't switch that default without breaking\n> compatibility for existing users.\n> \n> So I think after my series you'll have:\n> \n>  %(trailers:key=Files,separator=) %(trailers:key=Duration,separator=)\n> \n> or similar.\n> \n> -Peff\n\n"}]}