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

Re: [PATCH] branch: trivial style fix

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 5, 2018, 16:47 UTC
Message-ID
<xmqqy3bcwdb4.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20181005095213.12509-1-taoqy@ls-a.me>
Tao Qingyun <taoqy@ls-a.me> writes:
Show 18 quoted lines
> ---
>  builtin/branch.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/branch.c b/builtin/branch.c
> index c396c41533..52aad0f602 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -222,10 +222,11 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
>  		if (!head_rev)
>  			die(_("Couldn't look up commit object for HEAD"));
>  	}
> -	for (i = 0; i < argc; i++, strbuf_reset(&bname)) {
> +	for (i = 0; i < argc; i++) {
>  		char *target = NULL;
>  		int flags = 0;
>  
> +		strbuf_reset(&bname);
This is not "trivial" nor "style fix", though.

It is not "trivial" because it also changes the behaviour. Instead of resetting the strbuf each time after the loop body runs, the new code resets it before the loop body, even for the 0-th iteration where the strbuf hasn't even been used at all. It is not a "style fix" because we do not have a particular reason to avoid using the comma operator to perform two simple expressions with side effects inside a single expression.

Show 10 quoted lines
>  		strbuf_branchname(&bname, argv[i], allowed_interpret);
>  		free(name);
>  		name = mkpathdup(fmt, bname.buf);
> @@ -716,8 +717,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
>  		print_columns(&output, colopts, NULL);
>  		string_list_clear(&output, 0);
>  		return 0;
> -	}
> -	else if (edit_description) {
> +	} else if (edit_description) {

This one is a style fix that is trivial. It does not change the semantics a bit, and we do prefer "else if" to be on the same line as the closing "}" of the earlier "if" that opened the matching "{".

>  		const char *branch_name;
>  		struct strbuf branch_ref = STRBUF_INIT;
Previous: Jeff KingNext: Tao Qingyun
Message 3 of 9 in “branch: trivial style fix”
  1. branch: trivial style fixTao Qingyun, Oct 5, 2018
  2. Jeff KingOct 5, 2018
  3. Junio C HamanoOct 5, 2018
  4. branch: trivial style fixTao Qingyun, Oct 16, 2018
  5. Jeff KingOct 16, 2018
  6. Jeff KingOct 15, 2018
  7. Tao QingyunOct 16, 2018
  8. Ævar Arnfjörð BjarmasonOct 16, 2018
  9. Jeff KingOct 16, 2018

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.