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

Re: [PATCH v10 09/14] git-clean: use a git-add-interactive compatible UI

From
Junio C Hamano <gitster@pobox.com>
Date
May 16, 2013, 19:29 UTC
Message-ID
<7vy5be4tbf.fsf@alter.siamese.dyndns.org>
In-Reply-To
<9d73d532fb2d8372b971d607b9ddaa1af2b84ffd.1368696028.git.worldhello.net@gmail.com>
Jiang Xin <worldhello.net@gmail.com> writes:
Show 11 quoted lines
> +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".
Previous: Jiang XinNext: Junio C Hamano
Message 12 of 18 in “interactive git-clean”
  1. 00/14 interactive git-cleanJiang Xin, May 16, 2013
  2. 01/14 path.c: refactor relative_path(), not only strip prefixJiang Xin, May 16, 2013
  3. 02/14 quote.c: remove path_relative, use relative_path insteadJiang Xin, May 16, 2013
  4. 03/14 Refactor quote_path_relative, remove unused paramsJiang Xin, May 16, 2013
  5. 04/14 Refactor write_name_quoted_relative, remove unused paramsJiang Xin, May 16, 2013
  6. Junio C HamanoMay 16, 2013
  7. 05/14 git-clean: refactor git-clean into two phasesJiang Xin, May 16, 2013
  8. 06/14 git-clean: add support for -i/--interactiveJiang Xin, May 16, 2013
  9. 07/14 git-clean: show items of del_list in columnsJiang Xin, May 16, 2013
  10. 08/14 git-clean: add colors to interactive git-cleanJiang Xin, May 16, 2013
  11. 09/14 git-clean: use a git-add-interactive compatible UIJiang Xin, May 16, 2013
  12. Junio C HamanoMay 16, 2013
  13. Junio C HamanoMay 16, 2013
  14. 10/14 git-clean: add filter by pattern interactive actionJiang Xin, May 16, 2013
  15. 11/14 git-clean: add select by numbers interactive actionJiang Xin, May 16, 2013
  16. 12/14 git-clean: add ask each interactive actionJiang Xin, May 16, 2013
  17. 13/14 git-clean: add documentation for interactive git-cleanJiang Xin, May 16, 2013
  18. 14/14 test: add t7301 for git-clean--interactiveJiang Xin, May 16, 2013

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.