Commit 12595ab8f91a71e5a596a883b31789d5317e9ec2

nulltoken 2012-07-12T00:52:01

revparse: deploy git_reference_remote_tracking_from_branch()

diff --git a/src/revparse.c b/src/revparse.c
index 670f67e..2b03c86 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -249,32 +249,12 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char *
 		date_error = git__date_parse(&timestamp, git_buf_cstr(&datebuf));
 
 		/* @{u} or @{upstream} -> upstream branch, for a tracking branch. This is stored in the config. */
-		if (!git__prefixcmp(git_reference_name(disambiguated), GIT_REFS_HEADS_DIR) &&
-			(!strcmp(reflogspec, "@{u}") || !strcmp(reflogspec, "@{upstream}"))) {
-			git_config *cfg;
-			if (!git_repository_config(&cfg, repo)) {
-				/* Is the ref a tracking branch? */
-				const char *remote;
-				git_buf_clear(&buf);
-				git_buf_printf(&buf, "branch.%s.remote",
-					git_reference_name(disambiguated) + strlen(GIT_REFS_HEADS_DIR));
-
-				if (!git_config_get_string(&remote, cfg, git_buf_cstr(&buf))) {
-					/* Yes. Find the first merge target name. */
-					const char *mergetarget;
-					git_buf_clear(&buf);
-					git_buf_printf(&buf, "branch.%s.merge",
-						git_reference_name(disambiguated) + strlen(GIT_REFS_HEADS_DIR));
-
-					if (!git_config_get_string(&mergetarget, cfg, git_buf_cstr(&buf)) &&
-						!git__prefixcmp(mergetarget, "refs/heads/")) {
-							/* Success. Look up the target and fetch the object. */
-							git_buf_clear(&buf);
-							git_buf_printf(&buf, "refs/remotes/%s/%s", remote, mergetarget+11);
-							retcode = revparse_lookup_fully_qualifed_ref(out, repo, git_buf_cstr(&buf));
-					}
-				}
-				git_config_free(cfg);
+		if (!strcmp(reflogspec, "@{u}") || !strcmp(reflogspec, "@{upstream}")) {
+			git_reference *tracking;
+			
+			if (!(retcode = git_reference_remote_tracking_from_branch(&tracking, disambiguated))) {
+				retcode = revparse_lookup_fully_qualifed_ref(out, repo, git_reference_name(tracking));
+				git_reference_free(tracking);
 			}
 		}