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

Re: [PATCH] unpack-trees: pass checkout state explicitly to check_updates()

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 13, 2016, 23:25 UTC
Message-ID
<xmqqa8fbtm9w.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<b57982ca-d508-5016-a187-fc3b829f9b0c@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 14 quoted lines
> Add a parameter for the struct checkout variable to check_updates()
> instead of using a static global variable.  Passing it explicitly makes
> object ownership and usage more easily apparent.  And we get rid of a
> static variable; those can be problematic in library-like code.
> ...
> diff --git a/unpack-trees.c b/unpack-trees.c
> index 11c37fb..74d6dd4 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -218,8 +218,8 @@ static void unlink_entry(const struct cache_entry *ce)
>  	schedule_dir_for_removal(ce->name, ce_namelen(ce));
>  }
>  
> -static struct checkout state;
Show 6 quoted lines
> ...
> @@ -1094,6 +1094,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
>  	int i, ret;
>  	static struct cache_entry *dfc;
>  	struct exclude_list el;
> +	struct checkout state;

Does the distinction between this thing in BSS implicitly cleared and the new one on stack that does not seem to have any initialization matter?

	... goes and looks ...

OK, after this hunk we clear and set up everything in state, so there is no difference in behaviour. Just we got rid of an unnecessary file-scope global.

Nice.  Thanks.
  
Show 11 quoted lines
>  	if (len > MAX_UNPACK_TREES)
>  		die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
> @@ -1239,7 +1240,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
>  	}
>  
>  	o->src_index = NULL;
> -	ret = check_updates(o) ? (-2) : 0;
> +	ret = check_updates(o, &state) ? (-2) : 0;
>  	if (o->dst_index) {
>  		if (!ret) {
>  			if (!o->result.cache_tree)
Previous: René Scharfe
Message 2 of 2 in “unpack-trees: pass checkout state explicitly to check_updates()”
  1. unpack-trees: pass checkout state explicitly to check_updates()René Scharfe, Sep 13, 2016
  2. Junio C HamanoSep 13, 2016

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.