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

Re: [PATCH] parse-options: warn developers on negated options

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 6, 2017, 23:41 UTC
Message-ID
<xmqqvakv2y5v.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<CAGZ79kaHHXdFMeEMfidWj7=FurR3L8VMysLrCLG3OyMtZPCgDQ@mail.gmail.com>
Stefan Beller <sbeller@google.com> writes:
Show 34 quoted lines
>> Ahh, I was an idiot (call it vacation-induced-brain-disfunction).  I
>> forgot about 0f1930c5 ("parse-options: allow positivation of options
>> starting, with no-", 2012-02-25), which may have already made your
>> new use of "--no-verify" in builtin/merge.c and existing one in
>> commit.c OK long time ago.  A quick check to see how your version of
>>
>>         git merge --verify
>>         git merge --no-verify
>>
>> behaves with respect to the commit-msg hook is veriy much
>> appreciated, as my tree is in no shape to apply and try a patch
>> while trying to absorb the patches sent to the list the past week.
>>
>> Thanks, and sorry for a possible false alarm.
>>
>>> Having said that, because the existing parse_options_check() is all
>>> about catching the programming mistake (the end user cannot fix an
>>> error from it by tweaking the command line option s/he gives to the
>>> program), I do not think a conditional compilation like you added
>>> mixes well.  Either make the whole thing, not just your new test,
>>> conditional to -DDEVELOPER (which would make it possible for you to
>>> build and ship a binary with broken options[] array to the end-users
>>> that does not die in this function), which is undesirable, or add a
>>> new test that catches a definite error unconditionally.
>>
>> This part still is valid.  If René's work 2 years ago is sufficient
>> to address "--no-foo" thing, then there is nothing we need to add to
>> this test, but if we later need to add new sanity check, we should
>> add it without -DDEVELOPER, or we should make the whole thing inside
>> it.
>
> As far as the code is concerned it is only inside the -DDEVELOPER ?
> The intent of this patch is to have a developers aid to remind them
> that too many negations might be a sign of trouble.

I understand that. What I was saying is that there may be no point "reminding" them with René's "positivation" thing in effect and that is why I asked you to try the simple two commands out to see if that is the case.

I did that myself with "git commit --[no-]verify" and they are indeed OK, so there is no reason to force developers to do this:

	int distim = 1; /* default is to distim */
	struct option options[] = {
		...
		OPT_BOOL(0, "distim", &distim, N_("distim")),
		...
	};
	...
	if (distim)
		do_the_distim_thing();
if/when the following is more natural in the context of the command:
	int no_distim = 1; /* default is to distim */
	struct option options[] = {
		...
		OPT_BOOL(0, "no-distim", &distim, N_("bypass distimming")),
		...
	};
	...
	if (distim)
		do_the_distim_thing();
whether it is inside -DDEVELOPER or not.
Previous: Stefan BellerNext: Stefan Beller
Message 7 of 19 in “builtin/merge: honor commit-msg hook for merges”
  1. builtin/merge: honor commit-msg hook for mergesStefan Beller, Sep 5, 2017
  2. Junio C HamanoSep 5, 2017
  3. parse-options: warn developers on negated optionsStefan Beller, Sep 5, 2017
  4. Junio C HamanoSep 6, 2017
  5. Junio C HamanoSep 6, 2017
  6. Stefan BellerSep 6, 2017
  7. Junio C HamanoSep 6, 2017
  8. [PATCHv2] builtin/merge: honor commit-msg hook for mergesStefan Beller, Sep 5, 2017
  9. Junio C HamanoSep 6, 2017
  10. Stefan BellerSep 6, 2017
  11. Junio C HamanoSep 6, 2017
  12. [PATCHv3] builtin/merge: honor commit-msg hook for mergesStefan Beller, Sep 7, 2017
  13. Junio C HamanoSep 8, 2017
  14. Stefan BellerSep 11, 2017
  15. Kaartic SivaraamSep 16, 2017
  16. Stefan BellerSep 20, 2017
  17. Junio C HamanoSep 21, 2017
  18. Documentation/githooks: mention merge in commit-msg hookStefan Beller, Sep 21, 2017
  19. Junio C HamanoSep 22, 2017

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.