@@ -827,7 +827,9 @@ static int batch_objects(struct batch_options *opt)
cb.seen = &seen;
for_each_loose_object(batch_unordered_loose, &cb, 0);
- for_each_packed_object(batch_unordered_packed, &cb,
+ for_each_packed_object(the_repository,
+ batch_unordered_packed,
+ &cb,
FOR_EACH_OBJECT_PACK_ORDER);
oidset_clear(&seen);
@@ -835,7 +837,10 @@ static int batch_objects(struct batch_options *opt)
struct oid_array sa = OID_ARRAY_INIT;
for_each_loose_object(collect_loose_object, &sa, 0);
- for_each_packed_object(collect_packed_object, &sa, 0);
+ for_each_packed_object(the_repository,
+ collect_packed_object,
+ &sa,
+ 0);
oid_array_for_each_unique(&sa, batch_object_cb, &cb);
@@ -391,7 +391,10 @@ static void check_connectivity(void)
* traversal.
*/
for_each_loose_object(mark_loose_unreachable_referents, NULL, 0);
- for_each_packed_object(mark_packed_unreachable_referents, NULL, 0);
+ for_each_packed_object(the_repository,
+ mark_packed_unreachable_referents,
+ NULL,
+ 0);
}
/* Look up all the requirements, warn about missing objects.. */
@@ -966,7 +969,10 @@ int cmd_fsck(int argc,
if (connectivity_only) {
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
- for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
+ for_each_packed_object(the_repository,
+ mark_packed_for_connectivity,
+ NULL,
+ 0);
} else {
prepare_alt_odb(the_repository);
for (odb = the_repository->objects->odb; odb; odb = odb->next)
@@ -3540,9 +3540,8 @@ static void read_packs_list_from_stdin(void)
for_each_string_list_item(item, &include_packs) {
struct packed_git *p = item->util;
- for_each_object_in_pack(p,
- add_object_entry_from_pack,
- &revs,
+ for_each_object_in_pack(the_repository, p,
+ add_object_entry_from_pack, &revs,
FOR_EACH_OBJECT_PACK_ORDER);
}
@@ -3929,7 +3928,8 @@ static int add_object_in_unpacked_pack(const struct object_id *oid,
static void add_objects_in_unpacked_packs(void)
{
- if (for_each_packed_object(add_object_in_unpacked_pack, NULL,
+ if (for_each_packed_object(the_repository,
+ add_object_in_unpacked_pack, NULL,
FOR_EACH_OBJECT_PACK_ORDER |
FOR_EACH_OBJECT_LOCAL_ONLY |
FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |
@@ -404,7 +404,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
* {type -> existing pack order} ordering when computing deltas instead
* of a {type -> size} ordering, which may produce better deltas.
*/
- for_each_packed_object(write_oid, &cmd,
+ for_each_packed_object(the_repository, write_oid, &cmd,
FOR_EACH_OBJECT_PROMISOR_ONLY);
if (cmd.in == -1) {
@@ -1923,8 +1923,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
ret = error(_("error opening index for %s"), packname.buf);
goto cleanup;
}
- for_each_object_in_pack(p, add_packed_commits, ctx,
- FOR_EACH_OBJECT_PACK_ORDER);
+ for_each_object_in_pack(the_repository, p, add_packed_commits,
+ ctx, FOR_EACH_OBJECT_PACK_ORDER);
close_pack(p);
free(p);
}
@@ -1960,7 +1960,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
ctx->progress = start_delayed_progress(
_("Finding commits for commit graph among packed objects"),
ctx->approx_nr_objects);
- for_each_packed_object(add_packed_commits, ctx,
+ for_each_packed_object(the_repository, add_packed_commits, ctx,
FOR_EACH_OBJECT_PACK_ORDER);
if (ctx->progress_done < ctx->approx_nr_objects)
display_progress(ctx->progress, ctx->approx_nr_objects);
@@ -542,10 +542,11 @@ typedef int each_packed_object_fn(const struct object_id *oid,
struct packed_git *pack,
uint32_t pos,
void *data);
-int for_each_object_in_pack(struct packed_git *p,
+int for_each_object_in_pack(struct repository *repo,
+ struct packed_git *p,
each_packed_object_fn, void *data,
enum for_each_object_flags flags);
-int for_each_packed_object(each_packed_object_fn, void *,
- enum for_each_object_flags flags);
+int for_each_packed_object(struct repository *repo, each_packed_object_fn,
+ void *, enum for_each_object_flags flags);
#endif /* OBJECT_STORE_LL_H */
@@ -2161,7 +2161,8 @@ int has_pack_index(struct repository *repo, const unsigned char *sha1)
return 1;
}
-int for_each_object_in_pack(struct packed_git *p,
+int for_each_object_in_pack(struct repository *repo,
+ struct packed_git *p,
each_packed_object_fn cb, void *data,
enum for_each_object_flags flags)
{
@@ -2169,7 +2170,7 @@ int for_each_object_in_pack(struct packed_git *p,
int r = 0;
if (flags & FOR_EACH_OBJECT_PACK_ORDER) {
- if (load_pack_revindex(the_repository, p))
+ if (load_pack_revindex(repo, p))
return -1;
}
@@ -2194,7 +2195,7 @@ int for_each_object_in_pack(struct packed_git *p,
else
index_pos = i;
- if (nth_packed_object_id(the_repository, &oid, p, index_pos) < 0)
+ if (nth_packed_object_id(repo, &oid, p, index_pos) < 0)
return error("unable to get sha1 of object %u in %s",
index_pos, p->pack_name);
@@ -2205,15 +2206,15 @@ int for_each_object_in_pack(struct packed_git *p,
return r;
}
-int for_each_packed_object(each_packed_object_fn cb, void *data,
- enum for_each_object_flags flags)
+int for_each_packed_object(struct repository *repo, each_packed_object_fn cb,
+ void *data, enum for_each_object_flags flags)
{
struct packed_git *p;
int r = 0;
int pack_errors = 0;
- prepare_packed_git(the_repository);
- for (p = get_all_packs(the_repository); p; p = p->next) {
+ prepare_packed_git(repo);
+ for (p = get_all_packs(repo); p; p = p->next) {
if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
continue;
if ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) &&
@@ -2229,7 +2230,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data,
pack_errors = 1;
continue;
}
- r = for_each_object_in_pack(p, cb, data, flags);
+ r = for_each_object_in_pack(repo, p, cb, data, flags);
if (r)
break;
}
@@ -2298,7 +2299,8 @@ int is_promisor_object(const struct object_id *oid)
if (!promisor_objects_prepared) {
if (repo_has_promisor_remote(the_repository)) {
- for_each_packed_object(add_promisor_object,
+ for_each_packed_object(the_repository,
+ add_promisor_object,
&promisor_objects,
FOR_EACH_OBJECT_PROMISOR_ONLY |
FOR_EACH_OBJECT_PACK_ORDER);
@@ -324,7 +324,7 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
if (ignore_in_core_kept_packs)
flags |= FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS;
- r = for_each_packed_object(add_recent_packed, &data, flags);
+ r = for_each_packed_object(revs->repo, add_recent_packed, &data, flags);
done:
oidset_clear(&data.extra_recent_oids);
@@ -3915,7 +3915,7 @@ int prepare_revision_walk(struct rev_info *revs)
revs->treesame.name = "treesame";
if (revs->exclude_promisor_objects) {
- for_each_packed_object(mark_uninteresting, revs,
+ for_each_packed_object(revs->repo, mark_uninteresting, revs,
FOR_EACH_OBJECT_PROMISOR_ONLY);
}
The function `for_each_packed_object` 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 | 9 +++++++-- builtin/fsck.c | 10 ++++++++-- builtin/pack-objects.c | 8 ++++---- builtin/repack.c | 2 +- commit-graph.c | 6 +++--- object-store-ll.h | 7 ++++--- packfile.c | 20 +++++++++++--------- reachable.c | 2 +- revision.c | 2 +- 9 files changed, 40 insertions(+), 26 deletions(-)