git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4] receive-pack: Create a HEAD ref for ref namespace

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 15, 2015, 20:48 UTC
Message-ID
<xmqqlhfk7l6l.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1433526142-2413-1-git-send-email-johannes@kyriasis.com>
Johannes Löthberg <johannes@kyriasis.com> writes:
Show 25 quoted lines
> diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
> index d2ec52b..0c18c92 100644
> --- a/builtin/receive-pack.c
> +++ b/builtin/receive-pack.c
> @@ -864,7 +864,9 @@ static const char *update(struct command *cmd, struct shallow_info *si)
>  {
>  	const char *name = cmd->ref_name;
>  	struct strbuf namespaced_name_buf = STRBUF_INIT;
> -	const char *namespaced_name, *ret;
> +	struct strbuf namespaced_head_buf = STRBUF_INIT;
> +	const char *namespaced_name, *ret, *namespace;
> +	const char *namespaced_head_path;
>  	unsigned char *old_sha1 = cmd->old_sha1;
>  	unsigned char *new_sha1 = cmd->new_sha1;
>  
> @@ -981,6 +983,14 @@ static const char *update(struct command *cmd, struct shallow_info *si)
>  		return NULL; /* good */
>  	}
>  	else {
> +		namespace = get_git_namespace();
> +		if (strcmp(namespace, "refs/namespaces/")) {
> +			strbuf_addf(&namespaced_head_buf, "%s%s", namespace, "HEAD");
> +			namespaced_head_path = strbuf_detach(&namespaced_head_buf, NULL);
> +
> +			create_symref(namespaced_head_path, namespaced_name, NULL);

In a normal environment without any namespace, get_git_namespace() will return an empty string, which is not "refs/namespaces/", so we create a symref HEAD (that is .git/HEAD) that points at whatever name the command is about. And this is done every time any ref is updated, flipping the HEAD to point at whatever was pushed the last, isn't it?

Why is this a good change?  I am puzzled...
> +		}
> +
>  		struct strbuf err = STRBUF_INIT;
This adds decl-after-stmt.
Going back to the proposed log message...
> Each ref namespace have their own separate branches, tags, and HEAD, so
> when pushing to a namespace we need to make sure that there exists a
> HEAD ref for the namespace, otherwise you will not be able to check out
> the repo after cloning from a namespace

What this paragraph describes is entirely correct, I think. But I do not think receive-pack is the "we" in that paragraph.

When setting up a "namespace" a and b, shouldn't you be doing essentially

	r=refs/namespaces/
	for ns in a b
        do
		git symbolic-ref $r$ns/HEAD $r$ns/refs/heads/master
	done

or something, which is an equivalent to what "git init" does to a normal repository?

Previous: Johannes LöthbergNext: Johannes Löthberg
Message 21 of 22 in “receive-pack: Create a HEAD ref for ref namespace”
  1. receive-pack: Create a HEAD ref for ref namespaceJohannes Löthberg, Jun 1, 2015
  2. Johannes LöthbergJun 5, 2015
  3. Michael J GruberJun 5, 2015
  4. Johannes LöthbergJun 5, 2015
  5. Johannes LöthbergJun 5, 2015
  6. Fix cloning from ref namespaceJohannes Löthberg, Jun 5, 2015
  7. 1/2 receive-pack: Create a HEAD ref for ref namespaceJohannes Löthberg, Jun 5, 2015
  8. 2/2 t: Add test for cloning from ref namespaceJohannes Löthberg, Jun 5, 2015
  9. Junio C HamanoJun 5, 2015
  10. Johannes LöthbergJun 5, 2015
  11. Junio C HamanoJun 5, 2015
  12. Johannes LöthbergJun 5, 2015
  13. Johannes LöthbergJun 5, 2015
  14. Junio C HamanoJun 5, 2015
  15. receive-pack: Create a HEAD ref for ref namespaceJohannes Löthberg, Jun 5, 2015
  16. Johannes LöthbergJun 5, 2015
  17. Junio C HamanoJun 5, 2015
  18. Johannes LöthbergJun 5, 2015
  19. receive-pack: Create a HEAD ref for ref namespaceJohannes Löthberg, Jun 5, 2015
  20. Johannes LöthbergJun 10, 2015
  21. Junio C HamanoJun 15, 2015
  22. Johannes LöthbergJun 15, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.