git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: Karthik Nayak <karthik.188@gmail.com>, me@ttaylorr.com, peff@peff.net
Subject: [PATCH 5/8] midx: pass `repository` to `load_multi_pack_index`
Date: Fri, 15 Nov 2024 14:42:18 +0100	[thread overview]
Message-ID: <20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-5-761f8a2c7775@gmail.com> (raw)
In-Reply-To: <20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-0-761f8a2c7775@gmail.com>

The `load_multi_pack_index` function in midx uses `the_repository`
variable to access the `repository` struct. Let's modify the function
and its callee's to send the `repository` field.

This moves usage of `the_repository` to the `test-read-midx.c` file.
While that is not optimal, it is okay, since we'll slowly move the usage
of `the_repository` up the layers and eventually remove it entirely.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 midx.c                    | 11 ++++++-----
 midx.h                    |  4 +++-
 t/helper/test-read-midx.c |  8 ++++----
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/midx.c b/midx.c
index 6f0fb8285af14843da132ef1b0c3a8bdd06732c9..98ee84d4a8bf388906634ad695ff39acdaa2c6d5 100644
--- a/midx.c
+++ b/midx.c
@@ -372,7 +372,8 @@ static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r
 	return m;
 }
 
-struct multi_pack_index *load_multi_pack_index(const char *object_dir,
+struct multi_pack_index *load_multi_pack_index(struct repository *r,
+					       const char *object_dir,
 					       int local)
 {
 	struct strbuf midx_name = STRBUF_INIT;
@@ -380,10 +381,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir,
 
 	get_midx_filename(&midx_name, object_dir);
 
-	m = load_multi_pack_index_one(the_repository, object_dir,
+	m = load_multi_pack_index_one(r, object_dir,
 				      midx_name.buf, local);
 	if (!m)
-		m = load_multi_pack_index_chain(the_repository, object_dir, local);
+		m = load_multi_pack_index_chain(r, object_dir, local);
 
 	strbuf_release(&midx_name);
 
@@ -727,7 +728,7 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i
 		if (!strcmp(object_dir, m_search->object_dir))
 			return 1;
 
-	m = load_multi_pack_index(object_dir, local);
+	m = load_multi_pack_index(r, object_dir, local);
 
 	if (m) {
 		struct multi_pack_index *mp = r->objects->multi_pack_index;
@@ -881,7 +882,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
 	struct pair_pos_vs_id *pairs = NULL;
 	uint32_t i;
 	struct progress *progress = NULL;
-	struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
+	struct multi_pack_index *m = load_multi_pack_index(r, object_dir, 1);
 	struct multi_pack_index *curr;
 	verify_midx_error = 0;
 
diff --git a/midx.h b/midx.h
index c37ad5b5242b56d21fd76bd59957a1bdb82786ec..78efa28d35371795fa33c68660278182debb60ab 100644
--- a/midx.h
+++ b/midx.h
@@ -97,7 +97,9 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);
 void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,
 				 const unsigned char *hash, const char *ext);
 
-struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
+struct multi_pack_index *load_multi_pack_index(struct repository *r,
+					       const char *object_dir,
+					       int local);
 int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
 struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
 				   uint32_t pack_int_id);
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 438fb9fc6197fc465f79d9a65b719ae315fed373..fc632369618917e2d8cdcb77bd9073c61e1544c1 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -18,7 +18,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,
 	struct multi_pack_index *m;
 
 	setup_git_directory();
-	m = load_multi_pack_index(object_dir, 1);
+	m = load_multi_pack_index(the_repository, object_dir, 1);
 
 	if (!m)
 		return 1;
@@ -82,7 +82,7 @@ static int read_midx_checksum(const char *object_dir)
 	struct multi_pack_index *m;
 
 	setup_git_directory();
-	m = load_multi_pack_index(object_dir, 1);
+	m = load_multi_pack_index(the_repository, object_dir, 1);
 	if (!m)
 		return 1;
 	printf("%s\n", hash_to_hex(get_midx_checksum(m)));
@@ -98,7 +98,7 @@ static int read_midx_preferred_pack(const char *object_dir)
 
 	setup_git_directory();
 
-	midx = load_multi_pack_index(object_dir, 1);
+	midx = load_multi_pack_index(the_repository, object_dir, 1);
 	if (!midx)
 		return 1;
 
@@ -121,7 +121,7 @@ static int read_midx_bitmapped_packs(const char *object_dir)
 
 	setup_git_directory();
 
-	midx = load_multi_pack_index(object_dir, 1);
+	midx = load_multi_pack_index(the_repository, object_dir, 1);
 	if (!midx)
 		return 1;
 

-- 
2.47.0


  parent reply	other threads:[~2024-11-15 13:42 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-15 13:42 [PATCH 0/8] Change midx.c and midx-write.c to not use global variables Karthik Nayak
2024-11-15 13:42 ` [PATCH 1/8] builtin: pass repository to sub commands Karthik Nayak
2024-11-16 12:49   ` shejialuo
2024-11-18  8:05     ` Patrick Steinhardt
2024-11-18 15:17     ` karthik nayak
2024-11-15 13:42 ` [PATCH 2/8] midx-write: add repository field to `write_midx_context` Karthik Nayak
2024-11-15 23:05   ` brian m. carlson
2024-11-18 15:17     ` karthik nayak
2024-11-18  8:05   ` Patrick Steinhardt
2024-11-18 15:37     ` karthik nayak
2024-11-15 13:42 ` [PATCH 3/8] midx-write: pass down repository to `write_midx_file[_only]` Karthik Nayak
2024-11-18  8:05   ` Patrick Steinhardt
2024-11-15 13:42 ` [PATCH 4/8] midx: cleanup internal usage of `the_repository` and `the_hash_algo` Karthik Nayak
2024-11-18  8:06   ` Patrick Steinhardt
2024-11-18 16:16     ` karthik nayak
2024-11-15 13:42 ` Karthik Nayak [this message]
2024-11-15 13:42 ` [PATCH 6/8] midx: pass down `hash_algo` to `get_midx_filename[_ext]` Karthik Nayak
2024-11-16 13:16   ` shejialuo
2024-11-18 16:25     ` karthik nayak
2024-11-19 12:12       ` shejialuo
2024-11-15 13:42 ` [PATCH 7/8] midx: pass down `hash_algo` to `get_split_midx_filename_ext` Karthik Nayak
2024-11-16 13:20   ` shejialuo
2024-11-15 13:42 ` [PATCH 8/8] midx: inline the `MIDX_MIN_SIZE` definition Karthik Nayak
2024-11-15 14:13 ` [PATCH 0/8] Change midx.c and midx-write.c to not use global variables karthik nayak
2024-11-19 15:36 ` [PATCH v2 00/10] " Karthik Nayak
2024-11-19 15:36   ` [PATCH v2 01/10] builtin: pass repository to sub commands Karthik Nayak
2024-11-19 15:36   ` [PATCH v2 02/10] midx-write: pass down repository to static functions Karthik Nayak
2024-11-20 18:15     ` Christian Couder
2024-11-20 19:41       ` Taylor Blau
2024-11-21 14:57       ` karthik nayak
2024-11-20 19:43     ` Taylor Blau
2024-11-21 15:06       ` karthik nayak
2024-11-19 15:36   ` [PATCH v2 03/10] midx-write: use `revs->repo` inside `read_refs_snapshot` Karthik Nayak
2024-11-20 12:58     ` shejialuo
2024-11-20 14:26       ` Richard Kerry
2024-11-20 19:46         ` Taylor Blau
2024-11-21 15:30           ` karthik nayak
2024-11-20 19:44     ` Taylor Blau
2024-11-19 15:36   ` [PATCH v2 04/10] write-midx: add repository field to `write_midx_context` Karthik Nayak
2024-11-19 15:36   ` [PATCH v2 05/10] midx-write: pass down repository to `write_midx_file[_only]` Karthik Nayak
2024-11-20 20:11     ` Taylor Blau
2024-11-19 15:36   ` [PATCH v2 06/10] midx: cleanup internal usage of `the_repository` and `the_hash_algo` Karthik Nayak
2024-11-19 15:36   ` [PATCH v2 07/10] midx: pass `repository` to `load_multi_pack_index` Karthik Nayak
2024-11-19 15:36   ` [PATCH v2 08/10] midx: pass down `hash_algo` to `get_midx_filename[_ext]` Karthik Nayak
2024-11-20 18:15     ` Christian Couder
2024-11-21 15:35       ` karthik nayak
2024-11-19 15:36   ` [PATCH v2 09/10] midx: pass down `hash_algo` to `get_split_midx_filename_ext` Karthik Nayak
2024-11-20 18:15     ` Christian Couder
2024-11-20 22:23       ` Taylor Blau
2024-11-21 15:41         ` karthik nayak
2024-11-19 15:36   ` [PATCH v2 10/10] midx: inline the `MIDX_MIN_SIZE` definition Karthik Nayak
2024-11-20 13:13     ` shejialuo
2024-11-21 15:41       ` karthik nayak
2024-11-20 18:20   ` [PATCH v2 00/10] Change midx.c and midx-write.c to not use global variables Christian Couder
2024-11-20 22:24     ` Taylor Blau
2024-11-21  0:09       ` Junio C Hamano
2024-11-21  2:19   ` Junio C Hamano
2024-11-22 10:25     ` karthik nayak
2024-11-27 16:28   ` [PATCH v3 0/8] " Karthik Nayak
2024-11-27 16:28     ` [PATCH v3 1/8] midx-write: pass down repository to static functions Karthik Nayak
2024-11-27 16:28     ` [PATCH v3 2/8] midx-write: use `revs->repo` inside `read_refs_snapshot` Karthik Nayak
2024-11-27 16:28     ` [PATCH v3 3/8] write-midx: add repository field to `write_midx_context` Karthik Nayak
2024-11-27 16:28     ` [PATCH v3 4/8] midx-write: pass down repository to `write_midx_file[_only]` Karthik Nayak
2024-11-27 16:28     ` [PATCH v3 5/8] midx: cleanup internal usage of `the_repository` and `the_hash_algo` Karthik Nayak
2024-11-27 16:28     ` [PATCH v3 6/8] midx: pass `repository` to `load_multi_pack_index` Karthik Nayak
2024-11-27 16:28     ` [PATCH v3 7/8] midx: pass down `hash_algo` to functions using global variables Karthik Nayak
2024-11-27 16:28     ` [PATCH v3 8/8] midx: inline the `MIDX_MIN_SIZE` definition Karthik Nayak
2024-11-28  1:27     ` [PATCH v3 0/8] Change midx.c and midx-write.c to not use global variables Junio C Hamano
2024-12-03  9:43       ` Patrick Steinhardt
2024-12-03 23:06         ` Junio C Hamano

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-5-761f8a2c7775@gmail.com \
    --to=karthik.188@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    /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.
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 NNTP newsgroup(s).