diff mbox series

[05/20] packfile: pass down repository to `unpack_object_header`

Message ID 655cfebb9d56fe09835985657944f3550b608f3b.1729504641.git.karthik.188@gmail.com (mailing list archive)
State New
Headers show
Series packfile: avoid using the 'the_repository' global variable | expand

Commit Message

karthik nayak Oct. 21, 2024, 9:57 a.m. UTC
The function `unpack_object_header` currently relies on the global
variable `the_repository`. To eliminate global variable usage in
`packfile.c`, we should progressively shift the dependency on
the_repository to higher layers. Let's remove its usage from this
function and any related ones.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 builtin/pack-objects.c |  3 ++-
 pack-bitmap.c          |  3 ++-
 pack-check.c           |  3 ++-
 packfile.c             | 13 ++++++-------
 packfile.h             |  3 ++-
 streaming.c            |  4 ++--
 6 files changed, 16 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 26e3090c85..3893135b59 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1033,7 +1033,8 @@  static void write_reused_pack_one(struct packed_git *reuse_packfile,
 			     offset - (hashfile_total(out) - pack_start));
 
 	cur = offset;
-	type = unpack_object_header(reuse_packfile, w_curs, &cur, &size);
+	type = unpack_object_header(the_repository, reuse_packfile, w_curs,
+				    &cur, &size);
 	assert(type >= 0);
 
 	if (type == OBJ_OFS_DELTA) {
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 067d1741d2..96c91a080e 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -2067,7 +2067,8 @@  static int try_partial_reuse(struct bitmap_index *bitmap_git,
 		return -1; /* not actually in the pack */
 
 	delta_obj_offset = offset;
-	type = unpack_object_header(pack->p, w_curs, &offset, &size);
+	type = unpack_object_header(the_repository, pack->p, w_curs, &offset,
+				    &size);
 	if (type < 0)
 		return -1; /* broken packfile, punt */
 
diff --git a/pack-check.c b/pack-check.c
index bb649edbc1..e2c3b264e7 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -127,7 +127,8 @@  static int verify_packfile(struct repository *r,
 		}
 
 		curpos = entries[i].offset;
-		type = unpack_object_header(p, w_curs, &curpos, &size);
+		type = unpack_object_header(the_repository, p, w_curs, &curpos,
+					    &size);
 		unuse_pack(w_curs);
 
 		if (type == OBJ_BLOB && big_file_threshold <= size) {
diff --git a/packfile.c b/packfile.c
index f300119bb1..7a0d1957e9 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1169,9 +1169,8 @@  unsigned long get_size_from_delta(struct repository *repo, struct packed_git *p,
 	return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
 }
 
-int unpack_object_header(struct packed_git *p,
-			 struct pack_window **w_curs,
-			 off_t *curpos,
+int unpack_object_header(struct repository *r, struct packed_git *p,
+			 struct pack_window **w_curs, off_t *curpos,
 			 unsigned long *sizep)
 {
 	unsigned char *base;
@@ -1185,7 +1184,7 @@  int unpack_object_header(struct packed_git *p,
 	 * the maximum deflated object size is 2^137, which is just
 	 * insane, so we know won't exceed what we have been given.
 	 */
-	base = use_pack(the_repository, p, w_curs, *curpos, &left);
+	base = use_pack(r, p, w_curs, *curpos, &left);
 	used = unpack_object_header_buffer(base, left, &type, sizep);
 	if (!used) {
 		type = OBJ_BAD;
@@ -1332,7 +1331,7 @@  static enum object_type packed_to_object_type(struct repository *r,
 		if (!base_offset)
 			goto unwind;
 		curpos = obj_offset = base_offset;
-		type = unpack_object_header(p, w_curs, &curpos, &size);
+		type = unpack_object_header(r, p, w_curs, &curpos, &size);
 		if (type <= OBJ_NONE) {
 			/* If getting the base itself fails, we first
 			 * retry the base, otherwise unwind */
@@ -1548,7 +1547,7 @@  int packed_object_info(struct repository *r, struct packed_git *p,
 		if (!*oi->contentp)
 			type = OBJ_BAD;
 	} else {
-		type = unpack_object_header(p, &w_curs, &curpos, &size);
+		type = unpack_object_header(r, p, &w_curs, &curpos, &size);
 	}
 
 	if (!oi->contentp && oi->sizep) {
@@ -1736,7 +1735,7 @@  void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
 			}
 		}
 
-		type = unpack_object_header(p, &w_curs, &curpos, &size);
+		type = unpack_object_header(r, p, &w_curs, &curpos, &size);
 		if (type != OBJ_OFS_DELTA && type != OBJ_REF_DELTA)
 			break;
 
diff --git a/packfile.h b/packfile.h
index 22d053a3af..488d78ae9f 100644
--- a/packfile.h
+++ b/packfile.h
@@ -169,7 +169,8 @@  void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object
 unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
 unsigned long get_size_from_delta(struct repository *repo, struct packed_git *,
 				  struct pack_window **, off_t);
-int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
+int unpack_object_header(struct repository *repo, struct packed_git *,
+			 struct pack_window **, off_t *, unsigned long *);
 off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs,
 		     off_t *curpos, enum object_type type,
 		     off_t delta_obj_offset);
diff --git a/streaming.c b/streaming.c
index 58b3b3cff7..56154349fa 100644
--- a/streaming.c
+++ b/streaming.c
@@ -334,7 +334,7 @@  static int close_istream_pack_non_delta(struct git_istream *st)
 }
 
 static int open_istream_pack_non_delta(struct git_istream *st,
-				       struct repository *r UNUSED,
+				       struct repository *r,
 				       const struct object_id *oid UNUSED,
 				       enum object_type *type UNUSED)
 {
@@ -343,7 +343,7 @@  static int open_istream_pack_non_delta(struct git_istream *st,
 
 	window = NULL;
 
-	in_pack_type = unpack_object_header(st->u.in_pack.pack,
+	in_pack_type = unpack_object_header(r, st->u.in_pack.pack,
 					    &window,
 					    &st->u.in_pack.pos,
 					    &st->size);