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

Re: [PATCH] t6300: values containing ')' are broken in ref formats

From
Jeff King <peff@peff.net>
Date
Nov 8, 2024, 17:16 UTC
Message-ID
<20241108171637.GA548990@coredump.intra.peff.net>
In-Reply-To
<Zy2PV+yywkS64D1p@five231003>
On Fri, Nov 08, 2024 at 09:41:03AM +0530, Kousik Sanagavarapu wrote:
Show 23 quoted lines
> > Then things like
> > 
> >   %(if:equals=%(upstream:lstrip=3))%(refname:short)%(then)...
> 
> So if I understand correctly, we grab the .str and operate on it so that
> we expand the atom within it and then do the comparision.
> 
> This seems nice, but there is a problem.  Since we always look for the
> first occurring ')' in our format string to indicate the end of the atom,
> we end up with
> 
> 	.str = %(upstream:lstrip=3
> 
> (the call chain is
> 
> 	verify_ref_format() -> parse_ref_filter_atom() -> if_atom_parser()
> )
> 
> Since we have now left out a ')', this ')' gets appended to our output
> buf, which would also show up in cur->output when we do the comparision
> in then_atom_handler().  For example, in this case our cur->output would
> be ")master" instead of "master" after we get the value of
> %(refname:short), meaning our comparision always fails.

Yes, though I think the parser _could_ be improved here. This is different the earlier case of matching "ref-with-)". In that case it is syntactically ambiguous. For example given:

  %(if:equals=ref-with-))foo
you cannot tell the difference between:
  - matching "ref-with-)", followed by "foo"
  - matching "ref-with-", followed by ")foo"
But if the parenthesis in question is closing a %() item, like:
  %(if:equals=%(refname))foo

then we know that the inner ")" is closing %(refname), since parsing it as "%(refname" followed by ")foo" would leave an unbalanced pair. But finding that would require a real recursive descent parser, rather than a blind strchr() for the closing ")"[1].

In the meantime yeah, you'd have to spell it as:
  %(if:equals=%(refname%29)
which is...deeply unsatisfying.

I have long dreamed of throwing out all of this format code in favor of a recursive parser which generates an actual tree of nodes, and implements all of the ref-filter/pretty.c/cat-file format placeholders. But I think it's a non-trivial task.

-Peff
[1] Incidentally, the "%)" I proposed earlier would also fall afoul of
    this problem. The search for the closing ")" is done blindly without
    regard to possible quoting.
Previous: Kousik SanagavarapuNext: Kousik Sanagavarapu
Message 12 of 14 in “t6300: values containing ')' are broken in ref formats”
  1. t6300: values containing ')' are broken in ref formatsKousik Sanagavarapu, Nov 5, 2024
  2. Junio C HamanoNov 6, 2024
  3. Jeff KingNov 6, 2024
  4. Junio C HamanoNov 6, 2024
  5. Kousik SanagavarapuNov 6, 2024
  6. Jeff KingNov 6, 2024
  7. Kousik SanagavarapuNov 7, 2024
  8. Jeff KingNov 6, 2024
  9. Kousik SanagavarapuNov 7, 2024
  10. Junio C HamanoNov 7, 2024
  11. Kousik SanagavarapuNov 8, 2024
  12. Jeff KingNov 8, 2024
  13. Kousik SanagavarapuNov 8, 2024
  14. Kousik SanagavarapuNov 6, 2024

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.