git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Pranit Bauva <pranit.bauva@gmail.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH v12 3/5] parse-options.c: make OPTION_COUNTUP respect "unspecified" values
Date: Tue, 5 Apr 2016 21:21:32 +0530	[thread overview]
Message-ID: <CAFZEwPPvwiw4E78vYA_jpLAfASS-M0fxPopnbFSLd4yomzVciA@mail.gmail.com> (raw)
In-Reply-To: <CAPig+cS23i9XFTntLTHRbNf21DxhLAcw+9ent_ZtWj=1aO7JwQ@mail.gmail.com>

On Mon, Apr 4, 2016 at 4:40 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Sat, Apr 2, 2016 at 7:33 PM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
>> The reason to make it respect "unspecified" values is to give the
>> ability to differentiate whether `--option` or `--no-option` was
>> specified at all. "unspecified" values should be in the form of negative
>> values. If initial value is set to negative and `--option` specified
>> then it will reflect the number of occurrences (counting done from 0),
>> if `--no-option` is specified then it will reflect 0 and if nothing at
>> all is given then it will retain its negative value.
>
> Thanks, this rewrite does a better job of explaining the aim of the
> change and how a client can take advantage of it. However, with my
> "first-time reader" hat on, I still have some trouble digesting it as
> a coherent whole. I wonder if a rewrite like this would help?
>
>     OPT_COUNTUP() merely increments the counter upon --option, and
>     resets it to 0 upon --no-option, which means that there is no
>     "unspecified" value with which a client can initialize the
>     counter to determine whether or not --[no-]option was seen at
>     all.
>
>     Make OPT_COUNTUP() treat any negative number as an "unspecified"
>     value to address this shortcoming. In particular, if a client
>     initializes the counter to -1, then if it is still -1 after
>     parse_options(), then neither --option nor --no-option was seen;
>     if it is 0, then --no-option was seen last, and if it is 1 or
>     greater, than --option was seen last.
>
>> This change will not affect existing users of COUNTUP, because they all
>> use the initial value of 0 (or more).
>
>     "This change does not affect behavior of existing clients of..."
>

Sure I could do the change.

>> Note that builtin/clean.c initializes the variable used with
>> OPT__FORCE (which uses OPT_COUNTUP()) to a negative value, but it is set
>> to either 0 or 1 by reading the configuration before the code calls
>> parse_options(), i.e. as far as parse_options() is concerned, the
>> initial value of the variable is not negative.
>>
>> To test this behavior "verbose" is set to "unspecified" while quiet is
>> set to 0 which will test the new behavior with all sets of values.
>
> I think you need to mention here that you're talking about test-parse-options.c
> (and indirectly t0040) since it's otherwise too easy for the reader to
> think that this paragraph is a continuation of the discussion about
> OPT_COUNTUP()'s new behavior and how it won't impact existing tests,
> rather than a new topic of its own (testing the behavior). Maybe say
> something like this:
>
>     To test the new behavior, augment the initial "verbose" setting
>     of test-parse-options.c to be unspecified...
>
> and then go on to say that, because "quiet" is still initialized to 0,
> you have complete coverage. An alternative would be to split off the
> new testing into its own patch, which would make this patch (which is
> the real meat of the change) less noisy.

I do like including test-parse-options.c in commit message. My main
motive behind including the test with this patch was to show the
"first-time" reader how to use the changes introduced in this patch.
This would also set a complete picture of this commit. And I kind of
believe it is much effort for the reader to find the commit whose
parent will be this (if it exists at all, as the reader won't know
about it) which will give a kind of demonstration to utilizing this
change.

>
> I actually expected you to add new functionality to
> test-parse-options.c specifically to test OPT_COUNTUP() directly
> rather than indirectly through --verbose and --quiet, however, I think
> I can be sold on the approach you took for a couple reasons. First,
> you have a genuine use-case for an "unspecified" --verbose value, so
> changing test-parse-options.c's --verbose to start at -1 tests what
> you ultimately care about. Second, since you retained 0-initialization
> of --quiet, that case of OPT_COUNTUP() is still being tested.
>
> What I find a bit disturbing about this approach is that you are
> getting "full coverage" only because of current *implementation*, not
> because you are explicitly testing for *expected* behavior. That is,
> you get that coverage only while both OPT__VERBOSE() and OPT__QUIET()
> are built atop OPT_COUNTUP(); if OPT__QUIET() is ever rewritten so it
> no longer uses OPT_COUNTUP(), then the tests silently lose full
> coverage. However, I may be over-worrying about the situation...

The main reason as I mentioned above was to give a demonstration of
how to utilize the change introduced.

>
>> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
>> ---
>> diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
>> @@ -144,8 +144,12 @@ There are some macros to easily define options:
>>  `OPT_COUNTUP(short, long, &int_var, description)`::
>>         Introduce a count-up option.
>> -       `int_var` is incremented on each use of `--option`, and
>> -       reset to zero with `--no-option`.
>> +       Each use of `--option` increments `int_var`, starting from zero
>> +       (even if initially negative), and `--no-option` resets it to
>> +       zero. To determine if `--option` or `--no-option` was set at
>
> s/was set/was encountered/
>
>> +       all, set `int_var` to a negative value, and if it is still
>
> s/set `int_var`/initialize `int_var`/
>
>> +       negative after parse_options(), then neither `--option` nor
>> +       `--no-option` was seen.
>> diff --git a/parse-options.c b/parse-options.c
>> @@ -110,6 +110,8 @@ static int get_value(struct parse_opt_ctx_t *p,
>>         case OPTION_COUNTUP:
>> +               if (*(int *)opt->value < 0)
>> +                       *(int *)opt->value = 0;
>>                 *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;
>
> This is nicer.
>
>>                 return 0;
>> diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
>> @@ -454,6 +454,25 @@ dry run: no
>> +test_expect_success 'OPT_COUNTUP() resets to 0 with --no- flag' '
>> +       test-parse-options --no-verbose >output 2>output.err &&
>> +       test_must_be_empty output.err &&
>> +       test_cmp expect output
>> +'
>
> If you take the advice of my 2/5 review and add new tests (in a new
> patch) which test --no-verbose and --no-quiet, then I think this new
> test here can just go away since the case it cares about will already
> be covered.

Adding a new patch between 2/5 and 3/5 would be a better choice.

  reply	other threads:[~2016-04-05 15:51 UTC|newest]

Thread overview: 136+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-14 21:38 [PATCH v7] commit: add a commit.verbose config variable Pranit Bauva
2016-03-15 11:31 ` SZEDER Gábor
2016-03-15 19:00   ` Pranit Bauva
2016-03-15 19:24     ` Eric Sunshine
2016-03-15 20:13       ` Pranit Bauva
2016-03-15 20:24         ` Junio C Hamano
2016-03-15 21:09           ` Pranit Bauva
2016-03-15 21:16             ` Junio C Hamano
2016-03-15 21:18               ` Pranit Bauva
2016-03-18 21:19 ` [PATCH v8 1/2] parse-options.c: make OPTION__COUNTUP consider negative values Pranit Bauva
2016-03-18 21:19   ` [PATCH v8 2/2] commit: add a commit.verbose config variable Pranit Bauva
2016-03-20  3:56     ` Eric Sunshine
2016-03-20 11:05       ` Pranit Bauva
2016-03-20 17:34         ` Eric Sunshine
2016-03-20 18:02           ` Pranit Bauva
2016-03-23 19:19             ` Junio C Hamano
2016-03-23 19:23               ` Pranit Bauva
2016-03-23 20:43                 ` Junio C Hamano
2016-03-24  8:25     ` [PATCH v9 1/3] parse-options.c: make OPTION__COUNTUP consider negative values Pranit Bauva
2016-03-24  8:25       ` [PATCH v9 2/3] t7507-commit-verbose: make test suite use write_script Pranit Bauva
2016-03-24 11:00         ` SZEDER Gábor
2016-03-24 23:57           ` Eric Sunshine
2016-03-25  6:06             ` Pranit Bauva
2016-03-25  6:24               ` Eric Sunshine
2016-03-25  6:55                 ` Pranit Bauva
2016-03-25 14:46             ` SZEDER Gábor
2016-03-25 14:50               ` Pranit Bauva
2016-03-25 17:04               ` Eric Sunshine
2016-03-25 18:15                 ` Pranit Bauva
2016-03-25 23:06                   ` Eric Sunshine
2016-03-24  8:25       ` [PATCH v9 3/3] commit: add a commit.verbose config variable Pranit Bauva
2016-03-24 10:04         ` SZEDER Gábor
2016-03-24 10:22           ` Pranit Bauva
2016-03-24 10:26             ` Pranit Bauva
2016-03-25  0:05         ` Eric Sunshine
2016-03-25  6:15           ` Pranit Bauva
2016-03-24 10:33       ` [PATCH v9 1/3] parse-options.c: make OPTION__COUNTUP consider negative values SZEDER Gábor
2016-03-24 10:38         ` Pranit Bauva
2016-03-24 23:34         ` Eric Sunshine
2016-03-28 18:42         ` Pranit Bauva
2016-03-28 19:03           ` Eric Sunshine
2016-03-26 19:48       ` [PATCH v10 1/3] parse-options.c: make OPTION__COUNTUP understand "unspecified" values Pranit Bauva
2016-03-26 19:48         ` [PATCH v10 2/3] t7507-commit-verbose: store output of grep in a file Pranit Bauva
2016-03-27  3:07           ` Eric Sunshine
2016-03-27 13:27             ` SZEDER Gábor
2016-03-27 13:43               ` Pranit Bauva
2016-03-27 17:27               ` Eric Sunshine
2016-03-27 18:31                 ` Pranit Bauva
     [not found]             ` <CAFZEwPMaZkUi+DvohhVrc_dW_8cdfJsZX-YA_SRWDp021UvDLQ@mail.gmail.com>
2016-03-27 17:03               ` Eric Sunshine
     [not found]               ` <CAPig+cTFK=HPAtk7MeMQSTccmiaai++3sVn6J_pRcSi+w_4Lng@mail.gmail.com>
2016-03-27 17:05                 ` Eric Sunshine
     [not found]                 ` <CAFZEwPMJiCTKszfCAVrzsA+jNHwoHPaXySSD3HyiO=f5AikvZg@mail.gmail.com>
     [not found]                   ` <CAPig+cS3usDDeTMzjqbxqi+k+XbmjawZ0TF20s9-vM6o=Fm=OQ@mail.gmail.com>
2016-03-27 17:08                     ` Eric Sunshine
2016-03-26 19:48         ` [PATCH v10 3/3] commit: add a commit.verbose config variable Pranit Bauva
2016-03-27  3:34           ` Eric Sunshine
2016-03-27  7:00             ` Pranit Bauva
2016-03-27  8:17               ` Eric Sunshine
2016-03-27  8:40                 ` Pranit Bauva
2016-03-27 11:51           ` SZEDER Gábor
2016-03-27 11:59             ` Pranit Bauva
2016-03-27 12:07               ` SZEDER Gábor
2016-03-27 12:11                 ` Pranit Bauva
2016-03-27 16:48               ` Eric Sunshine
2016-03-27  2:45         ` [PATCH v10 1/3] parse-options.c: make OPTION__COUNTUP understand "unspecified" values Eric Sunshine
2016-03-27  6:10           ` Pranit Bauva
2016-03-31 14:45         ` [PATCH v11 1/4] test-parse-options: print quiet as integer Pranit Bauva
2016-03-31 14:45           ` [PATCH v11 4/4] commit: add a commit.verbose config variable Pranit Bauva
2016-03-31 14:45           ` [PATCH v11 2/4] parse-options.c: make OPTION_COUNTUP respect "unspecified" values Pranit Bauva
2016-03-31 18:41             ` Junio C Hamano
2016-03-31 19:34               ` Pranit Bauva
2016-03-31 20:06                 ` Junio C Hamano
2016-03-31 20:41                   ` Pranit Bauva
2016-03-31 20:45                     ` Junio C Hamano
2016-03-31 14:45           ` [PATCH v11 3/4] t7507-commit-verbose: improve test coverage by testing number of diffs Pranit Bauva
2016-03-31 18:23             ` Junio C Hamano
2016-03-31 18:42               ` Pranit Bauva
2016-03-31 18:19           ` [PATCH v11 1/4] test-parse-options: print quiet as integer Junio C Hamano
2016-03-31 18:40             ` Pranit Bauva
2016-04-02 23:33           ` [PATCH v12 1/5] t0040-test-parse-options.sh: fix style issues Pranit Bauva
2016-04-02 23:33             ` [PATCH v12 2/5] test-parse-options: print quiet as integer Pranit Bauva
2016-04-03 21:30               ` Eric Sunshine
2016-04-05 15:39                 ` Pranit Bauva
2016-04-06  5:56                   ` Eric Sunshine
2016-04-08 11:33                   ` Duy Nguyen
2016-04-08 16:52                 ` Junio C Hamano
2016-04-02 23:33             ` [PATCH v12 4/5] t7507-commit-verbose: improve test coverage by testing number of diffs Pranit Bauva
2016-04-04  0:02               ` Eric Sunshine
2016-04-04  1:05                 ` Eric Sunshine
2016-04-05 15:54                 ` Pranit Bauva
2016-04-02 23:33             ` [PATCH v12 3/5] parse-options.c: make OPTION_COUNTUP respect "unspecified" values Pranit Bauva
2016-04-03 23:10               ` Eric Sunshine
2016-04-05 15:51                 ` Pranit Bauva [this message]
2016-04-02 23:33             ` [PATCH v12 5/5] commit: add a commit.verbose config variable Pranit Bauva
2016-04-04  0:58               ` Eric Sunshine
2016-04-04 23:29                 ` Eric Sunshine
2016-04-05 15:58                   ` Pranit Bauva
2016-04-03 21:00             ` [PATCH v12 1/5] t0040-test-parse-options.sh: fix style issues Eric Sunshine
2016-04-04 12:45               ` Pranit Bauva
2016-04-04 17:30                 ` Eric Sunshine
2016-04-05  5:08                   ` Pranit Bauva
2016-04-09 12:23             ` [PATCH v13 1/6] " Pranit Bauva
2016-04-09 12:23               ` [PATCH v13 3/6] t0040-parse-options: improve test coverage Pranit Bauva
2016-04-09 12:23               ` [PATCH v13 5/6] t7507-commit-verbose: improve test coverage by testing number of diffs Pranit Bauva
2016-04-09 12:23               ` [PATCH v13 6/6] commit: add a commit.verbose config variable Pranit Bauva
2016-04-12 21:24                 ` Junio C Hamano
2016-04-12 21:28                   ` Pranit Bauva
2016-04-12 21:39                   ` Junio C Hamano
2016-04-12 22:18                     ` Junio C Hamano
2016-04-12 22:25                       ` Pranit Bauva
2016-04-09 12:23               ` [PATCH v13 4/6] parse-options.c: make OPTION_COUNTUP respect "unspecified" values Pranit Bauva
2016-04-09 12:23               ` [PATCH v13 2/6] test-parse-options: print quiet as integer Pranit Bauva
2016-04-12 21:33                 ` Junio C Hamano
2016-04-12 22:16                   ` Pranit Bauva
2016-04-12 23:11                     ` Junio C Hamano
2016-04-12 23:02               ` [PATCH v14 1/6] t0040-test-parse-options.sh: fix style issues Pranit Bauva
2016-04-12 23:02                 ` [PATCH v14 5/6] t7507-commit-verbose: improve test coverage by testing number of diffs Pranit Bauva
2016-04-13  6:03                   ` Eric Sunshine
2016-04-13  9:00                     ` Pranit Bauva
2016-04-12 23:02                 ` [PATCH v14 6/6] commit: add a commit.verbose config variable Pranit Bauva
2016-04-13  6:14                   ` Eric Sunshine
2016-04-13  9:15                     ` Pranit Bauva
2016-04-13 17:44                       ` Eric Sunshine
2016-04-12 23:02                 ` [PATCH v14 3/6] t0040-parse-options: improve test coverage Pranit Bauva
2016-04-13  5:26                   ` Eric Sunshine
2016-04-13  8:59                     ` Pranit Bauva
2016-04-13 17:27                       ` Eric Sunshine
2016-04-25 18:40                         ` Pranit Bauva
2016-04-27 17:55                           ` Eric Sunshine
2016-04-27 18:16                             ` Pranit Bauva
2016-04-12 23:02                 ` [PATCH v14 4/6] parse-options.c: make OPTION_COUNTUP respect "unspecified" values Pranit Bauva
2016-04-13  5:56                   ` Eric Sunshine
2016-04-13  8:39                     ` Pranit Bauva
2016-04-13 17:33                       ` Eric Sunshine
2016-04-13 17:43                         ` Pranit Bauva
2016-04-13 17:50                           ` Eric Sunshine
2016-04-12 23:02                 ` [PATCH v14 2/6] test-parse-options: print quiet as integer Pranit Bauva
2016-03-18 22:59   ` [PATCH v8 1/2] parse-options.c: make OPTION__COUNTUP consider negative values Junio C Hamano
2016-03-19  4:55     ` Pranit Bauva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFZEwPPvwiw4E78vYA_jpLAfASS-M0fxPopnbFSLd4yomzVciA@mail.gmail.com \
    --to=pranit.bauva@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).