fetch-pack: put shallow info in output parameter

Expand the transport fetch method signature, by adding an output
parameter, to allow transports to return information about the refs they
have fetched.  Then communicate shallow status information through this
mechanism instead of by modifying the input list of refs.

This does require clients to sometimes generate the ref map twice: once
from the list of refs provided by the remote (as is currently done) and
potentially once from the new list of refs that the fetch mechanism
provides.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Brandon Williams 2018-06-27 15:30:22 -07:00 коммит произвёл Junio C Hamano
Родитель 6d1700d564
Коммит 989b8c4452
8 изменённых файлов: 77 добавлений и 24 удалений

Просмотреть файл

@ -1155,7 +1155,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
}
if (!is_local && !complete_refs_before_fetch)
transport_fetch_refs(transport, mapped_refs);
transport_fetch_refs(transport, mapped_refs, NULL);
remote_head = find_ref_by_name(refs, "HEAD");
remote_head_points_at =
@ -1197,7 +1197,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (is_local)
clone_local(path, git_dir);
else if (refs && complete_refs_before_fetch)
transport_fetch_refs(transport, mapped_refs);
transport_fetch_refs(transport, mapped_refs, NULL);
update_remote_refs(refs, mapped_refs, remote_head_points_at,
branch_top.buf, reflog_msg.buf, transport,

Просмотреть файл

@ -946,11 +946,13 @@ static int quickfetch(struct ref *ref_map)
return check_connected(iterate_ref_map, &rm, &opt);
}
static int fetch_refs(struct transport *transport, struct ref *ref_map)
static int fetch_refs(struct transport *transport, struct ref *ref_map,
struct ref **updated_remote_refs)
{
int ret = quickfetch(ref_map);
if (ret)
ret = transport_fetch_refs(transport, ref_map);
ret = transport_fetch_refs(transport, ref_map,
updated_remote_refs);
if (!ret)
/*
* Keep the new pack's ".keep" file around to allow the caller
@ -1112,7 +1114,7 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map)
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
if (!fetch_refs(transport, ref_map))
if (!fetch_refs(transport, ref_map, NULL))
consume_refs(transport, ref_map);
if (gsecondary) {
@ -1128,6 +1130,7 @@ static int do_fetch(struct transport *transport,
int autotags = (transport->remote->fetch_tags == 1);
int retcode = 0;
const struct ref *remote_refs;
struct ref *updated_remote_refs = NULL;
struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
if (tags == TAGS_DEFAULT) {
@ -1178,7 +1181,24 @@ static int do_fetch(struct transport *transport,
transport->url);
}
}
if (fetch_refs(transport, ref_map) || consume_refs(transport, ref_map)) {
if (fetch_refs(transport, ref_map, &updated_remote_refs)) {
free_refs(ref_map);
retcode = 1;
goto cleanup;
}
if (updated_remote_refs) {
/*
* Regenerate ref_map using the updated remote refs. This is
* to account for additional information which may be provided
* by the transport (e.g. shallow info).
*/
free_refs(ref_map);
ref_map = get_ref_map(transport->remote, updated_remote_refs, rs,
tags, &autotags);
free_refs(updated_remote_refs);
}
if (consume_refs(transport, ref_map)) {
free_refs(ref_map);
retcode = 1;
goto cleanup;

Просмотреть файл

@ -19,7 +19,7 @@ static void fetch_refs(const char *remote_name, struct ref *ref)
transport_set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
transport_set_option(transport, TRANS_OPT_NO_DEPENDENTS, "1");
transport_fetch_refs(transport, ref);
transport_fetch_refs(transport, ref, NULL);
fetch_if_missing = original_fetch_if_missing;
}

Просмотреть файл

@ -1470,12 +1470,13 @@ static int remove_duplicates_in_refs(struct ref **ref, int nr)
}
static void update_shallow(struct fetch_pack_args *args,
struct ref **sought, int nr_sought,
struct ref *refs,
struct shallow_info *si)
{
struct oid_array ref = OID_ARRAY_INIT;
int *status;
int i;
struct ref *r;
if (args->deepen && alternate_shallow_file) {
if (*alternate_shallow_file == '\0') { /* --unshallow */
@ -1517,8 +1518,8 @@ static void update_shallow(struct fetch_pack_args *args,
remove_nonexistent_theirs_shallow(si);
if (!si->nr_ours && !si->nr_theirs)
return;
for (i = 0; i < nr_sought; i++)
oid_array_append(&ref, &sought[i]->old_oid);
for (r = refs; r; r = r->next)
oid_array_append(&ref, &r->old_oid);
si->ref = &ref;
if (args->update_shallow) {
@ -1552,12 +1553,12 @@ static void update_shallow(struct fetch_pack_args *args,
* remote is also shallow, check what ref is safe to update
* without updating .git/shallow
*/
status = xcalloc(nr_sought, sizeof(*status));
status = xcalloc(ref.nr, sizeof(*status));
assign_shallow_commits_to_refs(si, NULL, status);
if (si->nr_ours || si->nr_theirs) {
for (i = 0; i < nr_sought; i++)
for (r = refs, i = 0; r; r = r->next, i++)
if (status[i])
sought[i]->status = REF_STATUS_REJECT_SHALLOW;
r->status = REF_STATUS_REJECT_SHALLOW;
}
free(status);
oid_array_clear(&ref);
@ -1591,7 +1592,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,
&si, pack_lockfile);
reprepare_packed_git(the_repository);
update_shallow(args, sought, nr_sought, &si);
update_shallow(args, ref_cpy, &si);
clear_shallow_info(&si);
return ref_cpy;
}

Просмотреть файл

@ -651,14 +651,16 @@ static int connect_helper(struct transport *transport, const char *name,
}
static int fetch(struct transport *transport,
int nr_heads, struct ref **to_fetch)
int nr_heads, struct ref **to_fetch,
struct ref **fetched_refs)
{
struct helper_data *data = transport->data;
int i, count;
if (process_connect(transport, 0)) {
do_take_over(transport);
return transport->vtable->fetch(transport, nr_heads, to_fetch);
return transport->vtable->fetch(transport, nr_heads, to_fetch,
fetched_refs);
}
count = 0;

Просмотреть файл

@ -36,11 +36,18 @@ struct transport_vtable {
* Fetch the objects for the given refs. Note that this gets
* an array, and should ignore the list structure.
*
* The transport *may* provide, in fetched_refs, the list of refs that
* it fetched. If the transport knows anything about the fetched refs
* that the caller does not know (for example, shallow status), it
* should provide that list of refs and include that information in the
* list.
*
* If the transport did not get hashes for refs in
* get_refs_list(), it should set the old_sha1 fields in the
* provided refs now.
**/
int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs);
int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs,
struct ref **fetched_refs);
/**
* Push the objects and refs. Send the necessary objects, and

Просмотреть файл

@ -151,7 +151,8 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
}
static int fetch_refs_from_bundle(struct transport *transport,
int nr_heads, struct ref **to_fetch)
int nr_heads, struct ref **to_fetch,
struct ref **fetched_refs)
{
struct bundle_transport_data *data = transport->data;
return unbundle(&data->header, data->fd,
@ -287,7 +288,8 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
}
static int fetch_refs_via_pack(struct transport *transport,
int nr_heads, struct ref **to_fetch)
int nr_heads, struct ref **to_fetch,
struct ref **fetched_refs)
{
int ret = 0;
struct git_transport_data *data = transport->data;
@ -354,8 +356,12 @@ static int fetch_refs_via_pack(struct transport *transport,
if (report_unmatched_refs(to_fetch, nr_heads))
ret = -1;
if (fetched_refs)
*fetched_refs = refs;
else
free_refs(refs);
free_refs(refs_tmp);
free_refs(refs);
free(dest);
return ret;
}
@ -1215,19 +1221,31 @@ const struct ref *transport_get_remote_refs(struct transport *transport,
return transport->remote_refs;
}
int transport_fetch_refs(struct transport *transport, struct ref *refs)
int transport_fetch_refs(struct transport *transport, struct ref *refs,
struct ref **fetched_refs)
{
int rc;
int nr_heads = 0, nr_alloc = 0, nr_refs = 0;
struct ref **heads = NULL;
struct ref *nop_head = NULL, **nop_tail = &nop_head;
struct ref *rm;
for (rm = refs; rm; rm = rm->next) {
nr_refs++;
if (rm->peer_ref &&
!is_null_oid(&rm->old_oid) &&
!oidcmp(&rm->peer_ref->old_oid, &rm->old_oid))
!oidcmp(&rm->peer_ref->old_oid, &rm->old_oid)) {
/*
* These need to be reported as fetched, but we don't
* actually need to fetch them.
*/
if (fetched_refs) {
struct ref *nop_ref = copy_ref(rm);
*nop_tail = nop_ref;
nop_tail = &nop_ref->next;
}
continue;
}
ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
heads[nr_heads++] = rm;
}
@ -1245,7 +1263,11 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
heads[nr_heads++] = rm;
}
rc = transport->vtable->fetch(transport, nr_heads, heads);
rc = transport->vtable->fetch(transport, nr_heads, heads, fetched_refs);
if (fetched_refs && nop_head) {
*nop_tail = *fetched_refs;
*fetched_refs = nop_head;
}
free(heads);
return rc;

Просмотреть файл

@ -218,7 +218,8 @@ int transport_push(struct transport *connection,
const struct ref *transport_get_remote_refs(struct transport *transport,
const struct argv_array *ref_prefixes);
int transport_fetch_refs(struct transport *transport, struct ref *refs);
int transport_fetch_refs(struct transport *transport, struct ref *refs,
struct ref **fetched_refs);
void transport_unlock_pack(struct transport *transport);
int transport_disconnect(struct transport *transport);
char *transport_anonymize_url(const char *url);