From: John Koleszar Date: Wed, 03 Apr 2013 15:52:09 GMT Subject: [PATCH] http-backend: respect GIT_NAMESPACE with dumb clients Message-ID: <1365004329-15264-1-git-send-email-jkoleszar@google.com> In-Reply-To: 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 --- This should incorporate all of Junio's and Josh's comments. Also fixes a bug in the first patch where the HEAD wasn't included in the list of refs returned. PTAL. http-backend.c | 9 ++++++--- t/lib-httpd/apache.conf | 5 +++++ t/t5560-http-backend-noserver.sh | 7 +++++++ t/t5561-http-backend.sh | 11 +++++++++++ t/t556x_common | 25 +++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/http-backend.c b/http-backend.c index f50e77f..d32128f 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,8 @@ static void get_info_refs(char *arg) } else { select_getanyfile(); - for_each_ref(show_text_ref, &buf); + head_ref_namespaced(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 + + SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} + SetEnv GIT_HTTP_EXPORT_ALL + SetEnv GIT_NAMESPACE ns + ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1 ScriptAlias /broken_smart/ broken-smart-http.sh/ diff --git a/t/t5560-http-backend-noserver.sh b/t/t5560-http-backend-noserver.sh index ef98d95..85a5625 100755 --- a/t/t5560-http-backend-noserver.sh +++ b/t/t5560-http-backend-noserver.sh @@ -26,6 +26,13 @@ GET() { test_cmp exp act } +GET_BODY() { + REQUEST_METHOD="GET" && export REQUEST_METHOD && + run_backend "/repo.git/$1" && + sane_unset REQUEST_METHOD && + tr '\015' Q expected && + grep /$NS/ expected >/dev/null && + GET_BODY "info/refs" >actual && + test_cmp expected actual && + GET_BODY "info/refs?service=git-upload-pack" | grep /$NS/ >/dev/null && + + SMART=smart_namespace && + GIT_NAMESPACE=$NS && export GIT_NAMESPACE && + git ls-remote public >expected && + ! grep /$NS/ expected>/dev/null && + GET_BODY "info/refs" >actual && + test_cmp expected actual && + ! (GET_BODY "info/refs?service=git-upload-pack" | grep /$NS/ >/dev/null) +)' -- 1.8.1.3