list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <>
To: Christian Couder <>
Cc:, Junio C Hamano <>,
	Donald R Laster Jr <>,
	Jacob Keller <>,
	Christian Couder <>
Subject: Re: [PATCH v3 1/7] git-compat-util: introduce skip_to_optional_arg()
Date: Sun, 10 Dec 2017 09:39:15 -0500	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On Sun, Dec 10, 2017 at 09:31:18AM -0500, Jeff King wrote:

> On Sat, Dec 09, 2017 at 09:40:07PM +0100, Christian Couder wrote:
> > 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.

And of course as soon as I sent this, I went back and double-checked.
And indeed I totally missed this call:

  +       else if (starts_with(arg, "-B") ||
  +                skip_to_optional_arg(arg, "--break-rewrites", NULL)) {
	  if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)

So that's kind-of weird, because we are parsing "-B", etc, and then
expecting it to be _reparsed_ by diff_scoreopt_parse. So the two
callsites must always match. IMHO this ought to do either:

  - we should just ask diff_scoreopt_parser to tell us if this was a
    valid option that it understood


  - parse up to the "=", and then ask the scoreopt parser to parse the
    remainder. This would require us passing 'B'/'C'/'M' to the
    function ourselves, I think that's a better pattern. It means we
    could reuse the parser for things like config values if we wanted to
    (our current diff.renames is a bool, but it would not be
    unreasonable for it to take a score).

None of that is a mess of your creation, though, so I'm OK punting on it
for now.


  reply	other threads:[~2017-12-10 14:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-09 20:40 [PATCH v3 1/7] git-compat-util: introduce skip_to_optional_arg() Christian Couder
2017-12-09 20:40 ` [PATCH v3 2/7] index-pack: use skip_to_optional_arg() Christian Couder
2017-12-09 20:40 ` [PATCH v3 3/7] diff: " Christian Couder
2017-12-09 20:40 ` [PATCH v3 4/7] diff: use skip_to_optional_arg_default() Christian Couder
2017-12-09 20:40 ` [PATCH v3 5/7] diff: use skip_to_optional_arg_default() in parsing --relative Christian Couder
2017-12-09 20:40 ` [PATCH v3 6/7] diff: add tests for --relative without optional prefix value Christian Couder
2017-12-09 20:40 ` [PATCH v3 7/7] t4045: reindent to make helpers readable Christian Couder
2017-12-10 14:31 ` [PATCH v3 1/7] git-compat-util: introduce skip_to_optional_arg() Jeff King
2017-12-10 14:39   ` Jeff King [this message]
2017-12-11  5:56     ` Christian Couder
2017-12-11 23:23     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).