Subject: Re: [PATCH 1/3] upload-pack: send the HEAD information

From: Junio C Hamano <[email-masked]>
Date: Fri, 06 Sep 2013 10:46:24 -0700

Andreas Krey <[email-masked]> writes:

> From: Junio C Hamano <[email-masked]>
>
> This implements the server side of protocol extension to show which branch
> the HEAD points at.  The information is sent as a capability symref=<target>.
>
> Signed-off-by: Junio C Hamano <[email-masked]>
> Signed-off-by: Andreas Krey <[email-masked]>
> ---
>  upload-pack.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/upload-pack.c b/upload-pack.c
> index 127e59a..390d1ec 100644
> --- a/upload-pack.c
> +++ b/upload-pack.c
> @@ -745,13 +745,17 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
>  	if (mark_our_ref(refname, sha1, flag, cb_data))
>  		return 0;
>  
> -	if (capabilities)
> -		packet_write(1, "%s %s%c%s%s%s agent=%s\n",
> +	if (capabilities) {
> +		unsigned char dummy[20];
> +		const char *target = resolve_ref_unsafe("HEAD", dummy, 0, NULL);
> +		packet_write(1, "%s %s%c%s%s%s%s%s agent=%s\n",
>  			     sha1_to_hex(sha1), refname_nons,
>  			     0, capabilities,
>  			     allow_tip_sha1_in_want ? " allow-tip-sha1-in-want" : "",
>  			     stateless_rpc ? " no-done" : "",
> +			     target ? " symref=" : "", target ? target : 0,
>  			     git_user_agent_sanitized());
> +	}
>  	else
>  		packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons);
>  	capabilities = NULL;

I think it is perfectly fine to expose _only_ HEAD now, and wait
until we find a good reason that we should send this information for
other symbolic refs in the repository.

However, because we already anticipate that we may find such a good
reason later, on-the-wire format should be prepared to support such
later enhancement.  I think sending

	symref=HEAD:refs/heads/master

is probably one good way to do so, as Peff suggested in that old
thread ($gmane/102070; note that back then this wasn't suggested as
a proper capability so the exact format he suggests in the message
is different).  Then we could later add advertisements for other
symbolic refs if we find it necessary to do so, e.g.

	symref=HEAD:refs/heads/master
        symref=refs/remotes/origin/HEAD:refs/remotes/origin/master

(all on one line together with other capabilities separated with a
SP in between).