]> git.ipfire.org Git - thirdparty/git.git/commitdiff
cache-tree: allow writing in-memory index as tree
authorPatrick Steinhardt <ps@pks.im>
Wed, 1 Oct 2025 15:57:37 +0000 (17:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Oct 2025 19:33:30 +0000 (12:33 -0700)
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.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
cache-tree.c
cache-tree.h

index d230b1f8995b44d2be53695b8fa8a9d6abaaa0f0..0b90f398feba66d4addf953f43ae123cdf783970 100644 (file)
@@ -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,
index d225554eedd920dcadc2b5d0c61c2e2932f6e811..1fe036052251c644094263b89925664bc6343d91 100644 (file)
@@ -700,11 +700,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);
 
@@ -724,7 +724,6 @@ struct tree* write_in_core_index_as_tree(struct repository *repo) {
        return lookup_tree(repo, &index_state->cache_tree->oid);
 }
 
-
 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;
index b82c4963e7c805ffd03adbb96407f5e39a0a8d4c..f8bddae5235f5474410e4e80cb0bfa9408353bfc 100644 (file)
@@ -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 *);