From: Junio C Hamano Date: Wed, 8 Sep 2010 16:17:00 +0000 (-0700) Subject: Merge branch 'bc/maint-fetch-url-only' X-Git-Tag: v1.7.3-rc1~15 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e250c5914fd151caf228cbda6c30560c266bcfef?ds=sidebyside;hp=-c Merge branch 'bc/maint-fetch-url-only' * bc/maint-fetch-url-only: builtin/fetch.c: ignore merge config when not fetching from branch's remote t/t5510: demonstrate failure to fetch when current branch has merge ref --- e250c5914fd151caf228cbda6c30560c266bcfef diff --combined builtin/fetch.c index fab3fce512,3bfc081c6d..fccc9cbea3 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@@ -146,7 -146,9 +146,9 @@@ static struct ref *get_ref_map(struct t struct remote *remote = transport->remote; struct branch *branch = branch_get(NULL); int has_merge = branch_has_merge_config(branch); - if (remote && (remote->fetch_refspec_nr || has_merge)) { + if (remote && + (remote->fetch_refspec_nr || + (has_merge && !strcmp(branch->remote_name, remote->name)))) { for (i = 0; i < remote->fetch_refspec_nr; i++) { get_fetch_map(remote_refs, &remote->fetch[i], &tail, 0); if (remote->fetch[i].dst && @@@ -528,7 -530,7 +530,7 @@@ static int add_existing(const char *ref int flag, void *cbdata) { struct string_list *list = (struct string_list *)cbdata; - struct string_list_item *item = string_list_insert(refname, list); + struct string_list_item *item = string_list_insert(list, refname); item->util = (void *)sha1; return 0; } @@@ -544,12 -546,37 +546,12 @@@ static int will_fetch(struct ref **head return 0; } -struct tag_data { - struct ref **head; - struct ref ***tail; -}; - -static int add_to_tail(struct string_list_item *item, void *cb_data) -{ - struct tag_data *data = (struct tag_data *)cb_data; - struct ref *rm = NULL; - - /* We have already decided to ignore this item */ - if (!item->util) - return 0; - - rm = alloc_ref(item->string); - rm->peer_ref = alloc_ref(item->string); - hashcpy(rm->old_sha1, item->util); - - **data->tail = rm; - *data->tail = &rm->next; - - return 0; -} - static void find_non_local_tags(struct transport *transport, struct ref **head, struct ref ***tail) { - struct string_list existing_refs = { NULL, 0, 0, 0 }; - struct string_list remote_refs = { NULL, 0, 0, 0 }; - struct tag_data data = {head, tail}; + struct string_list existing_refs = STRING_LIST_INIT_NODUP; + struct string_list remote_refs = STRING_LIST_INIT_NODUP; const struct ref *ref; struct string_list_item *item = NULL; @@@ -591,7 -618,7 +593,7 @@@ string_list_has_string(&existing_refs, ref->name)) continue; - item = string_list_insert(ref->name, &remote_refs); + item = string_list_insert(&remote_refs, ref->name); item->util = (void *)ref->old_sha1; } string_list_clear(&existing_refs, 0); @@@ -605,20 -632,10 +607,20 @@@ item->util = NULL; /* - * For all the tags in the remote_refs string list, call - * add_to_tail to add them to the list of refs to be fetched + * For all the tags in the remote_refs string list, + * add them to the list of refs to be fetched */ - for_each_string_list(add_to_tail, &remote_refs, &data); + for_each_string_list_item(item, &remote_refs) { + /* Unless we have already decided to ignore this item... */ + if (item->util) + { + struct ref *rm = alloc_ref(item->string); + rm->peer_ref = alloc_ref(item->string); + hashcpy(rm->old_sha1, item->util); + **tail = rm; + *tail = &rm->next; + } + } string_list_clear(&remote_refs, 0); } @@@ -651,7 -668,7 +653,7 @@@ 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 existing_refs = STRING_LIST_INIT_NODUP; struct string_list_item *peer_item = NULL; struct ref *ref_map; struct ref *rm; @@@ -659,12 -676,10 +661,12 @@@ 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) - tags = TAGS_UNSET; + if (tags == TAGS_DEFAULT) { + if (transport->remote->fetch_tags == 2) + tags = TAGS_SET; + if (transport->remote->fetch_tags == -1) + tags = TAGS_UNSET; + } if (!transport->get_refs_list || !transport->fetch) die("Don't know how to fetch from %s", transport->url); @@@ -682,8 -697,8 +684,8 @@@ for (rm = ref_map; rm; rm = rm->next) { if (rm->peer_ref) { - peer_item = string_list_lookup(rm->peer_ref->name, - &existing_refs); + peer_item = string_list_lookup(&existing_refs, + rm->peer_ref->name); if (peer_item) hashcpy(rm->peer_ref->old_sha1, peer_item->util); @@@ -732,7 -747,7 +734,7 @@@ static int get_one_remote_for_fetch(str { struct string_list *list = priv; if (!remote->skip_default_update) - string_list_append(remote->name, list); + string_list_append(list, remote->name); return 0; } @@@ -751,8 -766,8 +753,8 @@@ static int get_remote_group(const char int space = strcspn(value, " \t\n"); while (*value) { if (space > 1) { - string_list_append(xstrndup(value, space), - g->list); + string_list_append(g->list, + xstrndup(value, space)); } value += space + (value[space] != '\0'); space = strcspn(value, " \t\n"); @@@ -765,8 -780,7 +767,8 @@@ static int add_remote_or_group(const char *name, struct string_list *list) { int prev_nr = list->nr; - struct remote_group_data g = { name, list }; + struct remote_group_data g; + g.name = name; g.list = list; git_config(get_remote_group, &g); if (list->nr == prev_nr) { @@@ -774,7 -788,7 +776,7 @@@ if (!remote_is_configured(name)) return 0; remote = remote_get(name); - string_list_append(remote->name, list); + string_list_append(list, remote->name); } return 1; } @@@ -831,8 -845,7 +833,8 @@@ static int fetch_one(struct remote *rem int exit_code; if (!remote) - die("Where do you want to fetch from today?"); + die("No remote repository specified. Please, specify either a URL or a\n" + "remote name from which new revisions should be fetched."); transport = transport_get(remote, NULL); transport_set_verbosity(transport, verbosity, progress); @@@ -877,7 -890,7 +879,7 @@@ int cmd_fetch(int argc, const char **argv, const char *prefix) { int i; - struct string_list list = { NULL, 0, 0, 0 }; + struct string_list list = STRING_LIST_INIT_NODUP; struct remote *remote; int result = 0; diff --combined t/t5510-fetch.sh index 4eb10f602f,6a83771334..8fbd894e7f --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@@ -71,7 -71,7 +71,7 @@@ test_expect_success "fetch test for-mer echo "$one_in_two " } >expected && cut -f -2 .git/FETCH_HEAD >actual && - diff expected actual' + test_cmp expected actual' test_expect_success 'fetch tags when there is no tags' ' @@@ -240,6 -240,12 +240,12 @@@ test_expect_success 'fetch with a non-a git fetch blub ' + test_expect_success 'fetch from GIT URL with a non-applying branch..merge' ' + git update-ref -d FETCH_HEAD && + git fetch one && + git rev-parse --verify FETCH_HEAD + ' + # the strange name is: a\!'b test_expect_success 'quoting of a strangely named repo' ' test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&