Skip to content

Commit 3745e26

Browse files
avargitster
authored andcommitted
fetch-pack: use new fsck API to printing dangling submodules
Refactor the check added in 5476e1e (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to make use of us now passing the "msg_id" to the user defined "error_func". We can now compare against the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated message. Let's also replace register_found_gitmodules() with directly manipulating the "gitmodules_found" member. A recent commit moved it into "fsck_options" so we could do this here. I'm sticking this callback in fsck.c. Perhaps in the future we'd like to accumulate such callbacks into another file (maybe fsck-cb.c, similar to parse-options-cb.c?), but while we've got just the one let's just put it into fsck.c. A better alternative in this case would be some library some more obvious library shared by fetch-pack.c ad builtin/index-pack.c, but there isn't such a thing. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c96e184 commit 3745e26

File tree

4 files changed

+39
-51
lines changed

4 files changed

+39
-51
lines changed

builtin/index-pack.c

Lines changed: 1 addition & 20 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;
@@ -1713,24 +1713,6 @@ static void show_pack_info(int stat_only)
17131713
}
17141714
}
17151715

1716-
static int print_dangling_gitmodules(struct fsck_options *o,
1717-
const struct object_id *oid,
1718-
enum object_type object_type,
1719-
enum fsck_msg_type msg_type,
1720-
enum fsck_msg_id msg_id,
1721-
const char *message)
1722-
{
1723-
/*
1724-
* NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
1725-
* instead of relying on this string check.
1726-
*/
1727-
if (starts_with(message, "gitmodulesMissing")) {
1728-
printf("%s\n", oid_to_hex(oid));
1729-
return 0;
1730-
}
1731-
return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
1732-
}
1733-
17341716
int cmd_index_pack(int argc, const char **argv, const char *prefix)
17351717
{
17361718
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
@@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
17611743

17621744
read_replace_refs = 0;
17631745
fsck_options.walk = mark_link;
1764-
fsck_options.error_func = print_dangling_gitmodules;
17651746

17661747
reset_pack_idx_option(&opts);
17671748
git_config(git_index_pack_config, &opts);

fetch-pack.c

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +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_STRICT;
41+
static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
4242
static struct strbuf fsck_msg_types = STRBUF_INIT;
4343
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
4444

@@ -988,21 +988,6 @@ static int cmp_ref_by_name(const void *a_, const void *b_)
988988
return strcmp(a->name, b->name);
989989
}
990990

991-
static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
992-
{
993-
struct oidset_iter iter;
994-
const struct object_id *oid;
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(&fsck_options, oid);
1002-
if (fsck_finish(&fsck_options))
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);

fsck.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,11 +1196,6 @@ int fsck_error_function(struct fsck_options *o,
11961196
return 1;
11971197
}
11981198

1199-
void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid)
1200-
{
1201-
oidset_insert(&options->gitmodules_found, oid);
1202-
}
1203-
12041199
int fsck_finish(struct fsck_options *options)
12051200
{
12061201
int ret = 0;
@@ -1266,3 +1261,21 @@ int git_fsck_config(const char *var, const char *value, void *cb)
12661261

12671262
return git_default_config(var, value, cb);
12681263
}
1264+
1265+
/*
1266+
* Custom error callbacks that are used in more than one place.
1267+
*/
1268+
1269+
int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
1270+
const struct object_id *oid,
1271+
enum object_type object_type,
1272+
enum fsck_msg_type msg_type,
1273+
enum fsck_msg_id msg_id,
1274+
const char *message)
1275+
{
1276+
if (msg_id == FSCK_MSG_GITMODULES_MISSING) {
1277+
puts(oid_to_hex(oid));
1278+
return 0;
1279+
}
1280+
return fsck_error_function(o, oid, object_type, msg_type, msg_id, message);
1281+
}

fsck.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ int fsck_error_function(struct fsck_options *o,
111111
const struct object_id *oid, enum object_type object_type,
112112
enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
113113
const char *message);
114+
int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o,
115+
const struct object_id *oid,
116+
enum object_type object_type,
117+
enum fsck_msg_type msg_type,
118+
enum fsck_msg_id msg_id,
119+
const char *message);
114120

115121
struct fsck_options {
116122
fsck_walk_func walk;
@@ -135,6 +141,12 @@ struct fsck_options {
135141
.gitmodules_done = OIDSET_INIT, \
136142
.error_func = fsck_error_function, \
137143
}
144+
#define FSCK_OPTIONS_MISSING_GITMODULES { \
145+
.strict = 1, \
146+
.gitmodules_found = OIDSET_INIT, \
147+
.gitmodules_done = OIDSET_INIT, \
148+
.error_func = fsck_error_cb_print_missing_gitmodules, \
149+
}
138150

139151
/* descend in all linked child objects
140152
* the return value is:
@@ -152,9 +164,6 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
152164
int fsck_object(struct object *obj, void *data, unsigned long size,
153165
struct fsck_options *options);
154166

155-
void register_found_gitmodules(struct fsck_options *options,
156-
const struct object_id *oid);
157-
158167
/*
159168
* fsck a tag, and pass info about it back to the caller. This is
160169
* exposed fsck_object() internals for git-mktag(1).

0 commit comments

Comments
 (0)