Skip to content

Commit 081ee4a

Browse files
committed
Merge branch 'ps/fsck-wo-the-repository' into jch
Internals of "git fsck" have been refactored to not depend on the global `the_repository` variable. Comments? * ps/fsck-wo-the-repository: builtin/fsck: stop using `the_repository` in error reporting fsck: provide repository in `struct fsck_report_object` builtin/fsck: stop using `the_repository` when marking objects builtin/fsck: stop using `the_repository` when checking packed objects builtin/fsck: stop using `the_repository` with loose objects builtin/fsck: stop using `the_repository` when checking reflogs builtin/fsck: stop using `the_repository` when checking refs builtin/fsck: stop using `the_repository` when snapshotting refs builtin/fsck: fix trivial dependence on `the_repository` fsck: stop relying on global state via `parse_oid_hex()` fsck: drop `the_repository` in `fsck_set_msg_types()` fsck: refactor interface to parse fsck options fsck: drop `the_repository` in `fsck_finish()` fsck: drop `the_repository` in `fsck_walk()`
2 parents 0a15ecc + 25e5432 commit 081ee4a

11 files changed

Lines changed: 520 additions & 363 deletions

File tree

builtin/fsck.c

Lines changed: 168 additions & 131 deletions
Large diffs are not rendered by default.

builtin/index-pack.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
933933
else
934934
die(_("invalid blob object %s"), oid_to_hex(oid));
935935
if (do_fsck_object &&
936-
fsck_object(&blob->object, (void *)data, size, &fsck_options))
936+
fsck_object(the_repository, &blob->object, (void *)data,
937+
size, &fsck_options))
937938
die(_("fsck error in packed object"));
938939
} else {
939940
struct object *obj;
@@ -952,9 +953,9 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
952953
if (!obj)
953954
die(_("invalid %s"), type_name(type));
954955
if (do_fsck_object &&
955-
fsck_object(obj, buf, size, &fsck_options))
956+
fsck_object(the_repository, obj, buf, size, &fsck_options))
956957
die(_("fsck error in packed object"));
957-
if (strict && fsck_walk(obj, NULL, &fsck_options))
958+
if (strict && fsck_walk(the_repository, obj, NULL, &fsck_options))
958959
die(_("Not all child objects of %s are reachable"), oid_to_hex(&obj->oid));
959960
if (record_outgoing_links)
960961
do_record_outgoing_links(obj);
@@ -1932,13 +1933,15 @@ int cmd_index_pack(int argc,
19321933
} else if (skip_to_optional_arg(arg, "--strict", &arg)) {
19331934
strict = 1;
19341935
do_fsck_object = 1;
1935-
fsck_set_msg_types(&fsck_options, arg);
1936+
fsck_set_msg_types(&fsck_options, arg,
1937+
the_hash_algo);
19361938
} else if (!strcmp(arg, "--check-self-contained-and-connected")) {
19371939
strict = 1;
19381940
check_self_contained_and_connected = 1;
19391941
} else if (skip_to_optional_arg(arg, "--fsck-objects", &arg)) {
19401942
do_fsck_object = 1;
1941-
fsck_set_msg_types(&fsck_options, arg);
1943+
fsck_set_msg_types(&fsck_options, arg,
1944+
the_hash_algo);
19421945
} else if (!strcmp(arg, "--verify")) {
19431946
verify = 1;
19441947
} else if (!strcmp(arg, "--verify-stat")) {
@@ -2123,7 +2126,7 @@ int cmd_index_pack(int argc,
21232126
die(_("cannot perform queued object checks outside "
21242127
"of a repository"));
21252128

2126-
if (fsck_finish(&fsck_options))
2129+
if (fsck_finish(the_repository, &fsck_options))
21272130
die(_("fsck error in pack objects"));
21282131
}
21292132

builtin/mktag.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ int cmd_mktag(int argc,
9898
fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
9999
FSCK_WARN);
100100
/* config might set fsck.extraHeaderEntry=* again */
101-
repo_config(the_repository, git_fsck_config, &fsck_options);
102-
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
103-
&tagged_oid, &tagged_type))
101+
fsck_options_parse_config(&fsck_options, the_repository);
102+
103+
if (fsck_tag_standalone(the_repository, NULL, buf.buf, buf.len,
104+
&fsck_options, &tagged_oid, &tagged_type))
104105
die(_("tag on stdin did not pass our strict fsck check"));
105106

106107
if (verify_object_in_tag(&tagged_oid, &tagged_type) < 0)

builtin/refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
9797
if (argc)
9898
usage(_("'git refs verify' takes no arguments"));
9999

100-
repo_config(the_repository, git_fsck_config, &fsck_refs_options);
100+
fsck_options_parse_config(&fsck_refs_options, the_repository);
101101
prepare_repo_settings(the_repository);
102102

103103
worktrees = get_worktrees_without_reading_head();

builtin/unpack-objects.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ static int check_object(struct object *obj, enum object_type type,
241241
obj_buf = lookup_object_buffer(obj);
242242
if (!obj_buf)
243243
die("Whoops! Cannot find object '%s'", oid_to_hex(&obj->oid));
244-
if (fsck_object(obj, obj_buf->buffer, obj_buf->size, &fsck_options))
244+
if (fsck_object(the_repository, obj, obj_buf->buffer, obj_buf->size, &fsck_options))
245245
die("fsck error in packed object");
246246
fsck_options.walk = check_object;
247-
if (fsck_walk(obj, NULL, &fsck_options))
247+
if (fsck_walk(the_repository, obj, NULL, &fsck_options))
248248
die("Error on reachable objects of %s", oid_to_hex(&obj->oid));
249249
write_cached_object(obj, obj_buf);
250250
return 0;
@@ -649,7 +649,8 @@ int cmd_unpack_objects(int argc,
649649
}
650650
if (skip_prefix(arg, "--strict=", &arg)) {
651651
strict = 1;
652-
fsck_set_msg_types(&fsck_options, arg);
652+
fsck_set_msg_types(&fsck_options, arg,
653+
the_hash_algo);
653654
continue;
654655
}
655656
if (skip_prefix(arg, "--pack_header=", &arg)) {
@@ -676,7 +677,7 @@ int cmd_unpack_objects(int argc,
676677
git_hash_final_oid(&oid, &tmp_ctx);
677678
if (strict) {
678679
write_rest();
679-
if (fsck_finish(&fsck_options))
680+
if (fsck_finish(the_repository, &fsck_options))
680681
die(_("fsck error in pack objects"));
681682
}
682683
if (!hasheq(fill(the_hash_algo->rawsz), oid.hash,

fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
12311231
if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought,
12321232
&fsck_options.gitmodules_found))
12331233
die(_("git fetch-pack: fetch failed."));
1234-
if (fsck_finish(&fsck_options))
1234+
if (fsck_finish(the_repository, &fsck_options))
12351235
die("fsck failed");
12361236

12371237
all_done:
@@ -1876,7 +1876,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
18761876
string_list_clear(&packfile_uris, 0);
18771877
strvec_clear(&index_pack_args);
18781878

1879-
if (fsck_finish(&fsck_options))
1879+
if (fsck_finish(the_repository, &fsck_options))
18801880
die("fsck failed");
18811881

18821882
if (negotiator)

0 commit comments

Comments
 (0)