packfile: pass down repository to `has_object[_kept]_pack`
The functions `has_object[_kept]_pack` currently rely 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 these functions and any related ones. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karthik Nayak committed
Dec 3, 2024 at 15:43 UTC
cc656f4eb2b7b10bc530c96844909c869bdd1fdf
11 files changed
+21
-17
builtin/count-objects.c
+1
-1
@@ -67,7 +67,7 @@ static int count_loose(const struct object_id *oid, const char *path,
67
else {
68
loose_size += on_disk_bytes(st);
69
loose++;
70
- if (verbose && has_object_pack(oid))
70
+ if (verbose && has_object_pack(the_repository, oid))
71
packed_loose++;
72
}
73
return 0;
builtin/fsck.c
+1
-1
@@ -272,7 +272,7 @@ static void check_reachable_object(struct object *obj)
272
if (!(obj->flags & HAS_OBJ)) {
273
if (is_promisor_object(&obj->oid))
274
return;
275
- if (has_object_pack(&obj->oid))
275
+ if (has_object_pack(the_repository, &obj->oid))
276
return; /* it is in pack - forget about it */
277
printf_ln(_("missing %s %s"),
278
printable_type(&obj->oid, obj->type),
builtin/pack-objects.c
+2
-2
@@ -1529,7 +1529,7 @@ static int want_found_object(const struct object_id *oid, int exclude,
1529
return 0;
1530
if (ignore_packed_keep_in_core && p->pack_keep_in_core)
1531
return 0;
1532
- if (has_object_kept_pack(oid, flags))
1532
+ if (has_object_kept_pack(p->repo, oid, flags))
1533
return 0;
1534
}
1535
@@ -3627,7 +3627,7 @@ static void show_cruft_commit(struct commit *commit, void *data)
3627
3628
static int cruft_include_check_obj(struct object *obj, void *data UNUSED)
3629
{
3630
- return !has_object_kept_pack(&obj->oid, IN_CORE_KEEP_PACKS);
3630
+ return !has_object_kept_pack(to_pack.repo, &obj->oid, IN_CORE_KEEP_PACKS);
3631
}
3632
3633
static int cruft_include_check(struct commit *commit, void *data)
diff.c
+2
-1
@@ -4041,7 +4041,8 @@ static int reuse_worktree_file(struct index_state *istate,
4041
* objects however would tend to be slower as they need
4042
* to be individually opened and inflated.
4043
*/
4044
- if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))
4044
+ if (!FAST_WORKING_DIRECTORY && !want_file &&
4045
+ has_object_pack(istate->repo, oid))
4046
return 0;
4047
4048
/*
list-objects.c
+2
-1
@@ -41,7 +41,8 @@ static void show_object(struct traversal_context *ctx,
41
{
42
if (!ctx->show_object)
43
return;
44
- if (ctx->revs->unpacked && has_object_pack(&object->oid))
44
+ if (ctx->revs->unpacked && has_object_pack(ctx->revs->repo,
45
+ &object->oid))
46
return;
47
48
ctx->show_object(object, name, ctx->show_data);
pack-bitmap.c
+1
-1
@@ -1889,7 +1889,7 @@ static void filter_packed_objects_from_bitmap(struct bitmap_index *bitmap_git,
1889
bitmap_unset(result, i);
1890
1891
for (i = 0; i < eindex->count; ++i) {
1892
- if (has_object_pack(&eindex->objects[i]->oid))
1892
+ if (has_object_pack(the_repository, &eindex->objects[i]->oid))
1893
bitmap_unset(result, objects_nr + i);
1894
}
1895
}
packfile.c
+5
-4
@@ -2143,16 +2143,17 @@ int find_kept_pack_entry(struct repository *r,
2143
return 0;
2144
}
2145
2146
-int has_object_pack(const struct object_id *oid)
2146
+int has_object_pack(struct repository *r, const struct object_id *oid)
2147
{
2148
struct pack_entry e;
2149
- return find_pack_entry(the_repository, oid, &e);
2149
+ return find_pack_entry(r, oid, &e);
2150
}
2151
2152
-int has_object_kept_pack(const struct object_id *oid, unsigned flags)
2152
+int has_object_kept_pack(struct repository *r, const struct object_id *oid,
2153
+ unsigned flags)
2154
{
2155
struct pack_entry e;
2155
- return find_kept_pack_entry(the_repository, oid, flags, &e);
2156
+ return find_kept_pack_entry(r, oid, flags, &e);
2157
}
2158
2159
int for_each_object_in_pack(struct packed_git *p,
packfile.h
+3
-2
@@ -193,8 +193,9 @@ const struct packed_git *has_packed_and_bad(struct repository *, const struct ob
193
int find_pack_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e);
194
int find_kept_pack_entry(struct repository *r, const struct object_id *oid, unsigned flags, struct pack_entry *e);
195
196
-int has_object_pack(const struct object_id *oid);
197
-int has_object_kept_pack(const struct object_id *oid, unsigned flags);
196
+int has_object_pack(struct repository *r, const struct object_id *oid);
197
+int has_object_kept_pack(struct repository *r, const struct object_id *oid,
198
+ unsigned flags);
199
200
/*
201
* Return 1 if an object in a promisor packfile is or refers to the given
prune-packed.c
+1
-1
@@ -24,7 +24,7 @@ static int prune_object(const struct object_id *oid, const char *path,
24
{
25
int *opts = data;
26
27
- if (!has_object_pack(oid))
27
+ if (!has_object_pack(the_repository, oid))
28
return 0;
29
30
if (*opts & PRUNE_PACKED_DRY_RUN)
reachable.c
+1
-1
@@ -239,7 +239,7 @@ static int want_recent_object(struct recent_data *data,
239
const struct object_id *oid)
240
{
241
if (data->ignore_in_core_kept_packs &&
242
- has_object_kept_pack(oid, IN_CORE_KEEP_PACKS))
242
+ has_object_kept_pack(data->revs->repo, oid, IN_CORE_KEEP_PACKS))
243
return 0;
244
return 1;
245
}
revision.c
+2
-2
@@ -4103,10 +4103,10 @@ enum commit_action get_commit_action(struct rev_info *revs, struct commit *commi
4103
{
4104
if (commit->object.flags & SHOWN)
4105
return commit_ignore;
4106
- if (revs->unpacked && has_object_pack(&commit->object.oid))
4106
+ if (revs->unpacked && has_object_pack(revs->repo, &commit->object.oid))
4107
return commit_ignore;
4108
if (revs->no_kept_objects) {
4109
- if (has_object_kept_pack(&commit->object.oid,
4109
+ if (has_object_kept_pack(revs->repo, &commit->object.oid,
4110
revs->keep_pack_cache_flags))
4111
return commit_ignore;
4112
}