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

Re: [PATCH 5/5] ref-filter.c: parse trailers arguments with %(contents) atom

From
Jeff King <peff@peff.net>
Date
Sep 30, 2017, 07:36 UTC
Message-ID
<20170930073615.js3o57qmxlqnkpp5@sigill.intra.peff.net>
In-Reply-To
<20170930062238.87077-6-me@ttaylorr.com>
On Fri, Sep 29, 2017 at 11:22:38PM -0700, Taylor Blau wrote:
Show 11 quoted lines
> The %(contents) atom takes a contents "field" as its argument. Since "trailers"
> is one of those fields, extend contents_atom_parser to parse "trailers"'s
> arguments when used through "%(contents)", like:
> 
>   %(contents:trailers:unfold,only)
> 
> A caveat: trailers_atom_parser expects NULL when no arguments are given (see:
> `parse_ref_filter_atom`). To simulate this behavior without teaching
> trailers_atom_parser to accept strings with length zero, conditionally pass
> NULL to trailers_atom_parser if the arguments portion of the argument to
> %(contents) is empty.

Yeah, this is a weird effect of trailers_atom_parser() doing double-duty to parse both "%(contents:trailers)" and "%(trailers)".

Though I think trailers_atom_parser() does do the sensible thing with an empty string (there are no options, so nothing to parse). I.e., I'd expect the same thing out of:

  %(trailers:)
and
  %(trailers)

even though one gets a NULL "arg" field and the other gets an empty string.

Show 17 quoted lines
> diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
> index b7325a25d..0aaac8af9 100644
> --- a/Documentation/git-for-each-ref.txt
> +++ b/Documentation/git-for-each-ref.txt
> @@ -214,10 +214,11 @@ blank line.  The optional GPG signature is `contents:signature`.  The
>  first `N` lines of the message is obtained using `contents:lines=N`.
>  Additionally, the trailers as interpreted by linkgit:git-interpret-trailers[1]
>  are obtained as 'contents:trailers'. Non-trailer lines from the trailer block
> -can be omitted with 'trailers:only'. Whitespace-continuations can be removed
> -from trailers so that each trailer appears on a line by itself with its full
> -content with 'trailers:unfold'. Both can be used together as
> -'trailers:unfold,only'.
> +can be omitted with 'trailers:only', or 'contents:trailers:only'.
> +Whitespace-continuations can be removed from trailers so that each trailer
> +appears on a line by itself with its full content with 'trailers:unfold' or
> +'contents:trailers:unfold'. Both can be used together as 'trailers:unfold,only',
> +or 'contents:trailers:unfold,only'.

Rather than enumerate each, we might do better to just say explicitly "contents:trailers" and "trailers" are aliases of one another. It looks like we don't even document %(trailers) at all here. I'd actually be in favor of just declaring %(trailers) the official spelling, and calling "%(contents:trailers)" a historical alias.

Show 14 quoted lines
> diff --git a/ref-filter.c b/ref-filter.c
> index 8573acbed..a8d4a52bd 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -207,8 +207,10 @@ static void contents_atom_parser(struct used_atom *atom, const char *arg)
>  		atom->u.contents.option = C_SIG;
>  	else if (!strcmp(arg, "subject"))
>  		atom->u.contents.option = C_SUB;
> -	else if (!strcmp(arg, "trailers"))
> -		atom->u.contents.option = C_TRAILERS;
> +	else if (skip_prefix(arg, "trailers", &arg)) {
> +		skip_prefix(arg, ":", &arg);
> +		trailers_atom_parser(atom, strlen(arg) ? arg : NULL);
> +	}

We usually spell "is this an empty string?" as "*arg" rather than calling strlen().

However, I'm not sure we need to check. As I said above, I think trailers_atom_parser() does the sensible thing with an empty string.

And if we _did_ want to distinguish between
  %(contents:trailers:)
and
  %(contents:trailers)

then I don't think this quite does it. It passes NULL for both cases. So if we really want to emulate how parse_ref_filter_atom calls it, we'd want:

  if (!skip_prefix(arg, ":", &arg))
	arg = NULL;
  trailers_atom_parser(atom, arg);
Show 11 quoted lines
> diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
> index 2bd0c5da7..d9b71589f 100755
> --- a/t/t6300-for-each-ref.sh
> +++ b/t/t6300-for-each-ref.sh
> @@ -642,6 +642,35 @@ test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success '%(contents:trailers:unfold) unfolds trailers' '
> +  git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
> +  {
This has the same spaces/tabs thing going on as the previous commit.
-Peff
Previous: Taylor BlauNext: Jeff King
Message 15 of 78 in “Support %(trailers) arguments in for-each-ref(1)”
  1. 0/5 Support %(trailers) arguments in for-each-ref(1)Taylor Blau, Sep 30, 2017
  2. 1/5 pretty.c: delimit "%(trailers)" arguments with ","Taylor Blau, Sep 30, 2017
  3. Jeff KingSep 30, 2017
  4. 2/5 t6300: refactor %(trailers) testsTaylor Blau, Sep 30, 2017
  5. Jeff KingSep 30, 2017
  6. 3/5 ref-filter.c: add trailer options to used_atomTaylor Blau, Sep 30, 2017
  7. Jeff KingSep 30, 2017
  8. 4/5 ref-filter.c: use trailer_opts to format trailersTaylor Blau, Sep 30, 2017
  9. Jeff KingSep 30, 2017
  10. Junio C HamanoOct 1, 2017
  11. Junio C HamanoOct 1, 2017
  12. Jeff KingOct 2, 2017
  13. Taylor BlauOct 2, 2017
  14. 5/5 ref-filter.c: parse trailers arguments with %(contents) atomTaylor Blau, Sep 30, 2017
  15. Jeff KingSep 30, 2017
  16. Jeff KingSep 30, 2017
  17. 0/6 Support %(trailers) arguments in for-each-ref(1)Taylor Blau, Sep 30, 2017
  18. 1/6 pretty.c: delimit "%(trailers)" arguments with ","Taylor Blau, Sep 30, 2017
  19. 2/6 t6300: refactor %(trailers) testsTaylor Blau, Sep 30, 2017
  20. 4/6 doc: use modern "`"-style code fencingTaylor Blau, Sep 30, 2017
  21. 5/6 ref-filter.c: use trailer_opts to format trailersTaylor Blau, Sep 30, 2017
  22. 3/6 doc: 'trailers' is the preferred way to format trailersTaylor Blau, Sep 30, 2017
  23. 6/6 ref-filter.c: parse trailers arguments with %(contents) atomTaylor Blau, Sep 30, 2017
  24. Taylor BlauOct 1, 2017
  25. 1/6 pretty.c: delimit "%(trailers)" arguments with ","Taylor Blau, Oct 1, 2017
  26. 2/6 t6300: refactor %(trailers) testsTaylor Blau, Oct 1, 2017
  27. 3/6 doc: 'trailers' is the preferred way to format trailersTaylor Blau, Oct 1, 2017
  28. 4/6 doc: use modern "`"-style code fencingTaylor Blau, Oct 1, 2017
  29. 5/6 ref-filter.c: use trailer_opts to format trailersTaylor Blau, Oct 1, 2017
  30. 6/6 ref-filter.c: parse trailers arguments with %(contents) atomTaylor Blau, Oct 1, 2017
  31. Taylor BlauOct 1, 2017
  32. 1/6 pretty.c: delimit "%(trailers)" arguments with ","Taylor Blau, Oct 1, 2017
  33. 2/6 t6300: refactor %(trailers) testsTaylor Blau, Oct 1, 2017
  34. Junio C HamanoOct 2, 2017
  35. 3/6 doc: 'trailers' is the preferred way to format trailersTaylor Blau, Oct 1, 2017
  36. 4/6 doc: use modern "`"-style code fencingTaylor Blau, Oct 1, 2017
  37. Junio C HamanoOct 1, 2017
  38. Taylor BlauOct 2, 2017
  39. Junio C HamanoOct 2, 2017
  40. Jeff KingOct 2, 2017
  41. 5/6 ref-filter.c: use trailer_opts to format trailersTaylor Blau, Oct 1, 2017
  42. Junio C HamanoOct 2, 2017
  43. 6/6 ref-filter.c: parse trailers arguments with %(contents) atomTaylor Blau, Oct 1, 2017
  44. Junio C HamanoOct 2, 2017
  45. Junio C HamanoOct 2, 2017
  46. Jeff KingOct 2, 2017
  47. Taylor BlauOct 2, 2017
  48. 1/6 pretty.c: delimit "%(trailers)" arguments with ","Taylor Blau, Oct 2, 2017
  49. 2/6 t6300: refactor %(trailers) testsTaylor Blau, Oct 2, 2017
  50. 3/6 doc: 'trailers' is the preferred way to format trailersTaylor Blau, Oct 2, 2017
  51. 5/6 ref-filter.c: use trailer_opts to format trailersTaylor Blau, Oct 2, 2017
  52. 4/6 doc: use modern "`"-style code quotingTaylor Blau, Oct 2, 2017
  53. 6/6 ref-filter.c: parse trailers arguments with %(contents) atomTaylor Blau, Oct 2, 2017
  54. Junio C HamanoOct 2, 2017
  55. Junio C HamanoOct 2, 2017
  56. Taylor BlauOct 2, 2017
  57. Jeff KingOct 2, 2017
  58. Taylor BlauOct 2, 2017
  59. Jeff KingOct 2, 2017
  60. Taylor BlauOct 2, 2017
  61. 1/7 pretty.c: delimit "%(trailers)" arguments with ","Taylor Blau, Oct 2, 2017
  62. 2/7 t4205: unfold across multiple linesTaylor Blau, Oct 2, 2017
  63. 3/7 doc: 'trailers' is the preferred way to format trailersTaylor Blau, Oct 2, 2017
  64. 4/7 doc: use modern "`"-style code quotingTaylor Blau, Oct 2, 2017
  65. 6/7 ref-filter.c: use trailer_opts to format trailersTaylor Blau, Oct 2, 2017
  66. 7/7 ref-filter.c: parse trailers arguments with %(contents) atomTaylor Blau, Oct 2, 2017
  67. Jeff KingOct 2, 2017
  68. Junio C HamanoOct 2, 2017
  69. Taylor BlauOct 2, 2017
  70. Junio C HamanoOct 2, 2017
  71. 5/7 t6300: refactor %(trailers) testsTaylor Blau, Oct 2, 2017
  72. Jeff KingOct 2, 2017
  73. Junio C HamanoOct 3, 2017
  74. Jeff KingOct 3, 2017
  75. Junio C HamanoOct 3, 2017
  76. Junio C HamanoOct 2, 2017
  77. Junio C HamanoOct 2, 2017
  78. Taylor BlauOct 2, 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.