Skip to content

Commit c15087d

Browse files
avargitster
authored andcommitted
fsck.c: move gitmodules_{found,done} into fsck_options
Move the gitmodules_{found,done} static variables added in 159e7b0 (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 5476e1e (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53692df commit c15087d

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

fetch-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
998998

999999
oidset_iter_init(gitmodules_oids, &iter);
10001000
while ((oid = oidset_iter_next(&iter)))
1001-
register_found_gitmodules(oid);
1001+
register_found_gitmodules(&fo, oid);
10021002
if (fsck_finish(&fo))
10031003
die("fsck failed");
10041004
}

fsck.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#include "credential.h"
2020
#include "help.h"
2121

22-
static struct oidset gitmodules_found = OIDSET_INIT;
23-
static struct oidset gitmodules_done = OIDSET_INIT;
24-
2522
#define STR(x) #x
2623
#define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
2724
static struct {
@@ -606,7 +603,7 @@ static int fsck_tree(const struct object_id *oid,
606603

607604
if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
608605
if (!S_ISLNK(mode))
609-
oidset_insert(&gitmodules_found, oid);
606+
oidset_insert(&options->gitmodules_found, oid);
610607
else
611608
retval += report(options,
612609
oid, OBJ_TREE,
@@ -620,7 +617,7 @@ static int fsck_tree(const struct object_id *oid,
620617
has_dotgit |= is_ntfs_dotgit(backslash);
621618
if (is_ntfs_dotgitmodules(backslash)) {
622619
if (!S_ISLNK(mode))
623-
oidset_insert(&gitmodules_found, oid);
620+
oidset_insert(&options->gitmodules_found, oid);
624621
else
625622
retval += report(options, oid, OBJ_TREE,
626623
FSCK_MSG_GITMODULES_SYMLINK,
@@ -1132,9 +1129,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,
11321129
struct fsck_gitmodules_data data;
11331130
struct config_options config_opts = { 0 };
11341131

1135-
if (!oidset_contains(&gitmodules_found, oid))
1132+
if (!oidset_contains(&options->gitmodules_found, oid))
11361133
return 0;
1137-
oidset_insert(&gitmodules_done, oid);
1134+
oidset_insert(&options->gitmodules_done, oid);
11381135

11391136
if (object_on_skiplist(options, oid))
11401137
return 0;
@@ -1199,9 +1196,9 @@ int fsck_error_function(struct fsck_options *o,
11991196
return 1;
12001197
}
12011198

1202-
void register_found_gitmodules(const struct object_id *oid)
1199+
void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
12031200
{
1204-
oidset_insert(&gitmodules_found, oid);
1201+
oidset_insert(&options->gitmodules_found, oid);
12051202
}
12061203

12071204
int fsck_finish(struct fsck_options *options)
@@ -1210,13 +1207,13 @@ int fsck_finish(struct fsck_options *options)
12101207
struct oidset_iter iter;
12111208
const struct object_id *oid;
12121209

1213-
oidset_iter_init(&gitmodules_found, &iter);
1210+
oidset_iter_init(&options->gitmodules_found, &iter);
12141211
while ((oid = oidset_iter_next(&iter))) {
12151212
enum object_type type;
12161213
unsigned long size;
12171214
char *buf;
12181215

1219-
if (oidset_contains(&gitmodules_done, oid))
1216+
if (oidset_contains(&options->gitmodules_done, oid))
12201217
continue;
12211218

12221219
buf = read_object_file(oid, &type, &size);
@@ -1241,8 +1238,8 @@ int fsck_finish(struct fsck_options *options)
12411238
}
12421239

12431240

1244-
oidset_clear(&gitmodules_found);
1245-
oidset_clear(&gitmodules_done);
1241+
oidset_clear(&options->gitmodules_found);
1242+
oidset_clear(&options->gitmodules_done);
12461243
return ret;
12471244
}
12481245

fsck.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,21 @@ struct fsck_options {
118118
unsigned strict:1;
119119
enum fsck_msg_type *msg_type;
120120
struct oidset skiplist;
121+
struct oidset gitmodules_found;
122+
struct oidset gitmodules_done;
121123
kh_oid_map_t *object_names;
122124
};
123125

124126
#define FSCK_OPTIONS_DEFAULT { \
125127
.skiplist = OIDSET_INIT, \
128+
.gitmodules_found = OIDSET_INIT, \
129+
.gitmodules_done = OIDSET_INIT, \
126130
.error_func = fsck_error_function \
127131
}
128132
#define FSCK_OPTIONS_STRICT { \
129133
.strict = 1, \
134+
.gitmodules_found = OIDSET_INIT, \
135+
.gitmodules_done = OIDSET_INIT, \
130136
.error_func = fsck_error_function, \
131137
}
132138

@@ -146,7 +152,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
146152
int fsck_object(struct object *obj, void *data, unsigned long size,
147153
struct fsck_options *options);
148154

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);
150157

151158
/*
152159
* fsck a tag, and pass info about it back to the caller. This is

0 commit comments

Comments
 (0)