diff mbox series

[7/8] midx: pass down `hash_algo` to `get_split_midx_filename_ext`

Message ID 20241115-374-refactor-midx-c-and-midx-write-c-to-not-depend-on-global-state-v1-7-761f8a2c7775@gmail.com (mailing list archive)
State New
Headers show
Series Change midx.c and midx-write.c to not use global variables | expand

Commit Message

karthik nayak Nov. 15, 2024, 1:42 p.m. UTC
Similar to the previous commit, pass down `hash_algo` to
`get_split_midx_filename_ext` so we can use `hash_to_hex_algop` and not
rely on the `the_repository` global variable.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 midx-write.c |  7 ++++---
 midx.c       | 10 ++++++----
 midx.h       |  3 ++-
 3 files changed, 12 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/midx-write.c b/midx-write.c
index 7c1563845993075d622f59faeb25462180434abd..21a64f791cd8addf33437d85304dcf35bf17d904 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -992,7 +992,8 @@  static int link_midx_to_chain(struct multi_pack_index *m)
 
 		get_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir,
 				      hash, midx_exts[i].non_split);
-		get_split_midx_filename_ext(&to, m->object_dir, hash,
+		get_split_midx_filename_ext(m->repo->hash_algo, &to,
+					    m->object_dir, hash,
 					    midx_exts[i].split);
 
 		if (link(from.buf, to.buf) < 0 && errno != ENOENT) {
@@ -1438,8 +1439,8 @@  static int write_midx_internal(struct repository *r, const char *object_dir,
 		if (link_midx_to_chain(ctx.base_midx) < 0)
 			return -1;
 
-		get_split_midx_filename_ext(&final_midx_name, object_dir,
-					    midx_hash, MIDX_EXT_MIDX);
+		get_split_midx_filename_ext(r->hash_algo, &final_midx_name,
+					    object_dir, midx_hash, MIDX_EXT_MIDX);
 
 		if (rename_tempfile(&incr, final_midx_name.buf) < 0) {
 			error_errno(_("unable to rename new multi-pack-index layer"));
diff --git a/midx.c b/midx.c
index 9bed4185ff4d44602aedfe0329dd840ff9e85435..f45ea842cd6eda23d2eadc9deaae43839aef24c1 100644
--- a/midx.c
+++ b/midx.c
@@ -236,11 +236,13 @@  void get_midx_chain_filename(struct strbuf *buf, const char *object_dir)
 	strbuf_addstr(buf, "/multi-pack-index-chain");
 }
 
-void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,
+void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,
+				 struct strbuf *buf, const char *object_dir,
 				 const unsigned char *hash, const char *ext)
 {
 	get_midx_chain_dirname(buf, object_dir);
-	strbuf_addf(buf, "/multi-pack-index-%s.%s", hash_to_hex(hash), ext);
+	strbuf_addf(buf, "/multi-pack-index-%s.%s",
+		    hash_to_hex_algop(hash, hash_algo), ext);
 }
 
 static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo,
@@ -328,8 +330,8 @@  static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r,
 		valid = 0;
 
 		strbuf_reset(&buf);
-		get_split_midx_filename_ext(&buf, object_dir, layer.hash,
-					    MIDX_EXT_MIDX);
+		get_split_midx_filename_ext(r->hash_algo, &buf, object_dir,
+					    layer.hash, MIDX_EXT_MIDX);
 		m = load_multi_pack_index_one(r, object_dir, buf.buf, local);
 
 		if (m) {
diff --git a/midx.h b/midx.h
index 7620820d4d0272926af9e4eeb68bfb73404c7ec2..9d1374cbd58d016bb82338337b2a4e5ba7234092 100644
--- a/midx.h
+++ b/midx.h
@@ -97,7 +97,8 @@  void get_midx_filename_ext(const struct git_hash_algo *hash_algo,
 			   const unsigned char *hash, const char *ext);
 void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);
 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,
+void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,
+				 struct strbuf *buf, const char *object_dir,
 				 const unsigned char *hash, const char *ext);
 
 struct multi_pack_index *load_multi_pack_index(struct repository *r,