Skip to content

Commit cc050f0

Browse files
pks-tgitster
authored andcommitted
builtin/fsck: stop using the_repository when marking objects
We implicitly rely on `the_repository` when marking objects for connectivity. Refactor this to instead inject the repository via the callback payload. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1c5f77b commit cc050f0

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

builtin/fsck.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static int fsck_objects_error_func(struct fsck_options *o UNUSED,
124124
static struct object_array pending;
125125

126126
static int mark_object(struct object *obj, enum object_type type,
127-
void *data, struct fsck_options *options UNUSED)
127+
void *data, struct fsck_options *options)
128128
{
129129
struct object *parent = data;
130130

@@ -153,7 +153,7 @@ static int mark_object(struct object *obj, enum object_type type,
153153
return 0;
154154
obj->flags |= REACHABLE;
155155

156-
if (is_promisor_object(the_repository, &obj->oid))
156+
if (is_promisor_object(options->repo, &obj->oid))
157157
/*
158158
* Further recursion does not need to be performed on this
159159
* object since it is a promisor object (so it does not need to
@@ -162,7 +162,7 @@ static int mark_object(struct object *obj, enum object_type type,
162162
return 0;
163163

164164
if (!(obj->flags & HAS_OBJ)) {
165-
if (parent && !odb_has_object(the_repository->objects, &obj->oid,
165+
if (parent && !odb_has_object(options->repo->objects, &obj->oid,
166166
HAS_OBJECT_RECHECK_PACKED)) {
167167
printf_ln(_("broken link from %7s %s\n"
168168
" to %7s %s"),
@@ -181,7 +181,7 @@ static int mark_object(struct object *obj, enum object_type type,
181181

182182
static void mark_object_reachable(struct object *obj)
183183
{
184-
mark_object(obj, OBJ_ANY, NULL, NULL);
184+
mark_object(obj, OBJ_ANY, NULL, &fsck_walk_options);
185185
}
186186

187187
static int traverse_one_object(struct object *obj)
@@ -222,10 +222,11 @@ static int mark_used(struct object *obj, enum object_type type UNUSED,
222222

223223
static int mark_unreachable_referents(const struct object_id *oid,
224224
struct object_info *oi UNUSED,
225-
void *data UNUSED)
225+
void *data)
226226
{
227+
struct repository *repo = data;
227228
struct fsck_options options;
228-
struct object *obj = lookup_object(the_repository, oid);
229+
struct object *obj = lookup_object(data, oid);
229230

230231
if (!obj || !(obj->flags & HAS_OBJ))
231232
return 0; /* not part of our original set */
@@ -237,13 +238,13 @@ static int mark_unreachable_referents(const struct object_id *oid,
237238
* (and we want to avoid parsing blobs).
238239
*/
239240
if (obj->type == OBJ_NONE) {
240-
enum object_type type = odb_read_object_info(the_repository->objects,
241+
enum object_type type = odb_read_object_info(repo->objects,
241242
&obj->oid, NULL);
242243
if (type > 0)
243244
object_as_type(obj, type, 0);
244245
}
245246

246-
fsck_options_init(&options, the_repository, FSCK_OPTIONS_DEFAULT);
247+
fsck_options_init(&options, repo, FSCK_OPTIONS_DEFAULT);
247248
options.walk = mark_used;
248249
fsck_walk(obj, NULL, &options);
249250
if (obj->type == OBJ_TREE)
@@ -385,7 +386,7 @@ static void check_connectivity(struct repository *repo)
385386
* traversal.
386387
*/
387388
odb_for_each_object(repo->objects, NULL,
388-
mark_unreachable_referents, NULL, 0);
389+
mark_unreachable_referents, repo, 0);
389390
}
390391

391392
/* Look up all the requirements, warn about missing objects.. */
@@ -909,9 +910,10 @@ static void fsck_index(struct index_state *istate, const char *index_path,
909910

910911
static int mark_object_for_connectivity(const struct object_id *oid,
911912
struct object_info *oi UNUSED,
912-
void *cb_data UNUSED)
913+
void *cb_data)
913914
{
914-
struct object *obj = lookup_unknown_object(the_repository, oid);
915+
struct repository *repo = cb_data;
916+
struct object *obj = lookup_unknown_object(repo, oid);
915917
obj->flags |= HAS_OBJ;
916918
return 0;
917919
}
@@ -1065,7 +1067,7 @@ int cmd_fsck(int argc,
10651067

10661068
if (connectivity_only) {
10671069
odb_for_each_object(repo->objects, NULL,
1068-
mark_object_for_connectivity, NULL, 0);
1070+
mark_object_for_connectivity, repo, 0);
10691071
} else {
10701072
odb_prepare_alternates(repo->objects);
10711073
for (source = repo->objects->sources; source; source = source->next)

0 commit comments

Comments
 (0)