fetch-pack: use new fsck API to printing dangling submodules
Refactor the check added in 5476e1efde
(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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
c96e184cae
commit
3745e2693d
31
fetch-pack.c
31
fetch-pack.c
@ -38,7 +38,7 @@ static int server_supports_filtering;
|
||||
static int advertise_sid;
|
||||
static struct shallow_lock shallow_lock;
|
||||
static const char *alternate_shallow_file;
|
||||
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
|
||||
static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
|
||||
static struct strbuf fsck_msg_types = STRBUF_INIT;
|
||||
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
|
||||
|
||||
@ -988,21 +988,6 @@ static int cmp_ref_by_name(const void *a_, const void *b_)
|
||||
return strcmp(a->name, b->name);
|
||||
}
|
||||
|
||||
static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
|
||||
{
|
||||
struct oidset_iter iter;
|
||||
const struct object_id *oid;
|
||||
|
||||
if (!oidset_size(gitmodules_oids))
|
||||
return;
|
||||
|
||||
oidset_iter_init(gitmodules_oids, &iter);
|
||||
while ((oid = oidset_iter_next(&iter)))
|
||||
register_found_gitmodules(&fsck_options, oid);
|
||||
if (fsck_finish(&fsck_options))
|
||||
die("fsck failed");
|
||||
}
|
||||
|
||||
static struct ref *do_fetch_pack(struct fetch_pack_args *args,
|
||||
int fd[2],
|
||||
const struct ref *orig_ref,
|
||||
@ -1017,7 +1002,6 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
|
||||
int agent_len;
|
||||
struct fetch_negotiator negotiator_alloc;
|
||||
struct fetch_negotiator *negotiator;
|
||||
struct oidset gitmodules_oids = OIDSET_INIT;
|
||||
|
||||
negotiator = &negotiator_alloc;
|
||||
fetch_negotiator_init(r, negotiator);
|
||||
@ -1134,9 +1118,10 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
|
||||
else
|
||||
alternate_shallow_file = NULL;
|
||||
if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought,
|
||||
&gitmodules_oids))
|
||||
&fsck_options.gitmodules_found))
|
||||
die(_("git fetch-pack: fetch failed."));
|
||||
fsck_gitmodules_oids(&gitmodules_oids);
|
||||
if (fsck_finish(&fsck_options))
|
||||
die("fsck failed");
|
||||
|
||||
all_done:
|
||||
if (negotiator)
|
||||
@ -1587,7 +1572,6 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
|
||||
struct string_list packfile_uris = STRING_LIST_INIT_DUP;
|
||||
int i;
|
||||
struct strvec index_pack_args = STRVEC_INIT;
|
||||
struct oidset gitmodules_oids = OIDSET_INIT;
|
||||
|
||||
negotiator = &negotiator_alloc;
|
||||
fetch_negotiator_init(r, negotiator);
|
||||
@ -1678,7 +1662,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
|
||||
process_section_header(&reader, "packfile", 0);
|
||||
if (get_pack(args, fd, pack_lockfiles,
|
||||
packfile_uris.nr ? &index_pack_args : NULL,
|
||||
sought, nr_sought, &gitmodules_oids))
|
||||
sought, nr_sought, &fsck_options.gitmodules_found))
|
||||
die(_("git fetch-pack: fetch failed."));
|
||||
do_check_stateless_delimiter(args, &reader);
|
||||
|
||||
@ -1721,7 +1705,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
|
||||
|
||||
packname[the_hash_algo->hexsz] = '\0';
|
||||
|
||||
parse_gitmodules_oids(cmd.out, &gitmodules_oids);
|
||||
parse_gitmodules_oids(cmd.out, &fsck_options.gitmodules_found);
|
||||
|
||||
close(cmd.out);
|
||||
|
||||
@ -1742,7 +1726,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
|
||||
string_list_clear(&packfile_uris, 0);
|
||||
strvec_clear(&index_pack_args);
|
||||
|
||||
fsck_gitmodules_oids(&gitmodules_oids);
|
||||
if (fsck_finish(&fsck_options))
|
||||
die("fsck failed");
|
||||
|
||||
if (negotiator)
|
||||
negotiator->release(negotiator);
|
||||
|
Reference in New Issue
Block a user