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

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

From
Jeff King <peff@peff.net>
Date
May 19, 2021, 14:21 UTC
Message-ID
<YKUe5WD3ci3J4roO@coredump.intra.peff.net>
In-Reply-To
<20210519095235.cydjlj2qoko6xm4v@nabokov.fritz.box>
On Wed, May 19, 2021 at 11:52:35AM +0200, Wolfgang Müller wrote:
Show 12 quoted lines
> 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
Previous: Wolfgang MüllerNext: Wolfgang Müller
Message 11 of 12 in “rev-parse: fix segfault with missing --path-format argument”
  1. rev-parse: fix segfault with missing --path-format argumentWolfgang Müller, May 16, 2021
  2. Junio C HamanoMay 16, 2021
  3. Wolfgang MüllerMay 16, 2021
  4. Junio C HamanoMay 16, 2021
  5. Wolfgang MüllerMay 17, 2021
  6. 0/2 rev-parse: Fix segfault and translate messagesWolfgang Müller, May 17, 2021
  7. 1/2 rev-parse: fix segfault with missing --path-format argumentWolfgang Müller, May 17, 2021
  8. Jeff KingMay 17, 2021
  9. Wolfgang MüllerMay 19, 2021
  10. Wolfgang MüllerMay 19, 2021
  11. Jeff KingMay 19, 2021
  12. 2/2 rev-parse: Mark die() messages for translationWolfgang Müller, May 17, 2021

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.