Skip to content

Commit 5644419

Browse files
committed
Merge branch 'ab/fsck-api-cleanup'
Fsck API clean-up. * ab/fsck-api-cleanup: fetch-pack: use new fsck API to printing dangling submodules fetch-pack: use file-scope static struct for fsck_options fetch-pack: don't needlessly copy fsck_options fsck.c: move gitmodules_{found,done} into fsck_options fsck.c: add an fsck_set_msg_type() API that takes enums fsck.c: pass along the fsck_msg_id in the fsck_error callback fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h fsck.c: give "FOREACH_MSG_ID" a more specific name fsck.c: undefine temporary STR macro after use fsck.c: call parse_msg_type() early in fsck_set_msg_type() fsck.h: re-order and re-assign "enum fsck_msg_type" fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" fsck.c: rename remaining fsck_msg_id "id" to "msg_id" fsck.c: remove (mostly) redundant append_msg_id() function fsck.c: rename variables in fsck_set_msg_type() for less confusion fsck.h: use "enum object_type" instead of "int" fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} fsck.c: refactor and rename common config callback
2 parents d637a26 + 3745e26 commit 5644419

File tree

7 files changed

+210
-216
lines changed

7 files changed

+210
-216
lines changed

builtin/fsck.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ static const char *printable_type(const struct object_id *oid,
7171
return ret;
7272
}
7373

74-
static int fsck_config(const char *var, const char *value, void *cb)
75-
{
76-
return fsck_config_internal(var, value, cb, &fsck_obj_options);
77-
}
78-
7974
static int objerror(struct object *obj, const char *err)
8075
{
8176
errors_found |= ERROR_OBJECT;
@@ -89,7 +84,9 @@ static int objerror(struct object *obj, const char *err)
8984
static int fsck_error_func(struct fsck_options *o,
9085
const struct object_id *oid,
9186
enum object_type object_type,
92-
int msg_type, const char *message)
87+
enum fsck_msg_type msg_type,
88+
enum fsck_msg_id msg_id,
89+
const char *message)
9390
{
9491
switch (msg_type) {
9592
case FSCK_WARN:
@@ -197,7 +194,8 @@ static int traverse_reachable(void)
197194
return !!result;
198195
}
199196

200-
static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options)
197+
static int mark_used(struct object *obj, enum object_type object_type,
198+
void *data, struct fsck_options *options)
201199
{
202200
if (!obj)
203201
return 1;
@@ -803,7 +801,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
803801
if (name_objects)
804802
fsck_enable_object_names(&fsck_walk_options);
805803

806-
git_config(fsck_config, NULL);
804+
git_config(git_fsck_config, &fsck_obj_options);
807805

808806
if (connectivity_only) {
809807
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);

builtin/index-pack.c

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static int nr_threads;
120120
static int from_stdin;
121121
static int strict;
122122
static int do_fsck_object;
123-
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
123+
static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
124124
static int verbose;
125125
static int show_resolving_progress;
126126
static int show_stat;
@@ -212,7 +212,8 @@ static void cleanup_thread(void)
212212
free(thread_data);
213213
}
214214

215-
static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options)
215+
static int mark_link(struct object *obj, enum object_type type,
216+
void *data, struct fsck_options *options)
216217
{
217218
if (!obj)
218219
return -1;
@@ -1712,22 +1713,6 @@ static void show_pack_info(int stat_only)
17121713
}
17131714
}
17141715

1715-
static int print_dangling_gitmodules(struct fsck_options *o,
1716-
const struct object_id *oid,
1717-
enum object_type object_type,
1718-
int msg_type, const char *message)
1719-
{
1720-
/*
1721-
* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
1722-
* instead of relying on this string check.
1723-
*/
1724-
if (starts_with(message, "gitmodulesMissing")) {
1725-
printf("%s\n", oid_to_hex(oid));
1726-
return 0;
1727-
}
1728-
return fsck_error_function(o, oid, object_type, msg_type, message);
1729-
}
1730-
17311716
int cmd_index_pack(int argc, const char **argv, const char *prefix)
17321717
{
17331718
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
@@ -1948,13 +1933,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
19481933
else
19491934
close(input_fd);
19501935

1951-
if (do_fsck_object) {
1952-
struct fsck_options fo = fsck_options;
1953-
1954-
fo.error_func = print_dangling_gitmodules;
1955-
if (fsck_finish(&fo))
1956-
die(_("fsck error in pack objects"));
1957-
}
1936+
if (do_fsck_object && fsck_finish(&fsck_options))
1937+
die(_("fsck error in pack objects"));
19581938

19591939
free(objects);
19601940
strbuf_release(&index_name_buf);

builtin/mktag.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ static int option_strict = 1;
1414

1515
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
1616

17-
static int mktag_config(const char *var, const char *value, void *cb)
18-
{
19-
return fsck_config_internal(var, value, cb, &fsck_options);
20-
}
21-
2217
static int mktag_fsck_error_func(struct fsck_options *o,
2318
const struct object_id *oid,
2419
enum object_type object_type,
25-
int msg_type, const char *message)
20+
enum fsck_msg_type msg_type,
21+
enum fsck_msg_id msg_id,
22+
const char *message)
2623
{
2724
switch (msg_type) {
2825
case FSCK_WARN:
@@ -91,9 +88,10 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
9188
die_errno(_("could not read from stdin"));
9289

9390
fsck_options.error_func = mktag_fsck_error_func;
94-
fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
91+
fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
92+
FSCK_WARN);
9593
/* config might set fsck.extraHeaderEntry=* again */
96-
git_config(mktag_config, NULL);
94+
git_config(git_fsck_config, &fsck_options);
9795
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
9896
&tagged_oid, &tagged_type))
9997
die(_("tag on stdin did not pass our strict fsck check"));

builtin/unpack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
187187
* that have reachability requirements and calls this function.
188188
* Verify its reachability and validity recursively and write it out.
189189
*/
190-
static int check_object(struct object *obj, int type, void *data, struct fsck_options *options)
190+
static int check_object(struct object *obj, enum object_type type,
191+
void *data, struct fsck_options *options)
191192
{
192193
struct obj_buffer *obj_buf;
193194

fetch-pack.c

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static int server_supports_filtering;
3838
static int advertise_sid;
3939
static struct shallow_lock shallow_lock;
4040
static const char *alternate_shallow_file;
41+
static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
4142
static struct strbuf fsck_msg_types = STRBUF_INIT;
4243
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
4344

@@ -987,22 +988,6 @@ static int cmp_ref_by_name(const void *a_, const void *b_)
987988
return strcmp(a->name, b->name);
988989
}
989990

990-
static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
991-
{
992-
struct oidset_iter iter;
993-
const struct object_id *oid;
994-
struct fsck_options fo = FSCK_OPTIONS_STRICT;
995-
996-
if (!oidset_size(gitmodules_oids))
997-
return;
998-
999-
oidset_iter_init(gitmodules_oids, &iter);
1000-
while ((oid = oidset_iter_next(&iter)))
1001-
register_found_gitmodules(oid);
1002-
if (fsck_finish(&fo))
1003-
die("fsck failed");
1004-
}
1005-
1006991
static struct ref *do_fetch_pack(struct fetch_pack_args *args,
1007992
int fd[2],
1008993
const struct ref *orig_ref,
@@ -1017,7 +1002,6 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
10171002
int agent_len;
10181003
struct fetch_negotiator negotiator_alloc;
10191004
struct fetch_negotiator *negotiator;
1020-
struct oidset gitmodules_oids = OIDSET_INIT;
10211005

10221006
negotiator = &negotiator_alloc;
10231007
fetch_negotiator_init(r, negotiator);
@@ -1134,9 +1118,10 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
11341118
else
11351119
alternate_shallow_file = NULL;
11361120
if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought,
1137-
&gitmodules_oids))
1121+
&fsck_options.gitmodules_found))
11381122
die(_("git fetch-pack: fetch failed."));
1139-
fsck_gitmodules_oids(&gitmodules_oids);
1123+
if (fsck_finish(&fsck_options))
1124+
die("fsck failed");
11401125

11411126
all_done:
11421127
if (negotiator)
@@ -1587,7 +1572,6 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
15871572
struct string_list packfile_uris = STRING_LIST_INIT_DUP;
15881573
int i;
15891574
struct strvec index_pack_args = STRVEC_INIT;
1590-
struct oidset gitmodules_oids = OIDSET_INIT;
15911575

15921576
negotiator = &negotiator_alloc;
15931577
fetch_negotiator_init(r, negotiator);
@@ -1678,7 +1662,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
16781662
process_section_header(&reader, "packfile", 0);
16791663
if (get_pack(args, fd, pack_lockfiles,
16801664
packfile_uris.nr ? &index_pack_args : NULL,
1681-
sought, nr_sought, &gitmodules_oids))
1665+
sought, nr_sought, &fsck_options.gitmodules_found))
16821666
die(_("git fetch-pack: fetch failed."));
16831667
do_check_stateless_delimiter(args, &reader);
16841668

@@ -1721,7 +1705,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
17211705

17221706
packname[the_hash_algo->hexsz] = '\0';
17231707

1724-
parse_gitmodules_oids(cmd.out, &gitmodules_oids);
1708+
parse_gitmodules_oids(cmd.out, &fsck_options.gitmodules_found);
17251709

17261710
close(cmd.out);
17271711

@@ -1742,7 +1726,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
17421726
string_list_clear(&packfile_uris, 0);
17431727
strvec_clear(&index_pack_args);
17441728

1745-
fsck_gitmodules_oids(&gitmodules_oids);
1729+
if (fsck_finish(&fsck_options))
1730+
die("fsck failed");
17461731

17471732
if (negotiator)
17481733
negotiator->release(negotiator);

0 commit comments

Comments
 (0)