Skip to content

Commit 19fa8cd

Browse files
pks-tgitster
authored andcommitted
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 4aab5b4 (Make read-cache.c "the_index" free., 2007-04-01). Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ee6d63 commit 19fa8cd

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

repository.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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
61
#include "git-compat-util.h"
72
#include "abspath.h"
83
#include "repository.h"
@@ -23,22 +18,20 @@
2318
/* The main repository */
2419
static struct repository the_repo;
2520
struct repository *the_repository;
26-
struct index_state the_index;
2721

28-
static void initialize_repository(struct repository *repo,
29-
struct index_state *index)
22+
static void initialize_repository(struct repository *repo)
3023
{
31-
repo->index = index;
3224
repo->objects = raw_object_store_new();
3325
repo->remote_state = remote_state_new();
3426
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);
3629
}
3730

3831
void initialize_the_repository(void)
3932
{
4033
the_repository = &the_repo;
41-
initialize_repository(the_repository, &the_index);
34+
initialize_repository(the_repository);
4235
repo_set_hash_algo(&the_repo, GIT_HASH_SHA1);
4336
}
4437

@@ -191,12 +184,7 @@ int repo_init(struct repository *repo,
191184
struct repository_format format = REPOSITORY_FORMAT_INIT;
192185
memset(repo, 0, sizeof(*repo));
193186

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);
200188

201189
if (repo_init_gitdir(repo, gitdir))
202190
goto error;
@@ -313,8 +301,7 @@ void repo_clear(struct repository *repo)
313301

314302
if (repo->index) {
315303
discard_index(repo->index);
316-
if (repo->index != &the_index)
317-
FREE_AND_NULL(repo->index);
304+
FREE_AND_NULL(repo->index);
318305
}
319306

320307
if (repo->promisor_remote_config) {

repository.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ struct repository {
187187
};
188188

189189
extern struct repository *the_repository;
190-
#ifdef USE_THE_INDEX_VARIABLE
191-
extern struct index_state the_index;
192-
#endif
193190

194191
/*
195192
* Define a custom repository layout. Any field can be NULL, which

0 commit comments

Comments
 (0)