Skip to content

Commit da3ead3

Browse files
pks-tgitster
authored andcommitted
builtin/fsck: fix trivial dependence on the_repository
We have a bunch of sites in "builtin/fsck.c" that depend on `the_repository` even though we already have a repository available, or in cases where we can trivially make it available. Refactor such sites to use the context-provided repository instead. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent fe5f16e commit da3ead3

1 file changed

Lines changed: 49 additions & 49 deletions

File tree

builtin/fsck.c

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ static int traverse_one_object(struct object *obj)
195195
return result;
196196
}
197197

198-
static int traverse_reachable(void)
198+
static int traverse_reachable(struct repository *repo)
199199
{
200200
struct progress *progress = NULL;
201201
unsigned int nr = 0;
202202
int result = 0;
203203
if (show_progress)
204-
progress = start_delayed_progress(the_repository,
204+
progress = start_delayed_progress(repo,
205205
_("Checking connectivity"), 0);
206206
while (pending.nr) {
207207
result |= traverse_one_object(object_array_pop(&pending));
@@ -255,17 +255,17 @@ static int mark_unreachable_referents(const struct object_id *oid,
255255
/*
256256
* Check a single reachable object
257257
*/
258-
static void check_reachable_object(struct object *obj)
258+
static void check_reachable_object(struct repository *repo, struct object *obj)
259259
{
260260
/*
261261
* We obviously want the object to be parsed,
262262
* except if it was in a pack-file and we didn't
263263
* do a full fsck
264264
*/
265265
if (!(obj->flags & HAS_OBJ)) {
266-
if (is_promisor_object(the_repository, &obj->oid))
266+
if (is_promisor_object(repo, &obj->oid))
267267
return;
268-
if (has_object_pack(the_repository, &obj->oid))
268+
if (has_object_pack(repo, &obj->oid))
269269
return; /* it is in pack - forget about it */
270270
printf_ln(_("missing %s %s"),
271271
printable_type(&obj->oid, obj->type),
@@ -278,7 +278,7 @@ static void check_reachable_object(struct object *obj)
278278
/*
279279
* Check a single unreachable object
280280
*/
281-
static void check_unreachable_object(struct object *obj)
281+
static void check_unreachable_object(struct repository *repo, struct object *obj)
282282
{
283283
/*
284284
* Missing unreachable object? Ignore it. It's not like
@@ -318,19 +318,19 @@ static void check_unreachable_object(struct object *obj)
318318
printable_type(&obj->oid, obj->type),
319319
describe_object(&obj->oid));
320320
if (write_lost_and_found) {
321-
char *filename = repo_git_path(the_repository, "lost-found/%s/%s",
321+
char *filename = repo_git_path(repo, "lost-found/%s/%s",
322322
obj->type == OBJ_COMMIT ? "commit" : "other",
323323
describe_object(&obj->oid));
324324
FILE *f;
325325

326-
if (safe_create_leading_directories_const(the_repository, filename)) {
326+
if (safe_create_leading_directories_const(repo, filename)) {
327327
error(_("could not create lost-found"));
328328
free(filename);
329329
return;
330330
}
331331
f = xfopen(filename, "w");
332332
if (obj->type == OBJ_BLOB) {
333-
if (odb_stream_blob_to_fd(the_repository->objects, fileno(f),
333+
if (odb_stream_blob_to_fd(repo->objects, fileno(f),
334334
&obj->oid, NULL, 1))
335335
die_errno(_("could not write '%s'"), filename);
336336
} else
@@ -350,23 +350,23 @@ static void check_unreachable_object(struct object *obj)
350350
*/
351351
}
352352

353-
static void check_object(struct object *obj)
353+
static void check_object(struct repository *repo, struct object *obj)
354354
{
355355
if (verbose)
356356
fprintf_ln(stderr, _("Checking %s"), describe_object(&obj->oid));
357357

358358
if (obj->flags & REACHABLE)
359-
check_reachable_object(obj);
359+
check_reachable_object(repo, obj);
360360
else
361-
check_unreachable_object(obj);
361+
check_unreachable_object(repo, obj);
362362
}
363363

364-
static void check_connectivity(void)
364+
static void check_connectivity(struct repository *repo)
365365
{
366366
int i, max;
367367

368368
/* Traverse the pending reachable objects */
369-
traverse_reachable();
369+
traverse_reachable(repo);
370370

371371
/*
372372
* With --connectivity-only, we won't have actually opened and marked
@@ -384,20 +384,20 @@ static void check_connectivity(void)
384384
* and ignore any that weren't present in our earlier
385385
* traversal.
386386
*/
387-
odb_for_each_object(the_repository->objects, NULL,
387+
odb_for_each_object(repo->objects, NULL,
388388
mark_unreachable_referents, NULL, 0);
389389
}
390390

391391
/* Look up all the requirements, warn about missing objects.. */
392-
max = get_max_object_index(the_repository);
392+
max = get_max_object_index(repo);
393393
if (verbose)
394394
fprintf_ln(stderr, _("Checking connectivity (%d objects)"), max);
395395

396396
for (i = 0; i < max; i++) {
397-
struct object *obj = get_indexed_object(the_repository, i);
397+
struct object *obj = get_indexed_object(repo, i);
398398

399399
if (obj)
400-
check_object(obj);
400+
check_object(repo, obj);
401401
}
402402
}
403403

@@ -770,7 +770,7 @@ static int fsck_subdir(unsigned int nr, const char *path UNUSED, void *data)
770770
return 0;
771771
}
772772

773-
static void fsck_source(struct odb_source *source)
773+
static void fsck_source(struct repository *repo, struct odb_source *source)
774774
{
775775
struct progress *progress = NULL;
776776
struct for_each_loose_cb cb_data = {
@@ -781,7 +781,7 @@ static void fsck_source(struct odb_source *source)
781781
fprintf_ln(stderr, _("Checking object directory"));
782782

783783
if (show_progress)
784-
progress = start_progress(the_repository,
784+
progress = start_progress(repo,
785785
_("Checking object directories"), 256);
786786

787787
for_each_loose_file_in_source(source, fsck_loose,
@@ -790,7 +790,7 @@ static void fsck_source(struct odb_source *source)
790790
stop_progress(&progress);
791791
}
792792

793-
static int fsck_cache_tree(struct cache_tree *it, const char *index_path)
793+
static int fsck_cache_tree(struct repository *repo, struct cache_tree *it, const char *index_path)
794794
{
795795
int i;
796796
int err = 0;
@@ -799,7 +799,7 @@ static int fsck_cache_tree(struct cache_tree *it, const char *index_path)
799799
fprintf_ln(stderr, _("Checking cache tree of %s"), index_path);
800800

801801
if (0 <= it->entry_count) {
802-
struct object *obj = parse_object(the_repository, &it->oid);
802+
struct object *obj = parse_object(repo, &it->oid);
803803
if (!obj) {
804804
error(_("%s: invalid sha1 pointer in cache-tree of %s"),
805805
oid_to_hex(&it->oid), index_path);
@@ -813,7 +813,7 @@ static int fsck_cache_tree(struct cache_tree *it, const char *index_path)
813813
err |= objerror(obj, _("non-tree in cache-tree"));
814814
}
815815
for (i = 0; i < it->subtree_nr; i++)
816-
err |= fsck_cache_tree(it->down[i]->cache_tree, index_path);
816+
err |= fsck_cache_tree(repo, it->down[i]->cache_tree, index_path);
817817
return err;
818818
}
819819

@@ -839,7 +839,7 @@ static int fsck_resolve_undo(struct index_state *istate,
839839
if (!ru->mode[i] || !S_ISREG(ru->mode[i]))
840840
continue;
841841

842-
obj = parse_object(the_repository, &ru->oid[i]);
842+
obj = parse_object(istate->repo, &ru->oid[i]);
843843
if (!obj) {
844844
error(_("%s: invalid sha1 pointer in resolve-undo of %s"),
845845
oid_to_hex(&ru->oid[i]),
@@ -871,7 +871,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
871871
mode = istate->cache[i]->ce_mode;
872872
if (S_ISGITLINK(mode))
873873
continue;
874-
blob = lookup_blob(the_repository,
874+
blob = lookup_blob(istate->repo,
875875
&istate->cache[i]->oid);
876876
if (!blob)
877877
continue;
@@ -884,7 +884,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
884884
mark_object_reachable(obj);
885885
}
886886
if (istate->cache_tree)
887-
fsck_cache_tree(istate->cache_tree, index_path);
887+
fsck_cache_tree(istate->repo, istate->cache_tree, index_path);
888888
fsck_resolve_undo(istate, index_path);
889889
}
890890

@@ -907,7 +907,7 @@ static int check_pack_rev_indexes(struct repository *r, int show_progress)
907907
if (show_progress) {
908908
repo_for_each_pack(r, p)
909909
pack_count++;
910-
progress = start_delayed_progress(the_repository,
910+
progress = start_delayed_progress(r,
911911
"Verifying reverse pack-indexes", pack_count);
912912
pack_count = 0;
913913
}
@@ -1027,11 +1027,11 @@ int cmd_fsck(int argc,
10271027
if (name_objects)
10281028
fsck_enable_object_names(&fsck_walk_options);
10291029

1030-
repo_config(the_repository, git_fsck_config, &fsck_obj_options);
1031-
prepare_repo_settings(the_repository);
1030+
repo_config(repo, git_fsck_config, &fsck_obj_options);
1031+
prepare_repo_settings(repo);
10321032

10331033
if (check_references)
1034-
fsck_refs(the_repository);
1034+
fsck_refs(repo);
10351035

10361036
/*
10371037
* Take a snapshot of the refs before walking objects to avoid looking
@@ -1042,35 +1042,35 @@ int cmd_fsck(int argc,
10421042
snapshot_refs(&snap, argc, argv);
10431043

10441044
/* Ensure we get a "fresh" view of the odb */
1045-
odb_reprepare(the_repository->objects);
1045+
odb_reprepare(repo->objects);
10461046

10471047
if (connectivity_only) {
1048-
odb_for_each_object(the_repository->objects, NULL,
1048+
odb_for_each_object(repo->objects, NULL,
10491049
mark_object_for_connectivity, NULL, 0);
10501050
} else {
1051-
odb_prepare_alternates(the_repository->objects);
1052-
for (source = the_repository->objects->sources; source; source = source->next)
1053-
fsck_source(source);
1051+
odb_prepare_alternates(repo->objects);
1052+
for (source = repo->objects->sources; source; source = source->next)
1053+
fsck_source(repo, source);
10541054

10551055
if (check_full) {
10561056
struct packed_git *p;
10571057
uint32_t total = 0, count = 0;
10581058
struct progress *progress = NULL;
10591059

10601060
if (show_progress) {
1061-
repo_for_each_pack(the_repository, p) {
1061+
repo_for_each_pack(repo, p) {
10621062
if (open_pack_index(p))
10631063
continue;
10641064
total += p->num_objects;
10651065
}
10661066

1067-
progress = start_progress(the_repository,
1067+
progress = start_progress(repo,
10681068
_("Checking objects"), total);
10691069
}
10701070

1071-
repo_for_each_pack(the_repository, p) {
1071+
repo_for_each_pack(repo, p) {
10721072
/* verify gives error messages itself */
1073-
if (verify_pack(the_repository,
1073+
if (verify_pack(repo,
10741074
p, fsck_obj_buffer,
10751075
progress, count))
10761076
errors_found |= ERROR_PACK;
@@ -1104,7 +1104,7 @@ int cmd_fsck(int argc,
11041104
for (p = worktrees; *p; p++) {
11051105
struct worktree *wt = *p;
11061106
struct index_state istate =
1107-
INDEX_STATE_INIT(the_repository);
1107+
INDEX_STATE_INIT(repo);
11081108
char *path, *wt_gitdir;
11091109

11101110
/*
@@ -1125,17 +1125,17 @@ int cmd_fsck(int argc,
11251125
free_worktrees(worktrees);
11261126
}
11271127

1128-
errors_found |= check_pack_rev_indexes(the_repository, show_progress);
1129-
if (verify_bitmap_files(the_repository))
1128+
errors_found |= check_pack_rev_indexes(repo, show_progress);
1129+
if (verify_bitmap_files(repo))
11301130
errors_found |= ERROR_BITMAP;
11311131

1132-
check_connectivity();
1132+
check_connectivity(repo);
11331133

1134-
if (the_repository->settings.core_commit_graph) {
1134+
if (repo->settings.core_commit_graph) {
11351135
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
11361136

1137-
odb_prepare_alternates(the_repository->objects);
1138-
for (source = the_repository->objects->sources; source; source = source->next) {
1137+
odb_prepare_alternates(repo->objects);
1138+
for (source = repo->objects->sources; source; source = source->next) {
11391139
child_process_init(&commit_graph_verify);
11401140
commit_graph_verify.git_cmd = 1;
11411141
strvec_pushl(&commit_graph_verify.args, "commit-graph",
@@ -1149,11 +1149,11 @@ int cmd_fsck(int argc,
11491149
}
11501150
}
11511151

1152-
if (the_repository->settings.core_multi_pack_index) {
1152+
if (repo->settings.core_multi_pack_index) {
11531153
struct child_process midx_verify = CHILD_PROCESS_INIT;
11541154

1155-
odb_prepare_alternates(the_repository->objects);
1156-
for (source = the_repository->objects->sources; source; source = source->next) {
1155+
odb_prepare_alternates(repo->objects);
1156+
for (source = repo->objects->sources; source; source = source->next) {
11571157
child_process_init(&midx_verify);
11581158
midx_verify.git_cmd = 1;
11591159
strvec_pushl(&midx_verify.args, "multi-pack-index",

0 commit comments

Comments
 (0)