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

Re: Parse --o in format-patch

From
Jeff King <peff@peff.net>
Date
Jun 28, 2013, 16:31 UTC
Message-ID
<20130628163153.GA9127@sigill.intra.peff.net>
In-Reply-To
<20130628160459.GA16832@paksenarrion.iveqy.com>
On Fri, Jun 28, 2013 at 06:05:00PM +0200, Fredrik Gustafsson wrote:
Show 12 quoted lines
> I don't quite manage to figure out gits argv parsing and would need some
> help on the way.
> 
> I want:
> git format-patch -o outdir HEAD~
> 
> Work exactly the way it does now, setting output_directory to outdir.
> But I also want
> git format-patch -o HEAD~
> 
> to set output_directory with a NULL value so that I can assign a default
> value to it. Is that even possible with the current argv-parsing implementation?

It's possible to have an "optional" argument by using the PARSE_OPT_OPTARG flag. However, it is not backwards compatible from the user's perspective, as they must use the "sticked" form:

  git format-patch -ooutdir ...
to specify the argument. Otherwise, it is not clear in:
  git format-patch -o outdir HEAD~

whether "outdir" is the argument to "-o", or if it is simply the next argument.

However, if you are just interested in "turning off" a previously given argument, we usually spell that with the "--no-" prefix to the long option (e.g., "--no-output-directory" in this case).

I'm not clear how that interacts with your example, though. Your example tries to use "-o" to set output_directory to NULL. But it is already NULL if you do not specify any "-o" at all.

-Peff
Previous: Fredrik GustafssonNext: Fredrik Gustafsson
Message 2 of 4 in “Parse --o in format-patch”
  1. Fredrik GustafssonJun 28, 2013
  2. Jeff KingJun 28, 2013
  3. Fredrik GustafssonJun 28, 2013
  4. Jeff KingJun 28, 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.