From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Karthik Nayak <karthik.188@gmail.com>,
Phillip Wood <phillip.wood123@gmail.com>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 5/6] repository: drop `the_index` variable
Date: Thu, 18 Apr 2024 14:14:29 +0200 [thread overview]
Message-ID: <549f8c048fb13a4b0b004c5dc72a39fb24a70c7f.1713442061.git.ps@pks.im> (raw)
In-Reply-To: <cover.1713442061.git.ps@pks.im>
[-- Attachment #1: Type: text/plain, Size: 3005 bytes --]
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>
---
repository.c | 25 ++++++-------------------
repository.h | 3 ---
2 files changed, 6 insertions(+), 22 deletions(-)
diff --git a/repository.c b/repository.c
index d64d15d952..089edbffa2 100644
--- a/repository.c
+++ b/repository.c
@@ -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"
@@ -23,22 +18,20 @@
/* 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) {
diff --git a/repository.h b/repository.h
index 268436779c..6f4af15417 100644
--- a/repository.h
+++ b/repository.h
@@ -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
--
2.44.GIT
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-04-18 12:15 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 11:42 [PATCH 0/5] global: drop external `the_index` variable Patrick Steinhardt
2024-04-15 11:42 ` [PATCH 1/5] t/helper: stop using `the_index` Patrick Steinhardt
2024-04-17 17:23 ` Karthik Nayak
2024-04-15 11:42 ` [PATCH 2/5] builtin: " Patrick Steinhardt
2024-04-17 17:32 ` Karthik Nayak
2024-04-18 12:16 ` Patrick Steinhardt
2024-04-15 11:42 ` [PATCH 3/5] repository: initialize index in `repo_init()` Patrick Steinhardt
2024-04-17 17:38 ` Karthik Nayak
2024-04-18 12:16 ` Patrick Steinhardt
2024-04-15 11:43 ` [PATCH 4/5] builtin/clone: stop using `the_index` Patrick Steinhardt
2024-04-15 11:43 ` [PATCH 5/5] repository: drop global `the_index` variable Patrick Steinhardt
2024-04-15 13:55 ` [PATCH 0/5] global: drop external " Phillip Wood
2024-04-15 14:15 ` Patrick Steinhardt
2024-04-15 17:50 ` Junio C Hamano
2024-04-16 5:27 ` Patrick Steinhardt
2024-04-17 17:40 ` Karthik Nayak
2024-04-18 12:16 ` Patrick Steinhardt
2024-04-18 12:14 ` [PATCH v2 0/6] global: drop " Patrick Steinhardt
2024-04-18 12:14 ` [PATCH v2 1/6] t/helper: stop using `the_index` Patrick Steinhardt
2024-04-18 12:14 ` [PATCH v2 2/6] builtin: " Patrick Steinhardt
2024-04-18 12:14 ` [PATCH v2 3/6] repository: initialize index in `repo_init()` Patrick Steinhardt
2024-04-18 12:14 ` [PATCH v2 4/6] builtin/clone: stop using `the_index` Patrick Steinhardt
2024-04-18 12:14 ` Patrick Steinhardt [this message]
2024-04-18 12:14 ` [PATCH v2 6/6] repository: drop `initialize_the_repository()` Patrick Steinhardt
2024-04-18 19:36 ` [PATCH v2 0/6] global: drop `the_index` variable Junio C Hamano
2024-04-19 4:25 ` Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=549f8c048fb13a4b0b004c5dc72a39fb24a70c7f.1713442061.git.ps@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=phillip.wood123@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).