Skip to content

Commit

Permalink
repository & index API: populate "the_index.repo"
Browse files Browse the repository at this point in the history
When the "repo" member was added to "the_index" in
1fd9ae5 (repository: add repo reference to index_state,
2021-01-23) the repo_read_index() was made to populate it, but the
unpopulated "the_index" variable didn't get the same treatment.

Let's do that in initialize_the_repository() when we set it up, and
likewise for all of the current callers initialized an empty "struct
index_state". As we'll see in a subsequent commit we have some
workarounds in place that we'll be able to do away with since we don't
have to worry if "istate->repo" is NULL now for an otherwise valid
"istate".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
  • Loading branch information
avar committed Apr 22, 2022
1 parent 4efdd4f commit d83bfa8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions builtin/stash.c
Expand Up @@ -1083,7 +1083,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
int ret = 0;
struct strbuf untracked_msg = STRBUF_INIT;
struct child_process cp_upd_index = CHILD_PROCESS_INIT;
struct index_state istate = { NULL };
struct index_state istate = { .repo = the_repository };

cp_upd_index.git_cmd = 1;
strvec_pushl(&cp_upd_index.args, "update-index", "-z", "--add",
Expand Down Expand Up @@ -1122,7 +1122,7 @@ static int stash_staged(struct stash_info *info, struct strbuf *out_patch,
{
int ret = 0;
struct child_process cp_diff_tree = CHILD_PROCESS_INIT;
struct index_state istate = { NULL };
struct index_state istate = { .repo = the_repository };

if (write_index_as_tree(&info->w_tree, &istate, the_repository->index_file,
0, NULL)) {
Expand Down Expand Up @@ -1155,7 +1155,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
int ret = 0;
struct child_process cp_read_tree = CHILD_PROCESS_INIT;
struct child_process cp_diff_tree = CHILD_PROCESS_INIT;
struct index_state istate = { NULL };
struct index_state istate = { .repo = the_repository };
char *old_index_env = NULL, *old_repo_index_file;

remove_path(stash_index_path.buf);
Expand Down Expand Up @@ -1217,7 +1217,7 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps
struct rev_info rev;
struct child_process cp_upd_index = CHILD_PROCESS_INIT;
struct strbuf diff_output = STRBUF_INIT;
struct index_state istate = { NULL };
struct index_state istate = { .repo = the_repository };

init_revisions(&rev, NULL);
copy_pathspec(&rev.prune_data, ps);
Expand Down
2 changes: 2 additions & 0 deletions repository.c
Expand Up @@ -28,6 +28,8 @@ void initialize_the_repository(void)
the_repo.remote_state = remote_state_new();
the_repo.parsed_objects = parsed_object_pool_new();

the_index.repo = the_repository;

repo_set_hash_algo(&the_repo, GIT_HASH_SHA1);
}

Expand Down
2 changes: 1 addition & 1 deletion revision.c
Expand Up @@ -1733,7 +1733,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
worktrees = get_worktrees();
for (p = worktrees; *p; p++) {
struct worktree *wt = *p;
struct index_state istate = { NULL };
struct index_state istate = { .repo = revs->repo };

if (wt->is_current)
continue; /* current index already taken care of */
Expand Down

0 comments on commit d83bfa8

Please sign in to comment.