fetch: refactor to make function args narrower
Refactor find_non_local_tags and get_ref_map to only take the information they need instead of the entire transport struct. Besides improving code clarity, this also improves their flexibility, allowing for a different set of refs to be used instead of relying on the ones stored in the transport struct. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
05c4422676
commit
6d1700d564
@ -254,9 +254,9 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void find_non_local_tags(struct transport *transport,
|
static void find_non_local_tags(const struct ref *refs,
|
||||||
struct ref **head,
|
struct ref **head,
|
||||||
struct ref ***tail)
|
struct ref ***tail)
|
||||||
{
|
{
|
||||||
struct string_list existing_refs = STRING_LIST_INIT_DUP;
|
struct string_list existing_refs = STRING_LIST_INIT_DUP;
|
||||||
struct string_list remote_refs = STRING_LIST_INIT_NODUP;
|
struct string_list remote_refs = STRING_LIST_INIT_NODUP;
|
||||||
@ -264,7 +264,7 @@ static void find_non_local_tags(struct transport *transport,
|
|||||||
struct string_list_item *item = NULL;
|
struct string_list_item *item = NULL;
|
||||||
|
|
||||||
for_each_ref(add_existing, &existing_refs);
|
for_each_ref(add_existing, &existing_refs);
|
||||||
for (ref = transport_get_remote_refs(transport, NULL); ref; ref = ref->next) {
|
for (ref = refs; ref; ref = ref->next) {
|
||||||
if (!starts_with(ref->name, "refs/tags/"))
|
if (!starts_with(ref->name, "refs/tags/"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -338,7 +338,8 @@ static void find_non_local_tags(struct transport *transport,
|
|||||||
string_list_clear(&remote_refs, 0);
|
string_list_clear(&remote_refs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ref *get_ref_map(struct transport *transport,
|
static struct ref *get_ref_map(struct remote *remote,
|
||||||
|
const struct ref *remote_refs,
|
||||||
struct refspec *rs,
|
struct refspec *rs,
|
||||||
int tags, int *autotags)
|
int tags, int *autotags)
|
||||||
{
|
{
|
||||||
@ -346,27 +347,11 @@ static struct ref *get_ref_map(struct transport *transport,
|
|||||||
struct ref *rm;
|
struct ref *rm;
|
||||||
struct ref *ref_map = NULL;
|
struct ref *ref_map = NULL;
|
||||||
struct ref **tail = &ref_map;
|
struct ref **tail = &ref_map;
|
||||||
struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
|
|
||||||
|
|
||||||
/* opportunistically-updated references: */
|
/* opportunistically-updated references: */
|
||||||
struct ref *orefs = NULL, **oref_tail = &orefs;
|
struct ref *orefs = NULL, **oref_tail = &orefs;
|
||||||
|
|
||||||
struct string_list existing_refs = STRING_LIST_INIT_DUP;
|
struct string_list existing_refs = STRING_LIST_INIT_DUP;
|
||||||
const struct ref *remote_refs;
|
|
||||||
|
|
||||||
if (rs->nr)
|
|
||||||
refspec_ref_prefixes(rs, &ref_prefixes);
|
|
||||||
else if (transport->remote && transport->remote->fetch.nr)
|
|
||||||
refspec_ref_prefixes(&transport->remote->fetch, &ref_prefixes);
|
|
||||||
|
|
||||||
if (ref_prefixes.argc &&
|
|
||||||
(tags == TAGS_SET || (tags == TAGS_DEFAULT && !rs->nr))) {
|
|
||||||
argv_array_push(&ref_prefixes, "refs/tags/");
|
|
||||||
}
|
|
||||||
|
|
||||||
remote_refs = transport_get_remote_refs(transport, &ref_prefixes);
|
|
||||||
|
|
||||||
argv_array_clear(&ref_prefixes);
|
|
||||||
|
|
||||||
if (rs->nr) {
|
if (rs->nr) {
|
||||||
struct refspec *fetch_refspec;
|
struct refspec *fetch_refspec;
|
||||||
@ -403,7 +388,7 @@ static struct ref *get_ref_map(struct transport *transport,
|
|||||||
if (refmap.nr)
|
if (refmap.nr)
|
||||||
fetch_refspec = &refmap;
|
fetch_refspec = &refmap;
|
||||||
else
|
else
|
||||||
fetch_refspec = &transport->remote->fetch;
|
fetch_refspec = &remote->fetch;
|
||||||
|
|
||||||
for (i = 0; i < fetch_refspec->nr; i++)
|
for (i = 0; i < fetch_refspec->nr; i++)
|
||||||
get_fetch_map(ref_map, &fetch_refspec->items[i], &oref_tail, 1);
|
get_fetch_map(ref_map, &fetch_refspec->items[i], &oref_tail, 1);
|
||||||
@ -411,7 +396,6 @@ static struct ref *get_ref_map(struct transport *transport,
|
|||||||
die("--refmap option is only meaningful with command-line refspec(s).");
|
die("--refmap option is only meaningful with command-line refspec(s).");
|
||||||
} else {
|
} else {
|
||||||
/* Use the defaults */
|
/* Use the defaults */
|
||||||
struct remote *remote = transport->remote;
|
|
||||||
struct branch *branch = branch_get(NULL);
|
struct branch *branch = branch_get(NULL);
|
||||||
int has_merge = branch_has_merge_config(branch);
|
int has_merge = branch_has_merge_config(branch);
|
||||||
if (remote &&
|
if (remote &&
|
||||||
@ -450,7 +434,7 @@ static struct ref *get_ref_map(struct transport *transport,
|
|||||||
/* also fetch all tags */
|
/* also fetch all tags */
|
||||||
get_fetch_map(remote_refs, tag_refspec, &tail, 0);
|
get_fetch_map(remote_refs, tag_refspec, &tail, 0);
|
||||||
else if (tags == TAGS_DEFAULT && *autotags)
|
else if (tags == TAGS_DEFAULT && *autotags)
|
||||||
find_non_local_tags(transport, &ref_map, &tail);
|
find_non_local_tags(remote_refs, &ref_map, &tail);
|
||||||
|
|
||||||
/* Now append any refs to be updated opportunistically: */
|
/* Now append any refs to be updated opportunistically: */
|
||||||
*tail = orefs;
|
*tail = orefs;
|
||||||
@ -1143,6 +1127,8 @@ static int do_fetch(struct transport *transport,
|
|||||||
struct ref *ref_map;
|
struct ref *ref_map;
|
||||||
int autotags = (transport->remote->fetch_tags == 1);
|
int autotags = (transport->remote->fetch_tags == 1);
|
||||||
int retcode = 0;
|
int retcode = 0;
|
||||||
|
const struct ref *remote_refs;
|
||||||
|
struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
|
||||||
|
|
||||||
if (tags == TAGS_DEFAULT) {
|
if (tags == TAGS_DEFAULT) {
|
||||||
if (transport->remote->fetch_tags == 2)
|
if (transport->remote->fetch_tags == 2)
|
||||||
@ -1158,7 +1144,21 @@ static int do_fetch(struct transport *transport,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ref_map = get_ref_map(transport, rs, tags, &autotags);
|
if (rs->nr)
|
||||||
|
refspec_ref_prefixes(rs, &ref_prefixes);
|
||||||
|
else if (transport->remote && transport->remote->fetch.nr)
|
||||||
|
refspec_ref_prefixes(&transport->remote->fetch, &ref_prefixes);
|
||||||
|
|
||||||
|
if (ref_prefixes.argc &&
|
||||||
|
(tags == TAGS_SET || (tags == TAGS_DEFAULT && !rs->nr))) {
|
||||||
|
argv_array_push(&ref_prefixes, "refs/tags/");
|
||||||
|
}
|
||||||
|
|
||||||
|
remote_refs = transport_get_remote_refs(transport, &ref_prefixes);
|
||||||
|
argv_array_clear(&ref_prefixes);
|
||||||
|
|
||||||
|
ref_map = get_ref_map(transport->remote, remote_refs, rs,
|
||||||
|
tags, &autotags);
|
||||||
if (!update_head_ok)
|
if (!update_head_ok)
|
||||||
check_not_current_branch(ref_map);
|
check_not_current_branch(ref_map);
|
||||||
|
|
||||||
@ -1190,7 +1190,7 @@ static int do_fetch(struct transport *transport,
|
|||||||
if (tags == TAGS_DEFAULT && autotags) {
|
if (tags == TAGS_DEFAULT && autotags) {
|
||||||
struct ref **tail = &ref_map;
|
struct ref **tail = &ref_map;
|
||||||
ref_map = NULL;
|
ref_map = NULL;
|
||||||
find_non_local_tags(transport, &ref_map, &tail);
|
find_non_local_tags(remote_refs, &ref_map, &tail);
|
||||||
if (ref_map)
|
if (ref_map)
|
||||||
backfill_tags(transport, ref_map);
|
backfill_tags(transport, ref_map);
|
||||||
free_refs(ref_map);
|
free_refs(ref_map);
|
||||||
|
Reference in New Issue
Block a user