fsck.c: move gitmodules_{found,done} into fsck_options

Move the gitmodules_{found,done} static variables added in 159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the fsck_options struct. It makes sense to keep all the context in the same place. This requires changing the recently added register_found_gitmodules() function added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to take fsck_options. That function will be removed in a subsequent commit, but as it'll require the new gitmodules_found attribute of "fsck_options" we need this intermediate step first. An earlier version of this patch removed the small amount of duplication we now have between FSCK_OPTIONS_{DEFAULT,STRICT} with a FSCK_OPTIONS_COMMON macro. I don't think such de-duplication is worth it for this amount of copy/pasting. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Mar 28, 2021 at 15:15 UTC c15087d17bd3c146696bfe6abf86322d79bf61ca
3 files changed +19 -15
fetch-pack.c
+1 -1
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
998
999 oidset_iter_init(gitmodules_oids, &iter);
1000 while ((oid = oidset_iter_next(&iter)))
1001 - register_found_gitmodules(oid);
1001 + register_found_gitmodules(&fo, oid);
1002 if (fsck_finish(&fo))
1003 die("fsck failed");
1004 }
fsck.c
+10 -13
@@ -19,9 +19,6 @@
19 #include "credential.h"
20 #include "help.h"
21
22 -static struct oidset gitmodules_found = OIDSET_INIT;
23 -static struct oidset gitmodules_done = OIDSET_INIT;
24 -
22 #define STR(x) #x
23 #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
24 static struct {
@@ -606,7 +603,7 @@ static int fsck_tree(const struct object_id *oid,
603
604 if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
605 if (!S_ISLNK(mode))
609 - oidset_insert(&gitmodules_found, oid);
606 + oidset_insert(&options->gitmodules_found, oid);
607 else
608 retval += report(options,
609 oid, OBJ_TREE,
@@ -620,7 +617,7 @@ static int fsck_tree(const struct object_id *oid,
617 has_dotgit |= is_ntfs_dotgit(backslash);
618 if (is_ntfs_dotgitmodules(backslash)) {
619 if (!S_ISLNK(mode))
623 - oidset_insert(&gitmodules_found, oid);
620 + oidset_insert(&options->gitmodules_found, oid);
621 else
622 retval += report(options, oid, OBJ_TREE,
623 FSCK_MSG_GITMODULES_SYMLINK,
@@ -1132,9 +1129,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,
1129 struct fsck_gitmodules_data data;
1130 struct config_options config_opts = { 0 };
1131
1135 - if (!oidset_contains(&gitmodules_found, oid))
1132 + if (!oidset_contains(&options->gitmodules_found, oid))
1133 return 0;
1137 - oidset_insert(&gitmodules_done, oid);
1134 + oidset_insert(&options->gitmodules_done, oid);
1135
1136 if (object_on_skiplist(options, oid))
1137 return 0;
@@ -1199,9 +1196,9 @@ int fsck_error_function(struct fsck_options *o,
1196 return 1;
1197 }
1198
1202 -void register_found_gitmodules(const struct object_id *oid)
1199 +void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
1200 {
1204 - oidset_insert(&gitmodules_found, oid);
1201 + oidset_insert(&options->gitmodules_found, oid);
1202 }
1203
1204 int fsck_finish(struct fsck_options *options)
@@ -1210,13 +1207,13 @@ int fsck_finish(struct fsck_options *options)
1207 struct oidset_iter iter;
1208 const struct object_id *oid;
1209
1213 - oidset_iter_init(&gitmodules_found, &iter);
1210 + oidset_iter_init(&options->gitmodules_found, &iter);
1211 while ((oid = oidset_iter_next(&iter))) {
1212 enum object_type type;
1213 unsigned long size;
1214 char *buf;
1215
1219 - if (oidset_contains(&gitmodules_done, oid))
1216 + if (oidset_contains(&options->gitmodules_done, oid))
1217 continue;
1218
1219 buf = read_object_file(oid, &type, &size);
@@ -1241,8 +1238,8 @@ int fsck_finish(struct fsck_options *options)
1238 }
1239
1240
1244 - oidset_clear(&gitmodules_found);
1245 - oidset_clear(&gitmodules_done);
1241 + oidset_clear(&options->gitmodules_found);
1242 + oidset_clear(&options->gitmodules_done);
1243 return ret;
1244 }
1245
fsck.h
+8 -1
@@ -118,15 +118,21 @@ struct fsck_options {
118 unsigned strict:1;
119 enum fsck_msg_type *msg_type;
120 struct oidset skiplist;
121 + struct oidset gitmodules_found;
122 + struct oidset gitmodules_done;
123 kh_oid_map_t *object_names;
124 };
125
126 #define FSCK_OPTIONS_DEFAULT { \
127 .skiplist = OIDSET_INIT, \
128 + .gitmodules_found = OIDSET_INIT, \
129 + .gitmodules_done = OIDSET_INIT, \
130 .error_func = fsck_error_function \
131 }
132 #define FSCK_OPTIONS_STRICT { \
133 .strict = 1, \
134 + .gitmodules_found = OIDSET_INIT, \
135 + .gitmodules_done = OIDSET_INIT, \
136 .error_func = fsck_error_function, \
137 }
138
@@ -146,7 +152,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
152 int fsck_object(struct object *obj, void *data, unsigned long size,
153 struct fsck_options *options);
154
149 -void register_found_gitmodules(const struct object_id *oid);
155 +void register_found_gitmodules(struct fsck_options *options,
156 + const struct object_id *oid);
157
158 /*
159 * fsck a tag, and pass info about it back to the caller. This is