repository: drop `the_index` variable

All users of `the_index` have been converted to use either a custom `struct index_state *` or the index provided by `the_repository`. We can thus drop the globally-accessible declaration of this variable. In fact, we can go further than that and drop `the_index` completely now and have it be allocated dynamically in `initialize_repository()` as all the other data structures in it are. This concludes the quest to make Git `the_index` free, which has started with 4aab5b46f4 (Make read-cache.c "the_index" free., 2007-04-01). Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 18, 2024 at 14:14 UTC 19fa8cd48c106ded717eeaf145b45e995318f3fe
2 files changed +6 -22
repository.c
+6 -19
@@ -1,8 +1,3 @@
1 -/*
2 - * not really _using_ the compat macros, just make sure the_index
3 - * declaration matches the definition in this file.
4 - */
5 -#define USE_THE_INDEX_VARIABLE
1 #include "git-compat-util.h"
2 #include "abspath.h"
3 #include "repository.h"
@@ -23,22 +18,20 @@
18 /* The main repository */
19 static struct repository the_repo;
20 struct repository *the_repository;
26 -struct index_state the_index;
21
28 -static void initialize_repository(struct repository *repo,
29 - struct index_state *index)
22 +static void initialize_repository(struct repository *repo)
23 {
31 - repo->index = index;
24 repo->objects = raw_object_store_new();
25 repo->remote_state = remote_state_new();
26 repo->parsed_objects = parsed_object_pool_new();
35 - index_state_init(index, repo);
27 + ALLOC_ARRAY(repo->index, 1);
28 + index_state_init(repo->index, repo);
29 }
30
31 void initialize_the_repository(void)
32 {
33 the_repository = &the_repo;
41 - initialize_repository(the_repository, &the_index);
34 + initialize_repository(the_repository);
35 repo_set_hash_algo(&the_repo, GIT_HASH_SHA1);
36 }
37
@@ -191,12 +184,7 @@ int repo_init(struct repository *repo,
184 struct repository_format format = REPOSITORY_FORMAT_INIT;
185 memset(repo, 0, sizeof(*repo));
186
194 - if (repo == the_repository) {
195 - initialize_repository(the_repository, &the_index);
196 - } else {
197 - ALLOC_ARRAY(repo->index, 1);
198 - initialize_repository(repo, repo->index);
199 - }
187 + initialize_repository(repo);
188
189 if (repo_init_gitdir(repo, gitdir))
190 goto error;
@@ -313,8 +301,7 @@ void repo_clear(struct repository *repo)
301
302 if (repo->index) {
303 discard_index(repo->index);
316 - if (repo->index != &the_index)
317 - FREE_AND_NULL(repo->index);
304 + FREE_AND_NULL(repo->index);
305 }
306
307 if (repo->promisor_remote_config) {
repository.h
-3
@@ -187,9 +187,6 @@ struct repository {
187 };
188
189 extern struct repository *the_repository;
190 -#ifdef USE_THE_INDEX_VARIABLE
191 -extern struct index_state the_index;
192 -#endif
190
191 /*
192 * Define a custom repository layout. Any field can be NULL, which