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

Re: [PATCH] push: comment on a funny unbalanced option help

From
Jeff King <peff@peff.net>
Date
Aug 2, 2018, 16:54 UTC
Message-ID
<20180802165457.GC15984@sigill.intra.peff.net>
In-Reply-To
<xmqqftzw4weq.fsf@gitster-ct.c.googlers.com>
On Thu, Aug 02, 2018 at 08:31:57AM -0700, Junio C Hamano wrote:
Show 20 quoted lines
> > diff --git a/parse-options.c b/parse-options.c
> > index 7db84227ab..fadfc6a833 100644
> > --- a/parse-options.c
> > +++ b/parse-options.c
> > @@ -660,7 +660,8 @@ int parse_options(int argc, const char **argv, const char *prefix,
> >  static int usage_argh(const struct option *opts, FILE *outfile)
> >  {
> >  	const char *s;
> > -	int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh;
> > +	int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh ||
> > +		(opts->argh[0] == '<' && strchr(opts->argh, '>'));
> 
> You are greedier than what I thought ;-) I would have limited this
> magic to the case where argh is surrounded by "<>", but you allow
> one closing ">" anywhere, which allows us to grab more complex cases.
> 
> The lack of escape hatch to decline this auto-literal magic makes me
> somewhat nervous, but I do not offhand think of a reason why I do
> want an arg-help string that _begins_ with '<' to be enclosed by
> another set of "<>", so perhaps this is a good kind of magic.

I think that case is actually easy; once the caller provides a "<>", they are in "literal" mode, so they are free to add extra brackets if you want. I.e., any "<foo>bar" that you do want enclosed could be spelled "<<foo>bar>". It's the opposite that becomes impossible: you do not have an opening bracket and nor do you want one. But as long as we retain LITERAL_ARGHELP for that case, we have an escape hatch.

I was going to suggest that this conversion has the downside of being somewhat one-way. That is, it is easy for us to find affected sites now since they contain the string LITERAL_ARGHELP. Whereas if we wanted to back it out in the future, it is hard to know which sites are depending on this new behavior.

But I am having trouble thinking of a reason we would want to back it out. This makes most cases easier, and has a good escape hatch.

-Peff
PS I actually would have made the rule simply "does it begin with a
   '<'", which seems simpler still. If people accidentally write "<foo",
   forgetting to close their brackets, that is a bug under both the
   old and new behavior (just with slightly different outcomes).
Previous: René ScharfeNext: René Scharfe
Message 12 of 38 in “push: comment on a funny unbalanced option help”
  1. push: comment on a funny unbalanced option helpJunio C Hamano, Aug 1, 2018
  2. Ævar Arnfjörð BjarmasonAug 1, 2018
  3. Junio C HamanoAug 1, 2018
  4. Ævar Arnfjörð BjarmasonAug 1, 2018
  5. René ScharfeAug 2, 2018
  6. Ævar Arnfjörð BjarmasonAug 2, 2018
  7. René ScharfeAug 2, 2018
  8. René ScharfeAug 2, 2018
  9. Junio C HamanoAug 2, 2018
  10. Junio C HamanoAug 2, 2018
  11. René ScharfeAug 2, 2018
  12. Jeff KingAug 2, 2018
  13. René ScharfeAug 2, 2018
  14. 1/6 add, update-index: fix --chmod argument helpRené Scharfe, Aug 2, 2018
  15. Ævar Arnfjörð BjarmasonAug 2, 2018
  16. Ramsay JonesAug 2, 2018
  17. Junio C HamanoAug 2, 2018
  18. Andrei RybakAug 2, 2018
  19. Junio C HamanoAug 2, 2018
  20. 2/6 difftool: remove angular brackets from argument helpRené Scharfe, Aug 2, 2018
  21. 3/6 pack-objects: specify --index-version argument help explicitlyRené Scharfe, Aug 2, 2018
  22. 4/6 send-pack: specify --force-with-lease argument help explicitlyRené Scharfe, Aug 2, 2018
  23. 5/6 shortlog: correct option help for -wRené Scharfe, Aug 2, 2018
  24. 6/6 parse-options: automatically infer PARSE_OPT_LITERAL_ARGHELPRené Scharfe, Aug 2, 2018
  25. Junio C HamanoAug 2, 2018
  26. Kerry, RichardAug 3, 2018
  27. Kerry, RichardAug 3, 2018
  28. Junio C HamanoAug 2, 2018
  29. René ScharfeAug 2, 2018
  30. Junio C HamanoAug 3, 2018
  31. Re* [PATCH] push: comment on a funny unbalanced option helpJunio C Hamano, Aug 2, 2018
  32. René ScharfeAug 2, 2018
  33. Junio C HamanoAug 2, 2018
  34. Ævar Arnfjörð BjarmasonAug 2, 2018
  35. Junio C HamanoAug 2, 2018
  36. René ScharfeAug 3, 2018
  37. Junio C HamanoAug 3, 2018
  38. Jonathan NiederAug 1, 2018

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.