fetch-pack: move fsck options into function scope
When fetching a packfile, we optionally verify received objects via the fsck subsystem. The options for those consistency checks are declared in global scope without a good reason, and they are never cleaned up. So in case the options are reused, they may accumulate more state over time. Furthermore, in subsequent changes we'll introduce a repository pointer into the structure. Obviously though, we don't have a repository available at static time, except for `the_repository`, which we don't want to use here. Refactor the code to move the options into the respective functions and properly manage their lifecycle. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Mar 23, 2026 at 16:02 UTC
17cabd369b5cb96bee9577f49247ef95d07058a7
1 file changed
+4
-1
fetch-pack.c
+4
-1
@@ -51,7 +51,6 @@ static int server_supports_filtering;
51
static int advertise_sid;
52
static struct shallow_lock shallow_lock;
53
static const char *alternate_shallow_file;
54
-static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
54
static struct strbuf fsck_msg_types = STRBUF_INIT;
55
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
56
@@ -1100,6 +1099,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
1099
struct shallow_info *si,
1100
struct string_list *pack_lockfiles)
1101
{
1102
+ struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
1103
struct repository *r = the_repository;
1104
struct ref *ref = copy_ref_list(orig_ref);
1105
struct object_id oid;
@@ -1235,6 +1235,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
1235
die("fsck failed");
1236
1237
all_done:
1238
+ fsck_options_clear(&fsck_options);
1239
if (negotiator)
1240
negotiator->release(negotiator);
1241
return ref;
@@ -1654,6 +1655,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1655
struct string_list *pack_lockfiles)
1656
{
1657
struct repository *r = the_repository;
1658
+ struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
1659
struct ref *ref = copy_ref_list(orig_ref);
1660
enum fetch_state state = FETCH_CHECK_LOCAL;
1661
struct oidset common = OIDSET_INIT;
@@ -1882,6 +1884,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1884
if (negotiator)
1885
negotiator->release(negotiator);
1886
1887
+ fsck_options_clear(&fsck_options);
1888
oidset_clear(&common);
1889
return ref;
1890
}