X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=remote.c;h=9a88917aab32f32235d0ebaa1ffd0e2f2773a927;hb=c05ef93879696638406cad5be54be577a2666d04;hp=09c427906d8e873ab3f7142be03aa4b69dd1f4b2;hpb=baa79ca42d0ba5e93e4bb021706ec9a65cca6dda;p=git.git diff --git a/remote.c b/remote.c index 09c427906..9a88917aa 100644 --- a/remote.c +++ b/remote.c @@ -279,6 +279,25 @@ struct remote *remote_get(const char *name) return ret; } +int for_each_remote(each_remote_fn fn, void *priv) +{ + int i, result = 0; + read_config(); + for (i = 0; i < allocated_remotes && !result; i++) { + struct remote *r = remotes[i]; + if (!r) + continue; + if (!r->fetch) + r->fetch = parse_ref_spec(r->fetch_refspec_nr, + r->fetch_refspec); + if (!r->push) + r->push = parse_ref_spec(r->push_refspec_nr, + r->push_refspec); + result = fn(r, priv); + } + return result; +} + int remote_has_uri(struct remote *remote, const char *uri) { int i; @@ -291,32 +310,43 @@ int remote_has_uri(struct remote *remote, const char *uri) int remote_find_tracking(struct remote *remote, struct refspec *refspec) { + int find_src = refspec->src == NULL; + char *needle, **result; int i; + + if (find_src) { + if (refspec->dst == NULL) + return error("find_tracking: need either src or dst"); + needle = refspec->dst; + result = &refspec->src; + } else { + needle = refspec->src; + result = &refspec->dst; + } + for (i = 0; i < remote->fetch_refspec_nr; i++) { struct refspec *fetch = &remote->fetch[i]; + const char *key = find_src ? fetch->dst : fetch->src; + const char *value = find_src ? fetch->src : fetch->dst; if (!fetch->dst) continue; if (fetch->pattern) { - if (!prefixcmp(refspec->src, fetch->src)) { - refspec->dst = - xmalloc(strlen(fetch->dst) + - strlen(refspec->src) - - strlen(fetch->src) + 1); - strcpy(refspec->dst, fetch->dst); - strcpy(refspec->dst + strlen(fetch->dst), - refspec->src + strlen(fetch->src)); - refspec->force = fetch->force; - return 0; - } - } else { - if (!strcmp(refspec->src, fetch->src)) { - refspec->dst = xstrdup(fetch->dst); + if (!prefixcmp(needle, key)) { + *result = xmalloc(strlen(value) + + strlen(needle) - + strlen(key) + 1); + strcpy(*result, value); + strcpy(*result + strlen(value), + needle + strlen(key)); refspec->force = fetch->force; return 0; } + } else if (!strcmp(needle, key)) { + *result = xstrdup(value); + refspec->force = fetch->force; + return 0; } } - refspec->dst = NULL; return -1; } @@ -474,8 +504,11 @@ static int match_explicit(struct ref *src, struct ref *dst, if (!matched_src) errs = 1; - if (dst_value == NULL) + if (!dst_value) { + if (!matched_src) + return errs; dst_value = matched_src->name; + } switch (count_refspec_match(dst_value, dst, &matched_dst)) { case 1: @@ -596,6 +629,8 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, hashcpy(dst_peer->new_sha1, src->new_sha1); } dst_peer->peer_ref = src; + if (pat) + dst_peer->force = pat->force; free_name: free(dst_name); }