[PATCH 5/9] fetch: Move loop checking which refs we have already
From: Andreas Gruenbacher <hidden>
Date: 2016-06-15 22:48:27
Subsystem:
the rest · Maintainer:
Linus Torvalds
This loop fits better into get_ref_map(); move it there. Signed-off-by: Andreas Gruenbacher <redacted> --- builtin/fetch.c | 48 ++++++++++++++++++++++++------------------------ 1 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index fc6efc7..6dc75d4 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c@@ -115,6 +115,15 @@ static void add_merge_config(struct ref **head, } } +static int add_existing(const char *refname, const unsigned char *sha1, + int flag, void *cbdata) +{ + struct string_list *list = (struct string_list *)cbdata; + struct string_list_item *item = string_list_insert(refname, list); + item->util = (void *)sha1; + return 0; +} + static void find_non_local_tags(struct transport *transport, struct ref **head, struct ref ***tail);
@@ -123,6 +132,7 @@ static struct ref *get_ref_map(struct transport *transport, struct refspec *refs, int ref_count, int tags, int *autotags) { + struct string_list existing_refs = { NULL, 0, 0, 0 }; int i; struct ref *rm; struct ref *ref_map = NULL;
@@ -176,6 +186,20 @@ static struct ref *get_ref_map(struct transport *transport, find_non_local_tags(transport, &ref_map, &tail); ref_remove_duplicates(ref_map); + for_each_ref(add_existing, &existing_refs); + for (rm = ref_map; rm; rm = rm->next) { + if (rm->peer_ref) { + struct string_list_item *peer_item; + + peer_item = string_list_lookup(rm->peer_ref->name, + &existing_refs); + if (peer_item) + hashcpy(rm->peer_ref->old_sha1, + peer_item->util); + } + } + string_list_clear(&existing_refs, 0); + return ref_map; }
@@ -554,15 +578,6 @@ static int prune_refs(struct transport *transport, struct ref *ref_map) return result; } -static int add_existing(const char *refname, const unsigned char *sha1, - int flag, void *cbdata) -{ - struct string_list *list = (struct string_list *)cbdata; - struct string_list_item *item = string_list_insert(refname, list); - item->util = (void *)sha1; - return 0; -} - static int will_fetch(struct ref **head, const unsigned char *sha1) { struct ref *rm = *head;
@@ -696,14 +711,9 @@ static int truncate_fetch_head(void) static int do_fetch(struct transport *transport, struct refspec *refs, int ref_count) { - struct string_list existing_refs = { NULL, 0, 0, 0 }; - struct string_list_item *peer_item = NULL; struct ref *ref_map; - struct ref *rm; int autotags = (transport->remote->fetch_tags == 1); - for_each_ref(add_existing, &existing_refs); - if (transport->remote->fetch_tags == 2 && tags != TAGS_UNSET) tags = TAGS_SET; if (transport->remote->fetch_tags == -1)
@@ -723,16 +733,6 @@ static int do_fetch(struct transport *transport, if (!update_head_ok) check_not_current_branch(ref_map); - for (rm = ref_map; rm; rm = rm->next) { - if (rm->peer_ref) { - peer_item = string_list_lookup(rm->peer_ref->name, - &existing_refs); - if (peer_item) - hashcpy(rm->peer_ref->old_sha1, - peer_item->util); - } - } - if (tags == TAGS_DEFAULT && autotags) transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1"); if (fetch_refs(transport, ref_map)) {
--
1.7.0.2.273.gc2413