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,  shejialuo@gmail.com, gitster@pobox.com,
	 Christian Couder <chriscool@tuxfamily.org>
Subject: [PATCH v3 3/8] write-midx: add repository field to `write_midx_context`
Date: Wed, 27 Nov 2024 17:28:28 +0100	[thread overview]
Message-ID: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-3-c5a99f85009b@gmail.com> (raw)
In-Reply-To: <20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-0-c5a99f85009b@gmail.com>

The struct `write_midx_context` is used to pass context for creating
MIDX files. Add the repository field here to ensure that most functions
within `midx-write.c` have access to the field and can use that instead
of the global `the_repository` variable.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 midx-write.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/midx-write.c b/midx-write.c
index 564438f616f59cd24edda956e4af0e0acf167138..1c355cdf8db4e9fed61a4aabf61a237ad26181ce 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -110,6 +110,8 @@ struct write_midx_context {
 	uint32_t num_multi_pack_indexes_before;
 
 	struct string_list *to_include;
+
+	struct repository *repo;
 };
 
 static int should_include_pack(const struct write_midx_context *ctx,
@@ -154,7 +156,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len,
 			return;
 
 		ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);
-		p = add_packed_git(the_repository, full_path, full_path_len, 0);
+		p = add_packed_git(ctx->repo, full_path, full_path_len, 0);
 		if (!p) {
 			warning(_("failed to add packfile '%s'"),
 				full_path);
@@ -480,7 +482,7 @@ static int write_midx_oid_lookup(struct hashfile *f,
 				 void *data)
 {
 	struct write_midx_context *ctx = data;
-	unsigned char hash_len = the_hash_algo->rawsz;
+	unsigned char hash_len = ctx->repo->hash_algo->rawsz;
 	struct pack_midx_entry *list = ctx->entries;
 	uint32_t i;
 
@@ -605,7 +607,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)
 	uint32_t *pack_order, base_objects = 0;
 	uint32_t i;
 
-	trace2_region_enter("midx", "midx_pack_order", the_repository);
+	trace2_region_enter("midx", "midx_pack_order", ctx->repo);
 
 	if (ctx->incremental && ctx->base_midx)
 		base_objects = ctx->base_midx->num_objects +
@@ -640,7 +642,7 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)
 	}
 	free(data);
 
-	trace2_region_leave("midx", "midx_pack_order", the_repository);
+	trace2_region_leave("midx", "midx_pack_order", ctx->repo);
 
 	return pack_order;
 }
@@ -651,9 +653,10 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,
 	struct strbuf buf = STRBUF_INIT;
 	char *tmp_file;
 
-	trace2_region_enter("midx", "write_midx_reverse_index", the_repository);
+	trace2_region_enter("midx", "write_midx_reverse_index", ctx->repo);
 
-	strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex(midx_hash));
+	strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex_algop(midx_hash,
+								    ctx->repo->hash_algo));
 
 	tmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr,
 					midx_hash, WRITE_REV);
@@ -664,7 +667,7 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,
 	strbuf_release(&buf);
 	free(tmp_file);
 
-	trace2_region_leave("midx", "write_midx_reverse_index", the_repository);
+	trace2_region_leave("midx", "write_midx_reverse_index", ctx->repo);
 }
 
 static void prepare_midx_packing_data(struct packing_data *pdata,
@@ -672,10 +675,10 @@ static void prepare_midx_packing_data(struct packing_data *pdata,
 {
 	uint32_t i;
 
-	trace2_region_enter("midx", "prepare_midx_packing_data", the_repository);
+	trace2_region_enter("midx", "prepare_midx_packing_data", ctx->repo);
 
 	memset(pdata, 0, sizeof(struct packing_data));
-	prepare_packing_data(the_repository, pdata);
+	prepare_packing_data(ctx->repo, pdata);
 
 	for (i = 0; i < ctx->entries_nr; i++) {
 		uint32_t pos = ctx->pack_order[i];
@@ -686,7 +689,7 @@ static void prepare_midx_packing_data(struct packing_data *pdata,
 			       ctx->info[ctx->pack_perm[from->pack_int_id]].p);
 	}
 
-	trace2_region_leave("midx", "prepare_midx_packing_data", the_repository);
+	trace2_region_leave("midx", "prepare_midx_packing_data", ctx->repo);
 }
 
 static int add_ref_to_pending(const char *refname, const char *referent UNUSED,
@@ -784,17 +787,16 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
 	struct rev_info revs;
 	struct bitmap_commit_cb cb = {0};
 
-	trace2_region_enter("midx", "find_commits_for_midx_bitmap",
-			    the_repository);
+	trace2_region_enter("midx", "find_commits_for_midx_bitmap", ctx->repo);
 
 	cb.ctx = ctx;
 
-	repo_init_revisions(the_repository, &revs, NULL);
+	repo_init_revisions(ctx->repo, &revs, NULL);
 	if (refs_snapshot) {
 		read_refs_snapshot(refs_snapshot, &revs);
 	} else {
 		setup_revisions(0, NULL, &revs, NULL);
-		refs_for_each_ref(get_main_ref_store(the_repository),
+		refs_for_each_ref(get_main_ref_store(ctx->repo),
 				  add_ref_to_pending, &revs);
 	}
 
@@ -822,8 +824,7 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
 
 	release_revisions(&revs);
 
-	trace2_region_leave("midx", "find_commits_for_midx_bitmap",
-			    the_repository);
+	trace2_region_leave("midx", "find_commits_for_midx_bitmap", ctx->repo);
 
 	return cb.commits;
 }
@@ -945,7 +946,7 @@ static int fill_packs_from_midx(struct write_midx_context *ctx,
 			 */
 			if (flags & MIDX_WRITE_REV_INDEX ||
 			    preferred_pack_name) {
-				if (prepare_midx_pack(the_repository, m,
+				if (prepare_midx_pack(ctx->repo, m,
 						      m->num_packs_in_base + i)) {
 					error(_("could not load pack"));
 					return 1;
@@ -1073,6 +1074,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
 
 	trace2_region_enter("midx", "write_midx_internal", r);
 
+	ctx.repo = r;
 
 	ctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL);
 	if (ctx.incremental && (flags & MIDX_WRITE_BITMAP))
@@ -1469,7 +1471,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
 	}
 
 	if (ctx.m || ctx.base_midx)
-		close_object_store(the_repository->objects);
+		close_object_store(ctx.repo->objects);
 
 	if (commit_lock_file(&lk) < 0)
 		die_errno(_("could not write multi-pack-index"));

-- 
2.47.1


  parent reply	other threads:[~2024-11-27 16:28 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 ` [PATCH 5/8] midx: pass `repository` to `load_multi_pack_index` Karthik Nayak
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     ` Karthik Nayak [this message]
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=20241127-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v3-3-c5a99f85009b@gmail.com \
    --to=karthik.188@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.com \
    --cc=shejialuo@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.
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).