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

Re: [PATCH] http-backend: respect GIT_NAMESPACE with dumb clients

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 28, 2013, 06:02 UTC
Message-ID
<7v7gksjc3v.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1364446721-13351-1-git-send-email-jkoleszar@google.com>
John Koleszar <jkoleszar@google.com> writes:
Show 6 quoted lines
> Filter the list of refs returned via the dumb HTTP protocol according
> to the active namespace, consistent with other clients of the
> upload-pack service.
>
> Signed-off-by: John Koleszar <jkoleszar@google.com>
> ---
Looks sane from a cursory read---thanks.
Josh, any comments?
Show 96 quoted lines
>  http-backend.c          |  8 +++++---
>  t/lib-httpd/apache.conf |  5 +++++
>  t/t5561-http-backend.sh |  4 ++++
>  t/t556x_common          | 16 ++++++++++++++++
>  4 files changed, 30 insertions(+), 3 deletions(-)
>
> diff --git a/http-backend.c b/http-backend.c
> index f50e77f..b9896b0 100644
> --- a/http-backend.c
> +++ b/http-backend.c
> @@ -361,17 +361,19 @@ static void run_service(const char **argv)
>  static int show_text_ref(const char *name, const unsigned char *sha1,
>  	int flag, void *cb_data)
>  {
> +	const char *name_nons = strip_namespace(name);
>  	struct strbuf *buf = cb_data;
>  	struct object *o = parse_object(sha1);
>  	if (!o)
>  		return 0;
>  
> -	strbuf_addf(buf, "%s\t%s\n", sha1_to_hex(sha1), name);
> +	strbuf_addf(buf, "%s\t%s\n", sha1_to_hex(sha1), name_nons);
>  	if (o->type == OBJ_TAG) {
>  		o = deref_tag(o, name, 0);
>  		if (!o)
>  			return 0;
> -		strbuf_addf(buf, "%s\t%s^{}\n", sha1_to_hex(o->sha1), name);
> +		strbuf_addf(buf, "%s\t%s^{}\n", sha1_to_hex(o->sha1),
> +		            name_nons);
>  	}
>  	return 0;
>  }
> @@ -402,7 +404,7 @@ static void get_info_refs(char *arg)
>  
>  	} else {
>  		select_getanyfile();
> -		for_each_ref(show_text_ref, &buf);
> +		for_each_namespaced_ref(show_text_ref, &buf);
>  		send_strbuf("text/plain", &buf);
>  	}
>  	strbuf_release(&buf);
> diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf
> index 938b4cf..ad85537 100644
> --- a/t/lib-httpd/apache.conf
> +++ b/t/lib-httpd/apache.conf
> @@ -61,6 +61,11 @@ Alias /auth/dumb/ www/auth/dumb/
>  	SetEnv GIT_COMMITTER_NAME "Custom User"
>  	SetEnv GIT_COMMITTER_EMAIL custom@example.com
>  </LocationMatch>
> +<LocationMatch /smart_namespace/>
> +	SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
> +	SetEnv GIT_HTTP_EXPORT_ALL
> +	SetEnv GIT_NAMESPACE ns
> +</LocationMatch>
>  ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
>  ScriptAlias /broken_smart/ broken-smart-http.sh/
>  <Directory ${GIT_EXEC_PATH}>
> diff --git a/t/t5561-http-backend.sh b/t/t5561-http-backend.sh
> index b5d7fbc..5a19d61 100755
> --- a/t/t5561-http-backend.sh
> +++ b/t/t5561-http-backend.sh
> @@ -134,6 +134,10 @@ POST /smart/repo.git/git-receive-pack HTTP/1.1 200 -
>  ###
>  GET  /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
>  POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
> +
> +###  namespace test
> +###
> +GET  /smart_namespace/repo.git/info/refs HTTP/1.1 200
>  EOF
>  test_expect_success 'server request log matches test results' '
>  	sed -e "
> diff --git a/t/t556x_common b/t/t556x_common
> index 82926cf..cb9eb9d 100755
> --- a/t/t556x_common
> +++ b/t/t556x_common
> @@ -120,3 +120,19 @@ test_expect_success 'http.receivepack false' '
>  	GET info/refs?service=git-receive-pack "403 Forbidden" &&
>  	POST git-receive-pack 0000 "403 Forbidden"
>  '
> +test_expect_success 'backend respects namespaces' '
> +	log_div "namespace test"
> +	config http.uploadpack true &&
> +	config http.getanyfile true &&
> +
> +	GIT_NAMESPACE=ns && export GIT_NAMESPACE &&
> +	git push public master:master &&
> +	(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
> +		git for-each-ref | grep /$GIT_NAMESPACE/ >/dev/null
> +	) &&
> +
> +	git ls-remote public >exp &&  
> +	curl "$HTTPD_URL/smart_namespace/repo.git/info/refs" >act &&
> +	test_cmp exp act &&
> +	(grep /ns/ exp && false || true)
> +'
Previous: John KoleszarNext: Josh Triplett
Message 2 of 26 in “http-backend: respect GIT_NAMESPACE with dumb clients”
  1. http-backend: respect GIT_NAMESPACE with dumb clientsJohn Koleszar, Mar 28, 2013
  2. Junio C HamanoMar 28, 2013
  3. Josh TriplettMar 28, 2013
  4. Junio C HamanoMar 28, 2013
  5. John KoleszarMar 28, 2013
  6. Junio C HamanoMar 28, 2013
  7. http-backend: respect GIT_NAMESPACE with dumb clientsJohn Koleszar, Apr 3, 2013
  8. Jeff KingApr 3, 2013
  9. Jeff KingApr 3, 2013
  10. Junio C HamanoApr 3, 2013
  11. John KoleszarApr 4, 2013
  12. http-backend: respect GIT_NAMESPACE with dumb clientsJohn Koleszar, Apr 4, 2013
  13. Junio C HamanoApr 4, 2013
  14. John KoleszarApr 5, 2013
  15. Josh TriplettApr 5, 2013
  16. Jeff KingApr 5, 2013
  17. Junio C HamanoApr 5, 2013
  18. Jeff KingApr 5, 2013
  19. John KoleszarApr 6, 2013
  20. http-backend: respect GIT_NAMESPACE with dumb clientsJohn Koleszar, Apr 10, 2013
  21. Junio C HamanoApr 10, 2013
  22. Jeff KingApr 10, 2013
  23. Thomas RastApr 8, 2013
  24. Jeff KingApr 8, 2013
  25. John KoleszarApr 9, 2013
  26. Junio C HamanoApr 3, 2013

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.