treewide: always have a valid "index_state.repo" member
When the "repo" member was added to "the_index" in [1] 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". This simplifies code that needs to deal with "the_index" or a custom "struct index_state", we no longer need to second-guess this part of the "index_state" deep in the stack. A recent example of such second-guessing is the "istate->repo ? istate->repo : the_repository" code in [2]. We can now simply use "istate->repo". We're doing this by making use of the INDEX_STATE_INIT() macro (and corresponding function) added in [3], which now have mandatory "repo" arguments. Because we now call index_state_init() in repository.c's initialize_the_repository() we don't need to handle the case where we have a "repo->index" whose "repo" member doesn't match the "repo" we're setting up, i.e. the "Complete the double-reference" code in repo_read_index() being altered here. That logic was originally added in [1], and was working around the lack of what we now have in initialize_the_repository(). For "fsmonitor-settings.c" we can remove the initialization of a NULL "r" argument to "the_repository". This was added back in [4], and was needed at the time for callers that would pass us the "r" from an "istate->repo". Before this change such a change to "fsmonitor-settings.c" would segfault all over the test suite (e.g. in t0002-gitfile.sh). This change has wider eventual implications for "fsmonitor-settings.c". The reason the other lazy loading behavior in it is required (starting with "if (!r->settings.fsmonitor) ..." is because of the previously passed "r" being "NULL". I have other local changes on top of this which move its configuration reading to "prepare_repo_settings()" in "repo-settings.c", as we could now start to rely on it being called for our "r". But let's leave all of that for now, and narrowly remove this particular part of the lazy-loading. 1.1fd9ae517c(repository: add repo reference to index_state, 2021-01-23) 2.ee1f0c242e(read-cache: add index.skipHash config option, 2023-01-06) 3.2f6b1eb794(cache API: add a "INDEX_STATE_INIT" macro/function, add release_index(), 2023-01-12) 4.1e0ea5c431(fsmonitor: config settings are repository-specific, 2022-03-25) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Acked-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
dc71be4fda
commit
6269f8eaad
@@ -128,9 +128,6 @@ int is_sparse_index_allowed(struct index_state *istate, int flags)
|
||||
if (!core_apply_sparse_checkout || !core_sparse_checkout_cone)
|
||||
return 0;
|
||||
|
||||
if (!istate->repo)
|
||||
istate->repo = the_repository;
|
||||
|
||||
if (!(flags & SPARSE_INDEX_MEMORY_ONLY)) {
|
||||
int test_env;
|
||||
|
||||
@@ -327,9 +324,6 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
|
||||
pl = NULL;
|
||||
}
|
||||
|
||||
if (!istate->repo)
|
||||
istate->repo = the_repository;
|
||||
|
||||
/*
|
||||
* A NULL pattern set indicates we are expanding a full index, so
|
||||
* we use a special region name that indicates the full expansion.
|
||||
@@ -552,9 +546,6 @@ void expand_to_path(struct index_state *istate,
|
||||
if (!istate->sparse_index)
|
||||
return;
|
||||
|
||||
if (!istate->repo)
|
||||
istate->repo = the_repository;
|
||||
|
||||
in_expand_to_path = 1;
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user