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

Re: [PATCH] cache-tree.c: remove implicit dependency on the_repository

From
Derrick Stolee <stolee@gmail.com>
Date
Mar 25, 2021, 20:31 UTC
Message-ID
<f187df01-8e59-ac74-01e1-586a7a63fd4e@gmail.com>
In-Reply-To
<pull.915.git.1616701733901.gitgitgadget@gmail.com>
n 3/25/2021 3:48 PM, Chinmoy via GitGitGadget wrote:
Show 5 quoted lines
> From: Chinmoy Chakraborty <chinmoy12c@gmail.com>
> 
> This kills the_repository dependency in cache_tree_update(),
> but for unpack_trees(), they still assume the_repository
> (which also means the_index).
This is a worthwhile goal.
 
> Unfortunately the widespread use of unpack_trees() will make
> it hard to make the conversion now.
And this is true.
Show 5 quoted lines
> The `update_main_cache_tree()` method uses `cache_tree_update(r, r->index, flags)`.
> `r->index` is easily deduced from `r` but the signature of `cache_tree_update()`
> is not changed to take `struct repository *` instead of `struct index_state *`
> because there can be temporary indexes. Therefore, one might want to update
> the cache tree for an index other than `r->index`.

Unfortunately, you're also hitting against a use of cache_tree_update() that I'm introducing in my sparse-index work [1], so that will cause a semantic, non-textual conflict.

[1] https://lore.kernel.org/git/pull.883.v4.git.1616507069.gitgitgadget@gmail.com/
There are a couple options here:
1. Wait a little while for that to settle and merge to master.
2. Rebase your work onto ds/sparse-index, so you also fix the
   new use in sparse-index.c.
3. Continue without it, and maybe Junio will update the merge
   with this diff:
diff --git a/sparse-index.c b/sparse-index.c
index e5712d98d8..585f269214 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -169,7 +169,7 @@ int convert_to_sparse(struct index_state *istate)
 		return -1;
 	}
 
-	if (cache_tree_update(istate, 0)) {
+	if (cache_tree_update(istate->repo, istate, 0)) {
 		warning(_("unable to update cache-tree, staying full"));
 		return -1;
 	}
@@ -183,7 +183,7 @@ int convert_to_sparse(struct index_state *istate)
 
 	/* Clear and recompute the cache-tree */
 	cache_tree_free(&istate->cache_tree);
-	cache_tree_update(istate, 0);
+	cache_tree_update(istate->repo, istate, 0);
 
 	istate->sparse_index = 1;
 	trace2_region_leave("index", "convert_to_sparse", istate->repo);

Finally, there is yet a fourth option: use istate->repo instead. In
1fd9ae51 (repository: add repo reference to index_state), I added a
'repo' member to struct index_state. This is intended for methods to
access a repository directly from the index.

However, this is slightly dangerous because there are some cases where
and index is loaded without even the_repository being populated (and
hence istate->repo can be NULL). They are rare, so perhaps
unpack_trees() is always used on an index_state with a populated repo.
If not, then a temporary fix can be done to set istate->repo to
the_repository at the start of the method.

This could help you avoid changing method prototypes, reducing the
conflicts in your patch.

> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 2d6550bc3c86..3bc630ef64e7 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -684,6 +684,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
>  	int ret;
>  	struct lock_file lock_file = LOCK_INIT;
>  	struct tree *new_tree;
> +	struct repository *r = the_repository;

I do appreciate you using this pattern so we could
possibly add 'r' as a method parameter later.

The rest of the patch looks pretty standard. I hope my comments
above are helpful in your direction here.

Thanks,
-Stolee
Previous: Chinmoy via GitGitGadgetNext: Chinmoy Chakraborty
Message 2 of 17 in “cache-tree.c: remove implicit dependency on the_repository”
  1. cache-tree.c: remove implicit dependency on the_repositoryChinmoy via GitGitGadget, Mar 25, 2021
  2. Derrick StoleeMar 25, 2021
  3. Chinmoy ChakrabortyMar 26, 2021
  4. Chinmoy ChakrabortyMar 26, 2021
  5. cache-tree.c: remove implicit dependency on the_repositoryChinmoy via GitGitGadget, Mar 26, 2021
  6. cache-tree.c: remove implicit dependency on the_repositoryChinmoy via GitGitGadget, Apr 3, 2021
  7. Junio C HamanoApr 4, 2021
  8. Chinmoy ChakrabortyApr 4, 2021
  9. Junio C HamanoApr 4, 2021
  10. Chinmoy ChakrabortyApr 4, 2021
  11. Junio C HamanoApr 4, 2021
  12. Derrick StoleeApr 5, 2021
  13. Junio C HamanoApr 5, 2021
  14. cache-tree.c: remove implicit dependency on the_repositoryChinmoy via GitGitGadget, Apr 7, 2021
  15. Junio C HamanoApr 7, 2021
  16. Chinmoy ChakrabortyApr 8, 2021
  17. Junio C HamanoApr 8, 2021

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.