Skip to content

Commit cc656f4

Browse files
KarthikNayakgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 873b005 commit cc656f4

File tree

11 files changed

+21
-17
lines changed

11 files changed

+21
-17
lines changed

builtin/count-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int count_loose(const struct object_id *oid, const char *path,
6767
else {
6868
loose_size += on_disk_bytes(st);
6969
loose++;
70-
if (verbose && has_object_pack(oid))
70+
if (verbose && has_object_pack(the_repository, oid))
7171
packed_loose++;
7272
}
7373
return 0;

builtin/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static void check_reachable_object(struct object *obj)
272272
if (!(obj->flags & HAS_OBJ)) {
273273
if (is_promisor_object(&obj->oid))
274274
return;
275-
if (has_object_pack(&obj->oid))
275+
if (has_object_pack(the_repository, &obj->oid))
276276
return; /* it is in pack - forget about it */
277277
printf_ln(_("missing %s %s"),
278278
printable_type(&obj->oid, obj->type),

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ static int want_found_object(const struct object_id *oid, int exclude,
15291529
return 0;
15301530
if (ignore_packed_keep_in_core && p->pack_keep_in_core)
15311531
return 0;
1532-
if (has_object_kept_pack(oid, flags))
1532+
if (has_object_kept_pack(p->repo, oid, flags))
15331533
return 0;
15341534
}
15351535

@@ -3627,7 +3627,7 @@ static void show_cruft_commit(struct commit *commit, void *data)
36273627

36283628
static int cruft_include_check_obj(struct object *obj, void *data UNUSED)
36293629
{
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);
36313631
}
36323632

36333633
static int cruft_include_check(struct commit *commit, void *data)

diff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4041,7 +4041,8 @@ static int reuse_worktree_file(struct index_state *istate,
40414041
* objects however would tend to be slower as they need
40424042
* to be individually opened and inflated.
40434043
*/
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))
40454046
return 0;
40464047

40474048
/*

list-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ static void show_object(struct traversal_context *ctx,
4141
{
4242
if (!ctx->show_object)
4343
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))
4546
return;
4647

4748
ctx->show_object(object, name, ctx->show_data);

pack-bitmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ static void filter_packed_objects_from_bitmap(struct bitmap_index *bitmap_git,
18891889
bitmap_unset(result, i);
18901890

18911891
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))
18931893
bitmap_unset(result, objects_nr + i);
18941894
}
18951895
}

packfile.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,16 +2143,17 @@ int find_kept_pack_entry(struct repository *r,
21432143
return 0;
21442144
}
21452145

2146-
int has_object_pack(const struct object_id *oid)
2146+
int has_object_pack(struct repository *r, const struct object_id *oid)
21472147
{
21482148
struct pack_entry e;
2149-
return find_pack_entry(the_repository, oid, &e);
2149+
return find_pack_entry(r, oid, &e);
21502150
}
21512151

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)
21532154
{
21542155
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);
21562157
}
21572158

21582159
int for_each_object_in_pack(struct packed_git *p,

packfile.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ const struct packed_git *has_packed_and_bad(struct repository *, const struct ob
193193
int find_pack_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e);
194194
int find_kept_pack_entry(struct repository *r, const struct object_id *oid, unsigned flags, struct pack_entry *e);
195195

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);
198199

199200
/*
200201
* Return 1 if an object in a promisor packfile is or refers to the given

prune-packed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static int prune_object(const struct object_id *oid, const char *path,
2424
{
2525
int *opts = data;
2626

27-
if (!has_object_pack(oid))
27+
if (!has_object_pack(the_repository, oid))
2828
return 0;
2929

3030
if (*opts & PRUNE_PACKED_DRY_RUN)

reachable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static int want_recent_object(struct recent_data *data,
239239
const struct object_id *oid)
240240
{
241241
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))
243243
return 0;
244244
return 1;
245245
}

0 commit comments

Comments
 (0)