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

Re: [PATCH v3 1/7] git-compat-util: introduce skip_to_optional_arg()

From
Jeff King <peff@peff.net>
Date
Dec 10, 2017, 14:31 UTC
Message-ID
<20171210143118.GB19453@sigill.intra.peff.net>
In-Reply-To
<20171209204013.10997-1-chriscool@tuxfamily.org>
On Sat, Dec 09, 2017 at 09:40:07PM +0100, Christian Couder wrote:
Show 5 quoted lines
> The changes compared to v2 are:
> 
>   - s/_val/_arg/ in the name of the functions
>   - s/val/arg/ in the name of the third argument of the functions
>   - works with NULL as third argument of the functions

This whole series looks OK to me, but this third point made me wonder: what would be the use of allowing NULL for the "arg" parameter?

I didn't see any use of this in the series, and I'm having trouble figuring out how it would be useful. E.g., if I do:

  if (skip_to_optional_arg(arg, "--foo", NULL))
     ...

what can I do in "..."? I know we matched _some_ type of "--foo", but I cannot know whether it was "--foo" or "--foo=bar", nor what "bar" is. It could only be used by some kind of vague validator to say "well, at least this looks like an option that I _could_ parse if I wanted to".

So I guess I don't mind it, as it does the most reasonable thing it can when passed NULL, but I would be surprised if we ever actually exercise the code path.

-Peff
Previous: Christian CouderNext: Jeff King
Message 8 of 11 in “git-compat-util: introduce skip_to_optional_arg()”
  1. 1/7 git-compat-util: introduce skip_to_optional_arg()Christian Couder, Dec 9, 2017
  2. 2/7 index-pack: use skip_to_optional_arg()Christian Couder, Dec 9, 2017
  3. 3/7 diff: use skip_to_optional_arg()Christian Couder, Dec 9, 2017
  4. 4/7 diff: use skip_to_optional_arg_default()Christian Couder, Dec 9, 2017
  5. 5/7 diff: use skip_to_optional_arg_default() in parsing --relativeChristian Couder, Dec 9, 2017
  6. 6/7 diff: add tests for --relative without optional prefix valueChristian Couder, Dec 9, 2017
  7. 7/7 t4045: reindent to make helpers readableChristian Couder, Dec 9, 2017
  8. Jeff KingDec 10, 2017
  9. Jeff KingDec 10, 2017
  10. Christian CouderDec 11, 2017
  11. Junio C HamanoDec 11, 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.