aboutsummaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2007-07-10 18:48:40 +0100
committerJunio C Hamano <gitster@pobox.com>2007-07-11 15:28:15 -0700
commitb42f69273bf5ae2d5bb0c7479bfa9827e7b351ac (patch)
tree67849e4e3354317f92e8dd6acf1d941e05bf2778 /remote.c
parent5206d13091a38b2fef534c78e893814dbab0af26 (diff)
downloadgit-b42f69273bf5ae2d5bb0c7479bfa9827e7b351ac.tar.gz
git-b42f69273bf5ae2d5bb0c7479bfa9827e7b351ac.tar.xz
Add for_each_remote() function, and extend remote_find_tracking()
The function for_each_remote() does exactly what the name suggests. The function remote_find_tracking() was extended to be able to search remote refs for a given local ref. The caller sets either src or dst (but not both) in the refspec parameter, and remote_find_tracking() will fill in the other and return 0. Both changes are required for the next step: simplification of git-branch's --track functionality. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c60
1 files changed, 45 insertions, 15 deletions
diff --git a/remote.c b/remote.c
index 09c427906..bb774d0bc 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;
}