]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repository: drop `the_index` variable
authorPatrick Steinhardt <ps@pks.im>
Thu, 18 Apr 2024 12:14:29 +0000 (14:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Apr 2024 19:30:42 +0000 (12:30 -0700)
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>
repository.c
repository.h

index d64d15d952879c7ced1183e7b8109f40dc1e1d5a..089edbffa2d235a031ea4590e22c655d48477f90 100644 (file)
@@ -1,8 +1,3 @@
-/*
- * not really _using_ the compat macros, just make sure the_index
- * declaration matches the definition in this file.
- */
-#define USE_THE_INDEX_VARIABLE
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "repository.h"
 /* The main repository */
 static struct repository the_repo;
 struct repository *the_repository;
-struct index_state the_index;
 
-static void initialize_repository(struct repository *repo,
-                                 struct index_state *index)
+static void initialize_repository(struct repository *repo)
 {
-       repo->index = index;
        repo->objects = raw_object_store_new();
        repo->remote_state = remote_state_new();
        repo->parsed_objects = parsed_object_pool_new();
-       index_state_init(index, repo);
+       ALLOC_ARRAY(repo->index, 1);
+       index_state_init(repo->index, repo);
 }
 
 void initialize_the_repository(void)
 {
        the_repository = &the_repo;
-       initialize_repository(the_repository, &the_index);
+       initialize_repository(the_repository);
        repo_set_hash_algo(&the_repo, GIT_HASH_SHA1);
 }
 
@@ -191,12 +184,7 @@ int repo_init(struct repository *repo,
        struct repository_format format = REPOSITORY_FORMAT_INIT;
        memset(repo, 0, sizeof(*repo));
 
-       if (repo == the_repository) {
-               initialize_repository(the_repository, &the_index);
-       } else {
-               ALLOC_ARRAY(repo->index, 1);
-               initialize_repository(repo, repo->index);
-       }
+       initialize_repository(repo);
 
        if (repo_init_gitdir(repo, gitdir))
                goto error;
@@ -313,8 +301,7 @@ void repo_clear(struct repository *repo)
 
        if (repo->index) {
                discard_index(repo->index);
-               if (repo->index != &the_index)
-                       FREE_AND_NULL(repo->index);
+               FREE_AND_NULL(repo->index);
        }
 
        if (repo->promisor_remote_config) {
index 268436779c8f315228aef0dde9039f9ebf4f723e..6f4af15417561e2fe39326c6be686f40d3d74325 100644 (file)
@@ -187,9 +187,6 @@ struct repository {
 };
 
 extern struct repository *the_repository;
-#ifdef USE_THE_INDEX_VARIABLE
-extern struct index_state the_index;
-#endif
 
 /*
  * Define a custom repository layout. Any field can be NULL, which