Re: [PATCH v2 1/2] rev-parse: fix segfault with missing --path-format argument

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 19, 2021 at 11:52:35AM +0200, Wolfgang Müller wrote:

> On 2021-05-17 04:16, Jeff King wrote:
> 
> > I don't have a strong preference for one or the other. It is maybe
> > helpful to diagnose "--path-format" without an equals as an error, as
> > your patch would, rather than quietly passing it along as an unknown
> > (as the hunk above would). I dunno. That perhaps applies to the rest
> > of the options, too. :)
> 
> I have a very slight preference for throwing an error: that is what I
> expected to happen as a user. At the same time, passing it along as an
> unknown seems more consistent with the other options that take equals.
> I'm split on this, and would defer to what people here prefer.

Yeah, I don't feel strongly at all. I like consistency, but noticing
bogus input is good, too. ;)

> Short of fully migrating to the parse-options API, I do not see a
> perfect solution for this, especially since there are options that take
> optional arguments which are not delimited by equals. These seem to be
> sprinkled throughout and all error out if no argument is given.

Ultimately I think using the parse-options API would be nice. In the
meantime, I suspect (but didn't think too hard on it) that you could get
by with two helpers:

  - rename the current opt_with_value() to opt_with_optional_value()
    to make its assumptions clear.

  - add a new helper opt_with_required_value() that accepts either:

      --default <arg>
      --default=<arg>
      --disambiguate <arg>
      --disambiguate=<arg>
      etc...

     and complains when the "=" is missing, or there is no extra "<arg>"
     available.

The second helper is a little tricky to write, because it sometimes
needs to advance argv (and decrement argc) to account for the extra
consumed arg.

That's definitely something we can leave off for now, though.

> So it turns out that my hunch was not really correct. Maybe there's also
> a pattern that I am not seeing.

I don't find it hard to believe that there's no obvious pattern. :) I
would say that rev-parse is one of the messiest and most "organically
grown" parts of Git.

Thanks for digging, though. It is always nice to see contributors going
the extra mile to figure out how their solutions fit into the bigger
picture of the project.

-Peff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux