From: Junio C Hamano Date: Sun, 21 Jun 2009 04:47:27 +0000 (-0700) Subject: Merge branch 'mg/pushurl' X-Git-Tag: v1.6.4-rc0~46 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/deded16d151ff0f7b80ed21a518928daff09c14c?hp=-c Merge branch 'mg/pushurl' * mg/pushurl: avoid NULL dereference on failed malloc builtin-remote: Make "remote -v" display push urls builtin-remote: Show push urls as well technical/api-remote: Describe new struct remote member pushurl t5516: Check pushurl config setting Allow push and fetch urls to be different --- deded16d151ff0f7b80ed21a518928daff09c14c diff --combined builtin-remote.c index dfc0b9e706,fd0e63c5dc..406fb85255 --- a/builtin-remote.c +++ b/builtin-remote.c @@@ -295,14 -295,17 +295,14 @@@ static int get_push_ref_states(const st struct ref_states *states) { struct remote *remote = states->remote; - struct ref *ref, *local_refs, *push_map, **push_tail; + struct ref *ref, *local_refs, *push_map; if (remote->mirror) return 0; local_refs = get_local_heads(); push_map = copy_ref_list(remote_refs); - push_tail = &push_map; - while (*push_tail) - push_tail = &((*push_tail)->next); - match_refs(local_refs, push_map, &push_tail, remote->push_refspec_nr, + match_refs(local_refs, &push_map, remote->push_refspec_nr, remote->push_refspec, MATCH_REFS_NONE); states->push.strdup_strings = 1; @@@ -999,15 -1002,25 +999,25 @@@ static int show(int argc, const char ** info.list = &info_list; for (; argc; argc--, argv++) { int i; + const char **url; + int url_nr; get_remote_ref_states(*argv, &states, query_flag); printf("* remote %s\n", *argv); - if (states.remote->url_nr) { - for (i=0; i < states.remote->url_nr; i++) - printf(" URL: %s\n", states.remote->url[i]); - } else - printf(" URL: %s\n", "(no URL)"); + printf(" Fetch URL: %s\n", states.remote->url_nr > 0 ? + states.remote->url[0] : "(no URL)"); + if (states.remote->pushurl_nr) { + url = states.remote->pushurl; + url_nr = states.remote->pushurl_nr; + } else { + url = states.remote->url; + url_nr = states.remote->url_nr; + } + for (i=0; i < url_nr; i++) + printf(" Push URL: %s\n", url[i]); + if (!i) + printf(" Push URL: %s\n", "(no URL)"); if (no_query) printf(" HEAD branch: (not queried)\n"); else if (!states.heads.nr) @@@ -1266,14 -1279,31 +1276,31 @@@ static int update(int argc, const char static int get_one_entry(struct remote *remote, void *priv) { struct string_list *list = priv; + const char **url; + int i, url_nr; + void **utilp; if (remote->url_nr > 0) { - int i; - - for (i = 0; i < remote->url_nr; i++) - string_list_append(remote->name, list)->util = (void *)remote->url[i]; + utilp = &(string_list_append(remote->name, list)->util); + *utilp = xmalloc(strlen(remote->url[0])+strlen(" (fetch)")+1); + strcpy((char *) *utilp, remote->url[0]); + strcat((char *) *utilp, " (fetch)"); } else string_list_append(remote->name, list)->util = NULL; + if (remote->pushurl_nr) { + url = remote->pushurl; + url_nr = remote->pushurl_nr; + } else { + url = remote->url; + url_nr = remote->url_nr; + } + for (i = 0; i < url_nr; i++) + { + utilp = &(string_list_append(remote->name, list)->util); + *utilp = xmalloc(strlen(url[i])+strlen(" (push)")+1); + strcpy((char *) *utilp, url[i]); + strcat((char *) *utilp, " (push)"); + } return 0; } @@@ -1281,7 -1311,10 +1308,10 @@@ static int show_all(void) { struct string_list list = { NULL, 0, 0 }; - int result = for_each_remote(get_one_entry, &list); + int result; + + list.strdup_strings = 1; + result = for_each_remote(get_one_entry, &list); if (!result) { int i; @@@ -1299,6 -1332,7 +1329,7 @@@ } } } + string_list_clear(&list, 1); return result; } diff --combined remote.c index 08a59644c0,4544d65c72..9a0397ec57 --- a/remote.c +++ b/remote.c @@@ -106,6 -106,12 +106,12 @@@ static void add_url_alias(struct remot add_url(remote, alias_url(url)); } + static void add_pushurl(struct remote *remote, const char *pushurl) + { + ALLOC_GROW(remote->pushurl, remote->pushurl_nr + 1, remote->pushurl_alloc); + remote->pushurl[remote->pushurl_nr++] = pushurl; + } + static struct remote *make_remote(const char *name, int len) { struct remote *ret; @@@ -379,6 -385,11 +385,11 @@@ static int handle_config(const char *ke if (git_config_string(&v, key, value)) return -1; add_url(remote, v); + } else if (!strcmp(subkey, ".pushurl")) { + const char *v; + if (git_config_string(&v, key, value)) + return -1; + add_pushurl(remote, v); } else if (!strcmp(subkey, ".push")) { const char *v; if (git_config_string(&v, key, value)) @@@ -424,6 -435,9 +435,9 @@@ static void alias_all_urls(void for (j = 0; j < remotes[i]->url_nr; j++) { remotes[i]->url[j] = alias_url(remotes[i]->url[j]); } + for (j = 0; j < remotes[i]->pushurl_nr; j++) { + remotes[i]->pushurl[j] = alias_url(remotes[i]->pushurl[j]); + } } } @@@ -1085,20 -1099,12 +1099,20 @@@ static const struct refspec *check_patt return NULL; } +static struct ref **tail_ref(struct ref **head) +{ + struct ref **tail = head; + while (*tail) + tail = &((*tail)->next); + return tail; +} + /* * Note. This is used only by "push"; refspec matching rules for * push and fetch are subtly different, so do not try to reuse it * without thinking. */ -int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, +int match_refs(struct ref *src, struct ref **dst, int nr_refspec, const char **refspec, int flags) { struct refspec *rs; @@@ -1106,14 -1112,13 +1120,14 @@@ int send_mirror = flags & MATCH_REFS_MIRROR; int errs; static const char *default_refspec[] = { ":", 0 }; + struct ref **dst_tail = tail_ref(dst); if (!nr_refspec) { nr_refspec = 1; refspec = default_refspec; } rs = parse_push_refspec(nr_refspec, (const char **) refspec); - errs = match_explicit_refs(src, dst, dst_tail, rs, nr_refspec); + errs = match_explicit_refs(src, *dst, &dst_tail, rs, nr_refspec); /* pick the remainder */ for ( ; src; src = src->next) { @@@ -1143,7 -1148,7 +1157,7 @@@ dst_side, &dst_name)) die("Didn't think it matches any more"); } - dst_peer = find_ref_by_name(dst, dst_name); + dst_peer = find_ref_by_name(*dst, dst_name); if (dst_peer) { if (dst_peer->peer_ref) /* We're already sending something to this ref. */ @@@ -1159,7 -1164,7 +1173,7 @@@ goto free_name; /* Create a new one and link it */ - dst_peer = make_linked_ref(dst_name, dst_tail); + dst_peer = make_linked_ref(dst_name, &dst_tail); hashcpy(dst_peer->new_sha1, src->new_sha1); } dst_peer->peer_ref = copy_ref(src); diff --combined remote.h index 257a55538f,326bffeb0c..5db842087d --- a/remote.h +++ b/remote.h @@@ -15,6 -15,10 +15,10 @@@ struct remote int url_nr; int url_alloc; + const char **pushurl; + int pushurl_nr; + int pushurl_alloc; + const char **push_refspec; struct refspec *push; int push_refspec_nr; @@@ -85,7 -89,7 +89,7 @@@ void ref_remove_duplicates(struct ref * int valid_fetch_refspec(const char *refspec); struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec); -int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, +int match_refs(struct ref *src, struct ref **dst, int nr_refspec, const char **refspec, int all); /*