remote.c: introduce branch_get_upstream helper

All of the information needed to find the @{upstream} of a
branch is included in the branch struct, but callers have to
navigate a series of possible-NULL values to get there.
Let's wrap that logic up in an easy-to-read helper.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2015-05-21 00:45:28 -04:00
committed by Junio C Hamano
parent 8770e6fbb2
commit a9f9f8cc1f
5 changed files with 23 additions and 16 deletions

View File

@ -1705,6 +1705,13 @@ int branch_merge_matches(struct branch *branch,
return refname_match(branch->merge[i]->src, refname);
}
const char *branch_get_upstream(struct branch *branch)
{
if (!branch || !branch->merge || !branch->merge[0])
return NULL;
return branch->merge[0]->dst;
}
static int ignore_symref_update(const char *refname)
{
unsigned char sha1[20];
@ -1914,12 +1921,11 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs)
int rev_argc;
/* Cannot stat unless we are marked to build on top of somebody else. */
if (!branch ||
!branch->merge || !branch->merge[0] || !branch->merge[0]->dst)
base = branch_get_upstream(branch);
if (!base)
return 0;
/* Cannot stat if what we used to build on no longer exists */
base = branch->merge[0]->dst;
if (read_ref(base, sha1))
return -1;
theirs = lookup_commit_reference(sha1);