@@ -632,14 +632,14 @@ static int batch_unordered_loose(const struct object_id *oid,
return batch_unordered_object(oid, NULL, 0, data);
}
-static int batch_unordered_packed(struct repository *repo UNUSED,
+static int batch_unordered_packed(struct repository *repo,
const struct object_id *oid,
struct packed_git *pack,
uint32_t pos,
void *data)
{
return batch_unordered_object(oid, pack,
- nth_packed_object_offset(pack, pos),
+ nth_packed_object_offset(repo, pack, pos),
data);
}
@@ -3361,7 +3361,7 @@ static int git_pack_config(const char *k, const char *v,
static int stdin_packs_found_nr;
static int stdin_packs_hints_nr;
-static int add_object_entry_from_pack(struct repository *repo UNUSED,
+static int add_object_entry_from_pack(struct repository *repo,
const struct object_id *oid,
struct packed_git *p,
uint32_t pos,
@@ -3375,7 +3375,7 @@ static int add_object_entry_from_pack(struct repository *repo UNUSED,
if (have_duplicate_entry(oid, 0))
return 0;
- ofs = nth_packed_object_offset(p, pos);
+ ofs = nth_packed_object_offset(repo, p, pos);
if (!want_object_in_pack(oid, 0, &p, &ofs))
return 0;
@@ -3919,7 +3919,7 @@ static int add_object_in_unpacked_pack(struct repository *repo,
} else {
mtime = pack->mtime;
}
- offset = nth_packed_object_offset(pack, pos);
+ offset = nth_packed_object_offset(repo, pack, pos);
add_cruft_object_entry(oid, OBJ_NONE, pack, offset,
NULL, mtime);
@@ -1495,7 +1495,7 @@ static int add_packed_commits(struct repository *repo UNUSED,
{
struct write_commit_graph_context *ctx = (struct write_commit_graph_context*)data;
enum object_type type;
- off_t offset = nth_packed_object_offset(pack, pos);
+ off_t offset = nth_packed_object_offset(ctx->r, pack, pos);
struct object_info oi = OBJECT_INFO_INIT;
if (ctx->progress)
@@ -233,7 +233,7 @@ static void fill_pack_entry(uint32_t pack_int_id,
entry->pack_int_id = pack_int_id;
entry->pack_mtime = p->mtime;
- entry->offset = nth_packed_object_offset(p, cur_object);
+ entry->offset = nth_packed_object_offset(the_repository, p, cur_object);
entry->preferred = !!preferred;
}
@@ -98,7 +98,7 @@ static int verify_packfile(struct repository *r,
entries[nr_objects].offset = pack_sig_ofs;
/* first sort entries by pack offset, since unpacking them is more efficient that way */
for (i = 0; i < nr_objects; i++) {
- entries[i].offset = nth_packed_object_offset(p, i);
+ entries[i].offset = nth_packed_object_offset(r, p, i);
entries[i].nr = i;
}
QSORT(entries, nr_objects, compare_entries);
@@ -466,7 +466,8 @@ off_t pack_pos_to_offset(struct packed_git *p, uint32_t pos)
else if (pos == p->num_objects)
return p->pack_size - the_hash_algo->rawsz;
else
- return nth_packed_object_offset(p, pack_pos_to_index(p, pos));
+ return nth_packed_object_offset(the_repository, p,
+ pack_pos_to_index(p, pos));
}
uint32_t pack_pos_to_midx(struct multi_pack_index *m, uint32_t pos)
@@ -1964,10 +1964,12 @@ void check_pack_index_ptr(const struct packed_git *p, const void *vptr)
p->pack_name);
}
-off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n)
+off_t nth_packed_object_offset(struct repository *repo,
+ const struct packed_git *p,
+ uint32_t n)
{
const unsigned char *index = p->index_data;
- const unsigned int hashsz = the_hash_algo->rawsz;
+ const unsigned int hashsz = repo->hash_algo->rawsz;
index += 4 * 256;
if (p->index_version == 1) {
return ntohl(*((uint32_t *)(index + st_mult(hashsz + 4, n))));
@@ -1998,7 +2000,7 @@ off_t find_pack_entry_one(struct repository *repo, const unsigned char *sha1,
hashcpy(oid.hash, sha1, repo->hash_algo);
if (bsearch_pack(repo, &oid, p, &result))
- return nth_packed_object_offset(p, result);
+ return nth_packed_object_offset(repo, p, result);
return 0;
}
@@ -160,7 +160,9 @@ int nth_packed_object_id(struct repository *repo, struct object_id *,
* Return the offset of the nth object within the specified packfile.
* The index must already be opened.
*/
-off_t nth_packed_object_offset(const struct packed_git *, uint32_t n);
+off_t nth_packed_object_offset(struct repository *repo,
+ const struct packed_git *,
+ uint32_t n);
/*
* If the object named sha1 is present in the specified packfile,
@@ -295,7 +295,8 @@ static int add_recent_packed(struct repository *repo,
die(_("could not load cruft pack .mtimes"));
mtime = nth_packed_mtime(p, pos);
}
- add_recent_object(oid, p, nth_packed_object_offset(p, pos), mtime, data);
+ add_recent_object(oid, p, nth_packed_object_offset(repo, p, pos), mtime,
+ data);
return 0;
}
The function `nth_packed_object_offset` 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/cat-file.c | 4 ++-- builtin/pack-objects.c | 6 +++--- commit-graph.c | 2 +- midx-write.c | 2 +- pack-check.c | 2 +- pack-revindex.c | 3 ++- packfile.c | 8 +++++--- packfile.h | 4 +++- reachable.c | 3 ++- 9 files changed, 20 insertions(+), 14 deletions(-)