summaryrefslogtreecommitdiff
path: root/src/branch.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2013-04-20 04:43:28 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2013-04-20 17:54:13 +0200
commit4330ab26b53c0e1bf8cbb5e65704f65e3d116eba (patch)
tree14bf8d854854298bfe43b3a02c8c26f59377c988 /src/branch.c
parente5a27f039ee3ae1291fd5084707c3f9c168f10ba (diff)
downloadlibgit2-4330ab26b53c0e1bf8cbb5e65704f65e3d116eba.tar.gz
remote: handle multiple refspecs
A remote can have a multitude of refspecs. Up to now our git_remote's have supported a single one for each fetch and push out of simplicity to get something working. Let the remotes and internal code know about multiple remotes and get the tests passing with them. Instead of setting a refspec, the external users can clear all and add refspecs. This should be enough for most uses, though we're still missing a querying function.
Diffstat (limited to 'src/branch.c')
-rw-r--r--src/branch.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/branch.c b/src/branch.c
index 956286b74..88f052529 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -11,6 +11,7 @@
#include "config.h"
#include "refspec.h"
#include "refs.h"
+#include "remote.h"
#include "git2/branch.h"
@@ -283,12 +284,10 @@ int git_branch_upstream__name(
if ((error = git_remote_load(&remote, repo, remote_name)) < 0)
goto cleanup;
- refspec = git_remote_fetchspec(remote);
- if (refspec == NULL
- || refspec->src == NULL
- || refspec->dst == NULL) {
- error = GIT_ENOTFOUND;
- goto cleanup;
+ refspec = git_remote__matching_refspec(remote, merge_name);
+ if (!refspec) {
+ error = GIT_ENOTFOUND;
+ goto cleanup;
}
if (git_refspec_transform_r(&buf, refspec, merge_name) < 0)
@@ -333,11 +332,8 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical
if ((error = git_remote_load(&remote, repo, remote_list.strings[i])) < 0)
continue;
- fetchspec = git_remote_fetchspec(remote);
-
- /* Defensivly check that we have a fetchspec */
- if (fetchspec &&
- git_refspec_dst_matches(fetchspec, canonical_branch_name)) {
+ fetchspec = git_remote__matching_dst_refspec(remote, canonical_branch_name);
+ if (fetchspec) {
/* If we have not already set out yet, then set
* it to the matching remote name. Otherwise
* multiple remotes match this reference, and it
@@ -522,9 +518,9 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
if (git_remote_load(&remote, repo, git_buf_cstr(&value)) < 0)
goto on_error;
- fetchspec = git_remote_fetchspec(remote);
+ fetchspec = git_remote__matching_dst_refspec(remote, git_reference_name(upstream));
git_buf_clear(&value);
- if (git_refspec_transform_l(&value, fetchspec, git_reference_name(upstream)) < 0)
+ if (!fetchspec || git_refspec_transform_l(&value, fetchspec, git_reference_name(upstream)) < 0)
goto on_error;
git_remote_free(remote);