summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-11-08 20:09:11 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2014-11-08 20:09:11 +0100
commite235db021267841ac39e2f539339d63d7e757672 (patch)
tree9d0245b983761d67eba6d8284c482d6ba797a407
parent82374d9825040914a3cfd8ceeaf60f76b93fe638 (diff)
downloadlibgit2-e235db021267841ac39e2f539339d63d7e757672.tar.gz
remote: use git_branch_upstream_remote()
This reduces the clutter somewhat and lets us see what we're asking about the reference.
-rw-r--r--src/remote.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/remote.c b/src/remote.c
index 0007c41db..c2c71592e 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -936,9 +936,10 @@ static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_re
git_buf remote_name = GIT_BUF_INIT;
git_buf upstream_name = GIT_BUF_INIT;
git_buf config_key = GIT_BUF_INIT;
+ git_buf upstream_remote = GIT_BUF_INIT;
git_repository *repo;
git_config *config = NULL;
- const char *ref_name, *branch_remote;
+ const char *ref_name;
int error = 0;
assert(out && spec && ref);
@@ -958,17 +959,16 @@ static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_re
}
if ((!git_reference__is_branch(ref_name)) ||
- (error = git_repository_config_snapshot(&config, repo)) < 0 ||
- (error = git_buf_printf(&config_key, "branch.%s.remote",
- ref_name + strlen(GIT_REFS_HEADS_DIR))) < 0 ||
- (error = git_config_get_string(&branch_remote, config, git_buf_cstr(&config_key))) < 0 ||
- git__strcmp(git_remote_name(remote), branch_remote) ||
+ (error = git_branch_upstream_remote(&upstream_remote, repo, ref_name)) ||
+ git__strcmp(git_remote_name(remote), git_buf_cstr(&upstream_remote)) ||
(error = git_branch_upstream_name(&upstream_name, repo, ref_name)) < 0 ||
!git_refspec_dst_matches(spec, git_buf_cstr(&upstream_name)) ||
(error = git_refspec_rtransform(&remote_name, spec, upstream_name.ptr)) < 0) {
/* Not an error if there is no upstream */
- if (error == GIT_ENOTFOUND)
+ if (error == GIT_ENOTFOUND) {
+ giterr_clear();
error = 0;
+ }
goto cleanup;
}
@@ -977,6 +977,7 @@ static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_re
cleanup:
git_reference_free(resolved_ref);
+ git_buf_free(&upstream_remote);
git_buf_free(&remote_name);
git_buf_free(&upstream_name);
git_buf_free(&config_key);