git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jiang Xin <worldhello.net@gmail.com>
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	Matthieu Moy <Matthieu.Moy@imag.fr>,
	Git List <git@vger.kernel.org>
Subject: Re: [PATCH v10 09/14] git-clean: use a git-add-interactive compatible UI
Date: Thu, 16 May 2013 12:29:24 -0700	[thread overview]
Message-ID: <7vy5be4tbf.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <9d73d532fb2d8372b971d607b9ddaa1af2b84ffd.1368696028.git.worldhello.net@gmail.com> (Jiang Xin's message of "Thu, 16 May 2013 17:53:40 +0800")

Jiang Xin <worldhello.net@gmail.com> writes:

> +static void print_highlight_menu_stuff(struct menu_stuff *stuff, int **chosen)
> +{
> +	struct string_list menu_list = STRING_LIST_INIT_DUP;
> +	struct strbuf menu = STRBUF_INIT;
> +	int i;
> +
> +	if (MENU_STUFF_TYPE_MENU_ITEM == stuff->type) {
> +	...
> +	} else if (MENU_STUFF_TYPE_STRING_LIST == stuff->type) {
> +	...
> +	}

This is better to write as:

	switch (stuff->type) {
	default:
        	die("programming error");
        case MENU_STUFF_TYPE_MENU_ITEM:
        	...
                break;
	case MENU_STUFF_TYPE_STRING_LIST:
        	...
		break;
	}

Besides, there is no good reason to write an equality comparison
between constant and variable in that order (people call it a "Yoda
condition"); do "var == const" if you must.

Also please fix this one:

> +		for_each_string_list_item(item, (struct string_list *)stuff->stuff) {
> +			if ((*chosen)[i] < 0)
> +				(*chosen)[i] = 0;
> +			strbuf_addf(&menu, "%s%2d: %s", (*chosen)[i] ? "*" : " ", ++i, item->string);

Because the evaluation order of function arguments are not defined
(not left to right; these are comma-expressions),

	(*chosen)[i] ? "*" : " "

may use the original value of "i", or value after increment the
evaluation of

	++i

left in "i".

  reply	other threads:[~2013-05-16 19:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-16  9:53 [PATCH v10 00/14] interactive git-clean Jiang Xin
2013-05-16  9:53 ` [PATCH v10 01/14] path.c: refactor relative_path(), not only strip prefix Jiang Xin
2013-05-16  9:53 ` [PATCH v10 02/14] quote.c: remove path_relative, use relative_path instead Jiang Xin
2013-05-16  9:53 ` [PATCH v10 03/14] Refactor quote_path_relative, remove unused params Jiang Xin
2013-05-16  9:53 ` [PATCH v10 04/14] Refactor write_name_quoted_relative, " Jiang Xin
2013-05-16 19:15   ` Junio C Hamano
2013-05-16  9:53 ` [PATCH v10 05/14] git-clean: refactor git-clean into two phases Jiang Xin
2013-05-16  9:53 ` [PATCH v10 06/14] git-clean: add support for -i/--interactive Jiang Xin
2013-05-16  9:53 ` [PATCH v10 07/14] git-clean: show items of del_list in columns Jiang Xin
2013-05-16  9:53 ` [PATCH v10 08/14] git-clean: add colors to interactive git-clean Jiang Xin
2013-05-16  9:53 ` [PATCH v10 09/14] git-clean: use a git-add-interactive compatible UI Jiang Xin
2013-05-16 19:29   ` Junio C Hamano [this message]
2013-05-16 19:39     ` Junio C Hamano
2013-05-16  9:53 ` [PATCH v10 10/14] git-clean: add filter by pattern interactive action Jiang Xin
2013-05-16  9:53 ` [PATCH v10 11/14] git-clean: add select by numbers " Jiang Xin
2013-05-16  9:53 ` [PATCH v10 12/14] git-clean: add ask each " Jiang Xin
2013-05-16  9:53 ` [PATCH v10 13/14] git-clean: add documentation for interactive git-clean Jiang Xin
2013-05-16  9:53 ` [PATCH v10 14/14] test: add t7301 for git-clean--interactive Jiang Xin

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=7vy5be4tbf.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Matthieu.Moy@imag.fr \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    --cc=worldhello.net@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 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 NNTP newsgroup(s).