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

[PATCH v4 0/8] trailer parsing via interpret-trailers and %(trailers)

From
Jeff King <peff@peff.net>
Date
Aug 15, 2017, 10:22 UTC
Message-ID
<20170815102254.knccmhgralfijwli@sigill.intra.peff.net>
In-Reply-To
<20170810180326.4kkmawywvdbuzwnp@sigill.intra.peff.net>

Here's a fourth version of my series to make the output of interpret-trailers useful for callers who just want to parse existing trailers.

The big change here is that I added similar features to pretty.c's "%(trailers)", meaning you can now efficiently get the same output for multiple commits with a single invocation. Like:

  $ git rev-list --no-walk --format='%(trailers:only:unfold)' \
    3ac53e0d13fa7483cce90eb6a1cfcdcbda5b8e35
  commit 3ac53e0d13fa7483cce90eb6a1cfcdcbda5b8e35
  Signed-off-by: H. Peter Anvin <hpa@zytor.com>
  Signed-off-by: Junio C Hamano <junkio@cox.net>

That doesn't look very exciting, but with just "%(trailers)" you would see that the block also contains a "cherry-picked from" line. There aren't good examples of unfolding in git.git because we don't tend to fold. Nor does linux.git (though they do have a lot of non-trailer lines in square brackets). The tests show off some samples of both.

I left %(trailers) exactly as it is: it shows the trailer block verbatim, including funny syntax, etc. As soon as you use one of :only or :unfold, we have to parse further, and as a side effect we normalize a few bits (like whitespace around separators), because we round-trip through the parser. I think that's fine and what callers would want. But it did make me wonder if I should just have a single "parse" option that does all that normalizing. Or alternatively, have %(trailers) always do that round-trip normalizing. That's how interpret-trailers behaves, after all(since it always parses and reconstructs the trailer block). I felt better taking the conservative route, though, and leaving %(trailers) alone.

There are a few other changes from v3:
  - the --normalize option is now --unfold (and I matched it with
    ":unfold" for the placeholder)
  - the process_input_file function now takes the
    process_trailer_options to check "only_trailers" instead of taking a
    hint from a NULL outfile. This is hopefully a bit more obvious.
  - when only_trailers is set, I don't even bother adding non-trailers
    from the middle of the trailer-block to the list (we know we'd never
    output them, and they can't affect the trailer rules). This is just
    a micro-optimization I noticed while writing the %(trailers) helper.
  - Similarly, we no longer unfold non-trailers. So if you have:
      key: value
        more value
      this is not a trailer
        this is also not a trailer
    we would unfold "key: value more value", but not the other two
    lines. Because without a separator, that's not really folding. I'm
    not sure it actually matters. It's hard to have non-trailers in the
    block in the first place. But I think the new behavior is the right
    thing if it ever does come up.
  [1/8]: trailer: put process_trailers() options into a struct
  [2/8]: interpret-trailers: add an option to show only the trailers
  [3/8]: interpret-trailers: add an option to show only existing trailers
  [4/8]: interpret-trailers: add an option to unfold values
  [5/8]: interpret-trailers: add --parse convenience option
  [6/8]: pretty: move trailer formatting to trailer.c
  [7/8]: t4205: refactor %(trailer) tests
  [8/8]: pretty: support normalization options for %(trailers)
 Documentation/git-interpret-trailers.txt |  33 +++++++--
 Documentation/pretty-formats.txt         |   5 +-
 builtin/interpret-trailers.c             |  34 +++++++--
 pretty.c                                 |  26 +++----
 t/t4205-log-pretty-formats.sh            |  51 ++++++++++++--
 t/t7513-interpret-trailers.sh            |  76 ++++++++++++++++++++
 trailer.c                                | 115 ++++++++++++++++++++++++++-----
 trailer.h                                |  27 +++++++-
 8 files changed, 315 insertions(+), 52 deletions(-)
-Peff
Previous: Junio C HamanoNext: Jeff King
Message 57 of 68 in “make interpret-trailers useful for parsing”
  1. 0/5 make interpret-trailers useful for parsingJeff King, Aug 9, 2017
  2. 1/5 trailer: put process_trailers() options into a structJeff King, Aug 9, 2017
  3. 2/5 interpret-trailers: add an option to show only the trailersJeff King, Aug 9, 2017
  4. Stefan BellerAug 9, 2017
  5. Stefan BellerAug 9, 2017
  6. Jonathan TanAug 9, 2017
  7. Jeff KingAug 10, 2017
  8. 3/5 interpret-trailers: add an option to show only existing trailersJeff King, Aug 9, 2017
  9. Stefan BellerAug 9, 2017
  10. Jeff KingAug 10, 2017
  11. Stefan BellerAug 10, 2017
  12. Jeff KingAug 10, 2017
  13. Stefan BellerAug 10, 2017
  14. Junio C HamanoAug 10, 2017
  15. Jonathan TanAug 9, 2017
  16. Jeff KingAug 10, 2017
  17. 4/5 interpret-trailers: add an option to normalize outputJeff King, Aug 9, 2017
  18. 5/5 interpret-trailers: add --parse convenience optionJeff King, Aug 9, 2017
  19. Stefan BellerAug 9, 2017
  20. Jeff KingAug 10, 2017
  21. Junio C HamanoAug 9, 2017
  22. Jacob KellerAug 10, 2017
  23. Jeff KingAug 10, 2017
  24. Junio C HamanoAug 10, 2017
  25. Jacob KellerAug 13, 2017
  26. Jeff KingAug 10, 2017
  27. 1/5 trailer: put process_trailers() options into a structJeff King, Aug 10, 2017
  28. 2/5 interpret-trailers: add an option to show only the trailersJeff King, Aug 10, 2017
  29. 3/5 interpret-trailers: add an option to show only existing trailersJeff King, Aug 10, 2017
  30. 4/5 interpret-trailers: add an option to normalize outputJeff King, Aug 10, 2017
  31. Stefan BellerAug 10, 2017
  32. Jeff KingAug 10, 2017
  33. Christian CouderAug 10, 2017
  34. Jeff KingAug 10, 2017
  35. Christian CouderAug 10, 2017
  36. Stefan BellerAug 10, 2017
  37. Christian CouderAug 10, 2017
  38. Jeff KingAug 10, 2017
  39. Ramsay JonesAug 10, 2017
  40. Jeff KingAug 10, 2017
  41. Ramsay JonesAug 10, 2017
  42. Christian CouderAug 11, 2017
  43. Jeff KingAug 11, 2017
  44. Christian CouderAug 11, 2017
  45. 5/5 interpret-trailers: add --parse convenience optionJeff King, Aug 10, 2017
  46. Jeff KingAug 10, 2017
  47. 1/5 trailer: put process_trailers() options into a structJeff King, Aug 10, 2017
  48. 2/5 interpret-trailers: add an option to show only the trailersJeff King, Aug 10, 2017
  49. Stefan BellerAug 10, 2017
  50. Jeff KingAug 10, 2017
  51. Junio C HamanoAug 10, 2017
  52. 3/5 interpret-trailers: add an option to show only existing trailersJeff King, Aug 10, 2017
  53. 4/5 interpret-trailers: add an option to normalize outputJeff King, Aug 10, 2017
  54. 5/5 interpret-trailers: add --parse convenience optionJeff King, Aug 10, 2017
  55. Stefan BellerAug 10, 2017
  56. Junio C HamanoAug 10, 2017
  57. 0/8 trailer parsing via interpret-trailers and %(trailers)Jeff King, Aug 15, 2017
  58. 1/8 trailer: put process_trailers() options into a structJeff King, Aug 15, 2017
  59. 2/8 interpret-trailers: add an option to show only the trailersJeff King, Aug 15, 2017
  60. 3/8 interpret-trailers: add an option to show only existing trailersJeff King, Aug 15, 2017
  61. 4/8 interpret-trailers: add an option to unfold valuesJeff King, Aug 15, 2017
  62. 5/8 interpret-trailers: add --parse convenience optionJeff King, Aug 15, 2017
  63. Martin ÅgrenAug 15, 2017
  64. Jeff KingAug 16, 2017
  65. Martin ÅgrenAug 17, 2017
  66. 6/8 pretty: move trailer formatting to trailer.cJeff King, Aug 15, 2017
  67. 7/8 t4205: refactor %(trailers) testsJeff King, Aug 15, 2017
  68. 8/8 pretty: support normalization options for %(trailers)Jeff King, Aug 15, 2017

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.