From: Elijah Newren Date: Thu, 20 Nov 2025 07:04:31 GMT Subject: Re: [PATCH v6 10/11] cache-tree: allow writing in-memory index as tree Message-ID: In-Reply-To: <20251027-b4-pks-history-builtin-v6-10-407dd3f57ad3@pks.im> On Mon, Oct 27, 2025 at 4:34 AM Patrick Steinhardt wrote: > > The function `write_in_core_index_as_tree()` takes a repository and > writes its index into a tree object. What this function cannot do though > is to take an _arbitrary_ in-memory index. > > Introduce a new `struct index_state` parameter so that the caller can > pass a different index than the one belonging to the repository. This > will be used in a subsequent commit. Make sense. > Signed-off-by: Patrick Steinhardt > --- > builtin/checkout.c | 3 ++- > cache-tree.c | 5 ++--- > cache-tree.h | 3 ++- > 3 files changed, 6 insertions(+), 5 deletions(-) > > diff --git a/builtin/checkout.c b/builtin/checkout.c > index d230b1f8995..0b90f398feb 100644 > --- a/builtin/checkout.c > +++ b/builtin/checkout.c > @@ -902,7 +902,8 @@ static int merge_working_tree(const struct checkout_opts *opts, > 0); > init_ui_merge_options(&o, the_repository); > o.verbosity = 0; > - work = write_in_core_index_as_tree(the_repository); > + work = write_in_core_index_as_tree(the_repository, > + the_repository->index); > > ret = reset_tree(new_tree, > opts, 1, > diff --git a/cache-tree.c b/cache-tree.c > index 2aba47060e9..b67d0d703d2 100644 > --- a/cache-tree.c > +++ b/cache-tree.c > @@ -699,11 +699,11 @@ static int write_index_as_tree_internal(struct object_id *oid, > return 0; > } > > -struct tree* write_in_core_index_as_tree(struct repository *repo) { > +struct tree *write_in_core_index_as_tree(struct repository *repo, > + struct index_state *index_state) { > struct object_id o; > int was_valid, ret; > > - struct index_state *index_state = repo->index; > was_valid = index_state->cache_tree && > cache_tree_fully_valid(index_state->cache_tree); > > @@ -723,7 +723,6 @@ struct tree* write_in_core_index_as_tree(struct repository *repo) { > return lookup_tree(repo, &index_state->cache_tree->oid); > } > > - Why the random whitespace change? > int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix) > { > int entries, was_valid; > diff --git a/cache-tree.h b/cache-tree.h > index b82c4963e7c..f8bddae5235 100644 > --- a/cache-tree.h > +++ b/cache-tree.h > @@ -47,7 +47,8 @@ int cache_tree_verify(struct repository *, struct index_state *); > #define WRITE_TREE_UNMERGED_INDEX (-2) > #define WRITE_TREE_PREFIX_ERROR (-3) > > -struct tree* write_in_core_index_as_tree(struct repository *repo); > +struct tree *write_in_core_index_as_tree(struct repository *repo, > + struct index_state *index_state); > int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix); > void prime_cache_tree(struct repository *, struct index_state *, struct tree *); > > > -- > 2.51.1.930.gacf6e81ea2.dirty Looks good other than the random whitespace change.