Skip to content

Commit f8f8307

Browse files
pks-tgitster
authored andcommitted
cache-tree: allow writing in-memory index as tree
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 887b8ac commit f8f8307

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
902902
0);
903903
init_ui_merge_options(&o, the_repository);
904904
o.verbosity = 0;
905-
work = write_in_core_index_as_tree(the_repository);
905+
work = write_in_core_index_as_tree(the_repository,
906+
the_repository->index);
906907

907908
ret = reset_tree(new_tree,
908909
opts, 1,

cache-tree.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,11 +700,11 @@ static int write_index_as_tree_internal(struct object_id *oid,
700700
return 0;
701701
}
702702

703-
struct tree* write_in_core_index_as_tree(struct repository *repo) {
703+
struct tree *write_in_core_index_as_tree(struct repository *repo,
704+
struct index_state *index_state) {
704705
struct object_id o;
705706
int was_valid, ret;
706707

707-
struct index_state *index_state = repo->index;
708708
was_valid = index_state->cache_tree &&
709709
cache_tree_fully_valid(index_state->cache_tree);
710710

@@ -724,7 +724,6 @@ struct tree* write_in_core_index_as_tree(struct repository *repo) {
724724
return lookup_tree(repo, &index_state->cache_tree->oid);
725725
}
726726

727-
728727
int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix)
729728
{
730729
int entries, was_valid;

cache-tree.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ int cache_tree_verify(struct repository *, struct index_state *);
4747
#define WRITE_TREE_UNMERGED_INDEX (-2)
4848
#define WRITE_TREE_PREFIX_ERROR (-3)
4949

50-
struct tree* write_in_core_index_as_tree(struct repository *repo);
50+
struct tree *write_in_core_index_as_tree(struct repository *repo,
51+
struct index_state *index_state);
5152
int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix);
5253
void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
5354

0 commit comments

Comments
 (0)