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

Re: [PATCH v2 2/3] parse-options: make OPT_ARGUMENT() more useful

From
Jeff King <peff@peff.net>
Date
Mar 18, 2019, 21:04 UTC
Message-ID
<20190318210424.GA29661@sigill.intra.peff.net>
In-Reply-To
<xmqq7ecw7vbb.fsf@gitster-ct.c.googlers.com>
On Mon, Mar 18, 2019 at 11:47:20AM +0900, Junio C Hamano wrote:
Show 21 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> >> +`OPT_ARGUMENT(long, &int_var, description)`::
> >>  	Introduce a long-option argument that will be kept in `argv[]`.
> >> +	If this option was seen, `int_var` will be set to one (except
> >> +	if a `NULL` pointer was passed).
> >
> > So this effectively makes it into a "bool" that we keep. I think that's
> > fine. It always uses NOARG, so it is not like we would ever need to see
> > "we got --foo, and this is the argument it had".
> >
> > I did wonder if it was possible for "--no-foo" to trigger this (leaving
> > the caller who looks at the int unsure if they saw "--foo" or
> > "--no-foo"), but it seems that the parse-options code checks for
> > OPTION_ARGUMENT before it ever looks at negation.
> 
> When a caller that needs to tell --no-foo and lack of any foo
> related option arises, we should be able to update the function
> further so that the caller can initialize the variable to -1
> (unspecified) and make sure that 0 is left upon seeing --no-foo
> so it's not a show stopper, I guess.
The way it is written, I think the intent is that you would do:
  OPT_ARGUMENT("foo", &saw_foo, ...),
  OPT_ARGUMENT("no-foo", &saw_no_foo, ...),

I'm happy to punt on it until it ever comes up (which I suspect may be never).

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 13 of 17 in “Allow difftool to be run outside of Git worktrees”
  1. 0/2 Allow difftool to be run outside of Git worktreesJohannes Schindelin via GitGitGadget, Mar 13, 2019
  2. 2/2 difftool: allow running outside Git worktrees with --no-indexJohannes Schindelin via GitGitGadget, Mar 13, 2019
  3. Jeff KingMar 13, 2019
  4. Johannes SchindelinMar 14, 2019
  5. Jeff KingMar 15, 2019
  6. 1/2 difftool: remove obsolete (and misleading) commentJohannes Schindelin via GitGitGadget, Mar 13, 2019
  7. 0/3 Allow difftool to be run outside of Git worktreesJohannes Schindelin via GitGitGadget, Mar 14, 2019
  8. 1/3 difftool: remove obsolete (and misleading) commentJohannes Schindelin via GitGitGadget, Mar 14, 2019
  9. 2/3 parse-options: make OPT_ARGUMENT() more usefulJohannes Schindelin via GitGitGadget, Mar 14, 2019
  10. Jeff KingMar 15, 2019
  11. Johannes SchindelinMar 15, 2019
  12. Junio C HamanoMar 18, 2019
  13. Jeff KingMar 18, 2019
  14. Junio C HamanoMar 19, 2019
  15. 3/3 difftool: allow running outside Git worktrees with --no-indexJohannes Schindelin via GitGitGadget, Mar 14, 2019
  16. Jeff KingMar 15, 2019
  17. Johannes SchindelinMar 15, 2019

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.