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

Re: [PATCH] rev-parse --parseopt: fix handling of optional arguments

From
Jeff King <peff@peff.net>
Date
Oct 16, 2013, 21:50 UTC
Message-ID
<20131016215047.GA10260@sigill.intra.peff.net>
In-Reply-To
<xmqqsiw051zc.fsf@gitster.dls.corp.google.com>
On Wed, Oct 16, 2013 at 02:40:07PM -0700, Junio C Hamano wrote:
Show 20 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > ... But what is the normalized form for an
> > optional argument? It either needs to be consistently "sticked" or
> > "unsticked", either:
> >
> >   set -- -S '' --     ;# default
> >   set -- -S 'foo' --  ;# not default
> >
> > or
> >
> >   set -- -S --    ;# default
> >   set -- -Sfoo -- ;# not default
> >
> > so that reading the normalized form is unambiguous.
> 
> The analysis makes sense.  Either form do not let you distinguish
> between the case where the end user wanted to explicitly pass "" as
> the optional parameter to -S and the case where she gave -S without
> any optional parameter, though.

I almost mentioned that, but I am not sure that it matters. Keep in mind that:

  git my-script -S foo

already does not involve "foo" with S, because it is not "sticked". So there is no way for the _user_ to distinguish between "I want the default" and "I passed you an empty string"; because the argument must be sticked they both look like "-S". And that distinction is already impossible in the definition of optional arguments, and is not a problem with going through the "git rev-parse --parseopt" channel at all.

So the only bug is the ambiguity in the current normalized form. Of the two forms above, I think I prefer:

  set -- -S '' --

because it more closely matches the non-optional form we produce today, and because it is slightly less work to parse (you can check that $1 is "-S", and then store or check "$2", rather than having to match "-S*" and parse off the beginning).

> Which pretty much agrees with j6t's (and my earlier) comment that
> there is no way to solve this issue completely, I think.
I guess it depends on what the issue is. :)

No, I do not think you can ever "fix" the options to let those two cases be distinguishable. But I do not think anybody is really asking for that; the real concern is that the "rev-parse --parseopt" normalization is ambiguous, and that is easily fixable.

-Peff
Previous: Junio C HamanoNext: Nicolas Vigier
Message 10 of 25 in “rev-parse --parseopt: fix handling of optional arguments”
  1. rev-parse --parseopt: fix handling of optional argumentsNicolas Vigier, Oct 15, 2013
  2. Junio C HamanoOct 15, 2013
  3. Nicolas VigierOct 15, 2013
  4. Jonathan NiederOct 15, 2013
  5. Junio C HamanoOct 15, 2013
  6. Jonathan NiederOct 15, 2013
  7. Johannes SixtOct 16, 2013
  8. Jeff KingOct 16, 2013
  9. Junio C HamanoOct 16, 2013
  10. Jeff KingOct 16, 2013
  11. Nicolas VigierOct 16, 2013
  12. Nicolas VigierOct 16, 2013
  13. Jonathan NiederOct 16, 2013
  14. rev-parse --parseopt: add the --sticked-long modeNicolas Vigier, Oct 25, 2013
  15. Junio C HamanoOct 25, 2013
  16. Nicolas VigierOct 25, 2013
  17. Junio C HamanoOct 25, 2013
  18. Philip OakleyOct 26, 2013
  19. Junio C HamanoOct 28, 2013
  20. sticked -> stuckNicolas Vigier, Oct 31, 2013
  21. 1/2 Use the word 'stuck' instead of 'sticked'Nicolas Vigier, Oct 31, 2013
  22. Junio C HamanoOct 31, 2013
  23. 2/2 rev-parse --parseopt: add the --stuck-long modeNicolas Vigier, Oct 31, 2013
  24. Michael HaggertyOct 27, 2013
  25. Nicolas VigierOct 15, 2013

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.