All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Pranit Bauva <pranit.bauva@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v3] bisect--helper: convert a function in shell to C
Date: Wed, 23 Mar 2016 12:57:17 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1603231238180.4690@virtualbox> (raw)
In-Reply-To: <01020153a254974b-68f7d16a-66d7-4dc1-805d-2185ff1b3ebf-000000@eu-west-1.amazonses.com>

Hi Pranit,

On Wed, 23 Mar 2016, Pranit Bauva wrote:

> Convert the code literally without changing its design even though it
> seems that it is obscure as to the use of comparing revision to different
> bisect arguments which seems like a problem in shell because of the way
> function arguments are handled.

I still believe that it would make for an improvement to replace
"revision" by "orig_term".

> The argument handling is kind of hard coded right now because it is not
> really be meant to be used like this and this is just for testing
> purposes whether this new method is as functional as its counter part.
> The shell counter part of the method has been retained for historical
> purposes.

Well, maybe the argument handling is really meant to be used like this in
the end? Just skip that paragraph.

> Also using OPT_CMDMODE() to handle check-term-format and next-all
> because these sub commands are independent and error should be shown if
> used together and should be handled independently.

As is often the case, after some discussion a single patch becomes more
than just one change. This is what we see here, too: OPT_CMDMODE() is a
change that needs preparation of the existing code in
builtin/bisect--helper.c, and I would highly suggest to split that change
out into its own patch. It makes for a nicer story, and it is *much*
easier to review.

> This commit reduces the number of failed tests in
> t6030-bisect-porcelain.sh and t6041-bisect-submodule.sh

Oh? Which tests are supposed to fail? I do not see any failing tests
here...

> diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
> index 3324229..ab3891c 100644
> --- a/builtin/bisect--helper.c
> +++ b/builtin/bisect--helper.c
> [...]
> +static int check_term_format(const char *term, const char *revision, int flag) {
> +	if (check_refname_format(term, flag))
> +		die("'%s' is not a valid term", term);
> +
> +	if (one_of(term, "help", "start", "skip", "next", "reset", "visualize",
> +	    "replay", "log", "run", NULL))

If I understood Junio correctly, he meant to line up the second line with
the corresponding level. In this case, as "replay" is a parameter of the
one_of() function, the indentation would look like this instead:

	if (one_of(term, "help", "start", "skip", "next", "reset", "visualize",
		   "replay", "log", "run", NULL))

> +		die("can't use the builtin command '%s' as a term", term);
> +
> +	/* In theory, nothing prevents swapping
> +	 * completely good and bad, but this situation
> +	 * could be confusing and hasn't been tested
> +	 * enough. Forbid it for now.
> +	 */

I see quite a few comments that put the closing "*/" on its own line, but
do not award the same pleasure to the opening "/*". Personally, I much
prefer the opening "/*" to have an entire line to itself, too, but I guess
that there is enough precendence in Git's source code to accept both
forms.

> +	if (!strcmp(term, "bad") || !strcmp(term, "new"))
> +		if (strcmp(revision, "bad"))
> +			die("can't change the meaning of term '%s'", term);
> +
> +	if(!strcmp(term, "good") || !strcmp(term, "old"))
> +		if (strcmp(revision, "good"))
> +			die("can't change the meaning of term '%s'", term);

I am still convinced that

	if ((one_of(term, "bad", "new", NULL) && strcmp(orig_term, "bad")) ||
	    (one_of(term, "good", "old", NULL) && strcmp(orig_term, "good")))
		die("can't change the meaning of term '%s'", term);

looks so much nicer.

>  int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
>  {
> -	int next_all = 0;
> +	int sub_command = 0;
>  	int no_checkout = 0;
> +
> +	enum sub_commands {
> +		NEXT_ALL,
> +		CHECK_TERM_FMT
> +	};

Interesting. I did not think that Git's source code declares enums inside
functions, but builtin/remote.c's config_read_branches() does, so this
code is fine.

Still, the patch would be easier to review (corollary: bugs would have a
harder time to hide) if the change from OPT_BOOL to OPT_CMDMODE was done
in a separate, preparatory patch.

>  	argc = parse_options(argc, argv, prefix, options,
>  			     git_bisect_helper_usage, 0);
>  
> -	if (!next_all)
> +	if (sub_command == CHECK_TERM_FMT) {
> +		if (argc == 2) {
> +			if (argv[0] != NULL && argv[1] != NULL)
> +				return check_term_format(argv[0], argv[1], 0);
> +			else
> +				die("no revision or term provided with check_for_term");
> +		}
> +		else
> +			die("--check-term-format expects 2 arguments");
> +	}
> +
> +	if (sub_command != NEXT_ALL && sub_command != CHECK_TERM_FMT)
>  		usage_with_options(git_bisect_helper_usage, options);

Personally, I would prefer

- the usage_with_options() code to come before any sub_command processing,

- the sub_command enum to be initialized with -1, or alternatively
  hardcoding NEXT_ALL to 1,

- to avoid else clauses after an if () clause whose block returns or
  die()s,

- to order the clauses of an if/else in ascending size, i.e.

	if (argc != 2)
		die(...);
	if ...

- to avoid checking argv[i] for NULL when i < argc (it is the contract
  that argv[0..argc-1] are all non-NULL, so checking for it is unnecessary
  churn),

- use a switch() on sub_command instead of unrolled if () statements, and

- wrap the code at 80 columns/row (interpreting tabs as "up to 8 spaces").

The rest of the patch looks good.

Ciao,
Johannes

  reply	other threads:[~2016-03-23 11:57 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 [this message]
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
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

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

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1603231238180.4690@virtualbox \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=pranit.bauva@gmail.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.