Re: [PATCH v3 07/14] remote.c: introduce branch_get_upstream helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jeff King <peff@xxxxxxxx> writes:

> 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@xxxxxxxx>

This step in the whole series is a gem.  I cannot believe that we
were content having to repeat that "branch->merge[0]->dst if we can
dereference down to that level" this many times.  Nice clean-up.

> diff --git a/builtin/branch.c b/builtin/branch.c
> index 258fe2f..1eb6215 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -123,14 +123,12 @@ static int branch_merged(int kind, const char *name,
>  
>  	if (kind == REF_LOCAL_BRANCH) {
>  		struct branch *branch = branch_get(name);
> +		const char *upstream = branch_get_upstream(branch);
>  		unsigned char sha1[20];
>  
> -		if (branch &&
> -		    branch->merge &&
> -		    branch->merge[0] &&
> -		    branch->merge[0]->dst &&
> +		if (upstream &&
>  		    (reference_name = reference_name_to_free =
> -		     resolve_refdup(branch->merge[0]->dst, RESOLVE_REF_READING,
> +		     resolve_refdup(upstream, RESOLVE_REF_READING,
>  				    sha1, NULL)) != NULL)
>  			reference_rev = lookup_commit_reference(sha1);
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]