Skip to content

Commit 9dfa7ac

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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f980648 commit 9dfa7ac

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
@@ -699,11 +699,11 @@ static int write_index_as_tree_internal(struct object_id *oid,
699699
return 0;
700700
}
701701

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

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

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

726-
727726
int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix)
728727
{
729728
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)