No behavior changes yet, only some groundwork for the next change. The refs_result structure combines a status code with a ref map, which can be NULL even on success. This will be needed when there's a tweak-fetch hook, because it can filter out all refs, while still succeeding. fetch_refs returns a refs_result, so that it can modify the ref_map. Signed-off-by: Joey Hess <joey@xxxxxxxxxxx> --- builtin/fetch.c | 55 ++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 36 insertions(+), 19 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 33ad3aa..a48358a 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -29,6 +29,11 @@ enum { TAGS_SET = 2 }; +struct refs_result { + struct ref *new_refs; + int status; +}; + static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, verbosity; static int progress, recurse_submodules = RECURSE_SUBMODULES_DEFAULT; static int tags = TAGS_DEFAULT; @@ -89,6 +94,15 @@ static struct option builtin_fetch_options[] = { OPT_END() }; +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(list, refname); + item->util = (void *)sha1; + return 0; +} + static void unlock_pack(void) { if (transport) @@ -507,17 +521,25 @@ static int quickfetch(struct ref *ref_map) return check_everything_connected(iterate_ref_map, 1, &rm); } -static int fetch_refs(struct transport *transport, struct ref *ref_map) +static struct refs_result fetch_refs(struct transport *transport, + struct ref *ref_map) { - int ret = quickfetch(ref_map); - if (ret) - ret = transport_fetch_refs(transport, ref_map); - if (!ret) - ret |= store_updated_refs(transport->url, + struct refs_result res; + res.status = quickfetch(ref_map); + if (res.status) + res.status = transport_fetch_refs(transport, ref_map); + if (!res.status) { + res.new_refs = ref_map; + + res.status |= store_updated_refs(transport->url, transport->remote->name, - ref_map); + res.new_refs); + } + else { + res.new_refs = ref_map; + } transport_unlock_pack(transport); - return ret; + return res; } static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map) @@ -542,15 +564,6 @@ static int prune_refs(struct refspec *refs, int ref_count, 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(list, refname); - item->util = (void *)sha1; - return 0; -} - static int will_fetch(struct ref **head, const unsigned char *sha1) { struct ref *rm = *head; @@ -673,6 +686,7 @@ static int do_fetch(struct transport *transport, struct string_list_item *peer_item = NULL; struct ref *ref_map; struct ref *rm; + struct refs_result res; int autotags = (transport->remote->fetch_tags == 1); for_each_ref(add_existing, &existing_refs); @@ -710,7 +724,9 @@ static int do_fetch(struct transport *transport, if (tags == TAGS_DEFAULT && autotags) transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1"); - if (fetch_refs(transport, ref_map)) { + res = fetch_refs(transport, ref_map); + ref_map = res.new_refs; + if (res.status) { free_refs(ref_map); return 1; } @@ -750,7 +766,8 @@ static int do_fetch(struct transport *transport, if (ref_map) { transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL); transport_set_option(transport, TRANS_OPT_DEPTH, "0"); - fetch_refs(transport, ref_map); + res = fetch_refs(transport, ref_map); + ref_map = res.new_refs; } free_refs(ref_map); } -- 1.7.7.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html