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>,
	Christian Couder <chriscool@tuxfamily.org>,
	christain.couder@gmail.com,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Lars Schneider <larsxschneider@gmail.com>
Subject: Re: [PATCH 2/2] bisect: rewrite `check_term_format` shell function in C
Date: Wed, 4 May 2016 17:28:28 +0530	[thread overview]
Message-ID: <CAFZEwPNdmJdt=4Hg7KpfGS51sDeKyAPWgApESf564kt_eaP3Rg@mail.gmail.com> (raw)
In-Reply-To: <CAPig+cQn4iRCqquUE-g4879mTS7UJkHr7ANvH9HB2+087qCV7A@mail.gmail.com>

On Wed, May 4, 2016 at 1:58 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Wed, May 4, 2016 at 3:36 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
>> On Wed, May 4, 2016 at 12:22 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>>> On Wed, May 4, 2016 at 1:07 AM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
>>> Okay, I'll bite: Why is this a good idea? What does it buy you?
>>>
>>> It's not as if the rewrite is especially faster or more easily
>>> expressed in C; quite the contrary, the shell code is more concise and
>>> probably about equally as fast (not that execution speed matters in
>>> this case).
>>>
>>> I could understand this functionality being ported to C in the form of
>>> a static function as a minor part of porting "git bisect terms" in its
>>> entirety to C, but I'm not imaginative enough to see why this
>>> functionality is useful as a standalone git-bisect--helper subcommand,
>>> and the commit message doesn't enlighten. Consequently, it seems like
>>> unnecessary complexity.
>>
>> It is important to understand that the subcommand is just a
>> **temporary** measure.
>
> The commit message seems to be lacking this information and any other rationale.

I will modify the commit message in order to reflect this.

>>>> +static int one_of(const char *term, ...)
>>>> +{
>>>> +       va_list matches;
>>>> +       const char *match;
>>>> +
>>>> +       va_start(matches, term);
>>>> +       while ((match = va_arg(matches, const char *)) != NULL)
>>>> +               if (!strcmp(term, match))
>>>> +                       return 1;
>>>
>>> Is it wise to return here without invoking va_end()?
>>
>> I guess since it already checks for NULL, invoking va_end() will make
>> it redundant[3].
>
> Sorry, your response does not compute. Each va_start() *must* be
> balanced with a va_end(). (While it's true that you may encounters
> platforms/compilers for which a missing va_end() does no harm, such
> code is not portable.)

I am sorry for my misunderstanding. I had very little idea about
variable arguments. I have searched on this now. I will update by
according to Johannes which seems nice to me.

>>>> +       va_end(matches);
>>>> +
>>>> +       return 0;
>>>> +}
>>>> +
>>>> +static int check_term_format(const char *term, const char *orig_term,
>>>> +                            int flag)
>>>
>>> What is 'flag' for? The single caller only ever passes 0, so why is this needed?
>>
>> Well, currently the subcommand does not use this flag but this flag is
>> present in the method check_refname_format() so it would be better to
>> use it. This flag might be useful in further parts of conversion since
>> as I previously mentioned check-term-format isn't a permanent
>> solution.
>
> Sorry, again this does not compute. Certainly, you must pass *some*
> flags argument to check_refname_format() as 'flags' is part of its
> signature, but that doesn't explain why check_term_format() accepts a
> 'flag' argument. Moreover, check_term_format() is not a general
> purpose function like check_refname_format(), so this sort of
> *apparent* flexibility adds complexity with no obvious benefit.

I check the future functions and it does not require the flag argument
so I will remove it.

>>>> +       strbuf_addf(&new_term, "refs/bisect/%s", term);
>>>> +
>>>> +       if (check_refname_format(new_term.buf, flag))
>>>> +               die(_("'%s' is not a valid term\n"), term);
>>>
>>> Why does this die() while the other "invalid" cases merely return
>>> error()? What makes this special?
>>
>> This is because I felt that if check_refname_format() fails then its a
>> fatal error while in other cases, it is not as fatal.
>
> The name of the command is "check-term-format" and that is precisely
> its purpose so, from the perspective of the caller, *all* problems
> with the term are fatal. It's black-and-white, there is no grey:
> either a term is acceptable, or it isn't; that's all the caller wants
> to know. Consequently, all problems detected by this function should
> be reported the same way (preferably via 'return error()').

Sure. I will use 'return error()'. Any particular reason why this
instead of die() ?

>>>> +       else if (one_of(term, "help", "start", "skip", "next", "reset",
>>>
>>> s/else //
>>
>> Agree since it would be a part of the switch which is not included
>> with the check_refname_format().
>>
>>>> +       else if ((one_of(term, "bad", "new", NULL) && strcmp(orig_term, "bad")) ||
>>>
>>> s/else //
>>
>> In the shell script a switch was used, thus `else if` would be a more
>> appropriate choice over `if`. Also if the first if statement fails
>> then it is unnecessary to go further.
>
> Whether this was a 'switch' statement in the shell script is
> immaterial. The body of each of these 'if' statements exits the
> function, so no following code will be executed anyhow when the
> condition is true. This makes the 'else' pure noise which is why
> 's/else //' is suggested and good style. The less the reader's brain
> has to process, the easier the code is to comprehend.

Okay. I get it. Will drop off the else.

>>>> +               OPT_CMDMODE(0, "check-term-format", &sub_command,
>>>> +                        N_("check format of the ref"), CHECK_TERM_FMT),
>>>
>>> What "ref"?
>>
>> The ref here means that ref (like HEAD).
>
> Sorry, does not compute. To what HEAD or other ref are you referring?
> This command is about checking the name of a bisection term. Where
> does 'ref' come into it (other than as an implementation detail)?

I guess it would be more appropriate to use term.

Thanks,
Pranit Bauva

  parent reply	other threads:[~2016-05-04 11:58 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-21 19:00 [PATCH] bisect--helper: convert a function in shell to C Pranit Bauva
2016-03-22  0:28 ` Stefan Beller
2016-03-22  6:10   ` Christian Couder
2016-03-22  6:13     ` Pranit Bauva
2016-03-22  6:13   ` Pranit Bauva
2016-03-22  8:01 ` [PATCH v2] " Pranit Bauva
2016-03-22 15:09   ` Johannes Schindelin
2016-03-22 15:11     ` Johannes Schindelin
2016-03-22 17:46       ` Pranit Bauva
2016-03-23 11:23         ` Johannes Schindelin
2016-03-22 16:03     ` Junio C Hamano
2016-03-22 16:49       ` Johannes Schindelin
2016-03-22 17:52       ` Pranit Bauva
2016-03-22 17:59         ` Stefan Beller
2016-03-23 11:24           ` Johannes Schindelin
2016-03-22 17:45     ` Pranit Bauva
2016-03-23 11:22       ` Johannes Schindelin
2016-03-23 13:53         ` Pranit Bauva
2016-03-23  7:16   ` [PATCH v3] " Pranit Bauva
2016-03-23 11:57     ` Johannes Schindelin
2016-03-23 13:16       ` Pranit Bauva
2016-03-23 16:24         ` Junio C Hamano
2016-03-23 18:38           ` Pranit Bauva
2016-03-23 16:15       ` Junio C Hamano
2016-03-23 18:46         ` Pranit Bauva
2016-05-04  5:07     ` [PATCH 0/2] bisect--helper: rewrite of check_term_format() Pranit Bauva
2016-05-04  5:07       ` [PATCH 1/2] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-04  5:34         ` Pranit Bauva
2016-05-04  6:07         ` Eric Sunshine
2016-05-04  6:50           ` Christian Couder
2016-05-04 11:05             ` Johannes Schindelin
2016-05-04 12:04               ` Pranit Bauva
2016-05-04 12:05               ` Christian Couder
2016-05-04 12:21                 ` Johannes Schindelin
2016-05-04 12:41                   ` Christian Couder
2016-05-04 14:56                     ` Johannes Schindelin
2016-05-04 19:07                       ` Christian Couder
2016-05-08  6:54                         ` Johannes Schindelin
2016-05-04  7:28           ` Junio C Hamano
2016-05-04 11:02         ` Johannes Schindelin
2016-05-04  5:07       ` [PATCH 2/2] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-04  6:52         ` Eric Sunshine
2016-05-04  7:36           ` Pranit Bauva
2016-05-04  7:40             ` Pranit Bauva
2016-05-04  8:28             ` Eric Sunshine
2016-05-04  8:54               ` Christian Couder
2016-05-04 11:58               ` Pranit Bauva [this message]
2016-05-04 17:49                 ` Eric Sunshine
2016-05-04 18:08                   ` Pranit Bauva
2016-05-04 11:13             ` Johannes Schindelin
2016-05-04 12:00               ` Pranit Bauva
2016-05-04 12:21               ` Christian Couder
2016-05-04 19:10               ` Junio C Hamano
2016-05-04  5:22       ` [PATCH 0/2] bisect--helper: rewrite of check_term_format() Christian Couder
2016-05-04  5:25         ` Pranit Bauva
2016-05-06 14:49       ` [PATCH v5 0/2] bisect--helper: rewrite of check-term-format() Pranit Bauva
2016-05-06 14:49         ` [PATCH v5 1/2] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-08  7:04           ` Johannes Schindelin
2016-05-08  7:17             ` Pranit Bauva
2016-05-08 15:30               ` Christian Couder
2016-05-08 15:33                 ` Pranit Bauva
2016-05-09 14:59               ` Johannes Schindelin
2016-05-09 15:33                 ` Pranit Bauva
2016-05-06 14:49         ` [PATCH v5 2/2] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-07  0:05           ` Eric Sunshine
2016-05-06 22:15         ` [PATCH v5 0/2] bisect--helper: rewrite of check-term-format() Junio C Hamano
2016-05-07 13:07           ` Pranit Bauva
2016-05-08  2:25             ` Junio C Hamano
2016-05-08  6:23               ` Pranit Bauva
2016-05-08 13:34                 ` Pranit Bauva
2016-05-16  0:35                   ` Eric Sunshine
2016-05-16 17:07                     ` Christian Couder
2016-05-20  6:59                     ` Pranit Bauva
2016-05-12  5:32         ` [PATCH v6 0/3] bisect--helper: check_term_format() & write_terms() Pranit Bauva
2016-05-12  5:32           ` [PATCH v6 1/3] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-16  7:07             ` Eric Sunshine
2016-05-20  7:17               ` Pranit Bauva
2016-05-12  5:32           ` [PATCH v6 2/3] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-12 22:36             ` Junio C Hamano
2016-05-13  6:59               ` Pranit Bauva
2016-05-13 18:01                 ` Junio C Hamano
2016-05-12  5:32           ` [PATCH v6 3/3] bisect--helper: `write_terms` " Pranit Bauva
2016-05-16  7:28             ` Eric Sunshine
2016-05-16 13:16               ` Johannes Schindelin
2016-05-16 15:42                 ` Eric Sunshine
2016-05-16 16:45                   ` Johannes Schindelin
2016-05-16 16:59                     ` Eric Sunshine
2016-05-20  7:45                 ` Pranit Bauva
2016-05-23 11:07                   ` Johannes Schindelin
2016-05-23 13:58                     ` Christian Couder
2016-05-23 15:10                       ` Johannes Schindelin
2016-05-23 14:33                     ` Pranit Bauva
2016-05-20  7:42               ` Pranit Bauva
2016-05-23 14:48           ` [PATCH v7 0/3] bisect--helper: check_term_format() & write_terms() Pranit Bauva
2016-05-23 14:48             ` [PATCH v7 1/3] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-23 14:48             ` [PATCH v7 2/3] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-23 14:48             ` [PATCH v7 3/3] bisect--helper: `write_terms` " Pranit Bauva
2016-05-23 16:01               ` Eric Sunshine
2016-05-23 17:59                 ` Pranit Bauva
2016-05-24  7:21             ` [PATCH v8 0/3] bisect--helper: check-term-format() & write_terms() Pranit Bauva
2016-05-24 18:42               ` [PATCH v9 0/3] bisect--helper: check_term_format() and write_terms() Pranit Bauva
2016-05-24 18:42               ` [PATCH v9 1/3] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-24 18:42               ` [PATCH v9 2/3] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-24 18:42               ` [PATCH v9 3/3] bisect--helper: `write_terms` " Pranit Bauva
2016-05-24  7:21             ` [PATCH v8 1/3] bisect--helper: use OPT_CMDMODE instead of OPT_BOOL Pranit Bauva
2016-05-24  7:21             ` [PATCH v8 2/3] bisect: rewrite `check_term_format` shell function in C Pranit Bauva
2016-05-25  5:04               ` Johannes Schindelin
2016-05-25  5:13                 ` Pranit Bauva
2016-06-16  7:10               ` Lars Schneider
2016-06-17 12:48                 ` Pranit Bauva
2016-05-24  7:21             ` [PATCH v8 3/3] bisect--helper: `write_terms` " Pranit Bauva
2016-05-24  7:33               ` Christian Couder
2016-05-24 17:39                 ` Junio C Hamano
2016-05-24 18:31                 ` 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='CAFZEwPNdmJdt=4Hg7KpfGS51sDeKyAPWgApESf564kt_eaP3Rg@mail.gmail.com' \
    --to=pranit.bauva@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=chriscool@tuxfamily.org \
    --cc=christain.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=larsxschneider@gmail.com \
    --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).