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

[BUG?] trailer command with multiple keys

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Jun 6, 2016, 12:27 UTC
Message-ID
<b94e1666-2f89-619b-112c-023f72002d9d@drmicha.warpmail.net>
The command

printf "body\n\ntest: foo\ntest: froz\n" | git -c trailer.test.key=tested -c trailer.test.command="echo by \$ARG" interpret-trailers

gives:
body

tested: foo tested: froz tested: by froz

I expected the command to be run on each "test" key, resulting in the output:

body:

tested: by foo tested: by froz

(In a real life scenario, I would use ifexists replace.)[*]

Maybe my expectation is wrong? The code breaks out of the loop after the first matching in_tok, apparently intentionally so. But I'm not sure - the key is replaced for both instances.

Simply replacing that "return 1" by a "ret = 1" etc. runs into problems with the way the freeing of in_tok and arg_tok is arranged there :|

Basically, I expected the trailer command to work "grep/sed-like" on all key value pairs that have matching keys, passing the value to the command, and using the (each) command's output as the new value for each of these pairs.

Michael

[*] My prime use case: fill in reported-by etc. with short author names, completed the same way we complete --author=jun using a trailer command (interpret-trailers in the commit-msg hook):

$ git help author `git author' is aliased to `!f() { a=$(git log -1 --all -i --format="%aN <%aE>" --author "$1"); echo ${a:-$1}; }; f'

$ cat .git/hooks/commit-msg #!/bin/sh git interpret-trailers --in-place "$1"

$ git config --get-regexp trailer trailer.report.key Reported-by trailer.report.command git author '$ARG' trailer.report.ifexists replace trailer.report.ifmissing doNothing

Next: Christian Couder
Message 1 of 2 in “[BUG?] trailer command with multiple keys”
  1. Michael J GruberJun 6, 2016
  2. Christian CouderJun 6, 2016

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.