{"thread":{"id":"21355","subject":"[PATCH 0/5] Updates for git-http-backend","startedAt":"2009-10-25T18:05:30Z","lastAt":"2009-10-28T07:18:38Z","messageCount":8,"participants":["Mark Lodato","Shawn O. Pearce","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"125907","messageId":"1256493935-8680-1-git-send-email-lodatom@gmail.com","threadId":"21355","inReplyTo":null,"subject":"[PATCH 0/5] Updates for git-http-backend","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2009-10-25T18:05:30Z","receivedAt":"2009-10-25T18:05:30Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"This patch series applies to pu.  It adds a GIT_PROJECT_ROOT environment\nvariable, which makes git-http-backend much easier to configure, and it\nupdates the documentation to add more useful examples and to clarify some\nthings.\n\nI originally posted this same series as a single patch in one of the replies\nto Return of Smart HTTP.  Here, I'm posting it as a set of proper series of\npatch, each of which is a unit and has a proper signed-off-by line.\n\nMark Lodato (5):\n  http-backend: add GIT_PROJECT_ROOT environment var\n  http-backend: reword some documentation\n  http-backend: use mod_alias instead of mod_rewrite\n  http-backend: add example for gitweb on same URL\n  http-backend: more explict LocationMatch\n\n Documentation/git-http-backend.txt |   94 +++++++++++++++++++++++-------------\n http-backend.c                     |   25 ++++++++-\n 2 files changed, 83 insertions(+), 36 deletions(-)\n"},{"id":"125908","messageId":"1256493935-8680-2-git-send-email-lodatom@gmail.com","threadId":"21355","inReplyTo":"1256493935-8680-1-git-send-email-lodatom@gmail.com","subject":"[PATCH 1/5] http-backend: add GIT_PROJECT_ROOT environment var","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2009-10-25T18:05:31Z","receivedAt":"2009-10-25T18:05:31Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"Add a new environment variable, GIT_PROJECT_ROOT, to override the\nmethod of using PATH_TRANSLATED to find the git repository on disk.\nThis makes it much easier to configure the web server, especially when\nthe web server's DocumentRoot does not contain the git repositories,\nwhich is the usual case.\n\nSigned-off-by: Mark Lodato <lodatom@gmail.com>\n---\n Documentation/git-http-backend.txt |   39 +++++++++++++++--------------------\n http-backend.c                     |   25 ++++++++++++++++++++--\n 2 files changed, 39 insertions(+), 25 deletions(-)\n\ndiff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt\nindex 022a243..99dbbfb 100644\n--- a/Documentation/git-http-backend.txt\n+++ b/Documentation/git-http-backend.txt\n@@ -41,29 +41,24 @@ http.receivepack::\n \n URL TRANSLATION\n ---------------\n-'git-http-backend' relies on the invoking web server to perform\n-URL to path translation, and store the repository path into the\n-PATH_TRANSLATED environment variable.  Most web servers will do\n-this translation automatically, resolving the suffix after the\n-CGI name relative to the server's document root.\n+To determine the location of the repository on disk, 'git-http-backend'\n+concatenates the environment variables PATH_INFO, which is set\n+automatically by the web server, and GIT_PROJECT_ROOT, which must be set\n+manually in the web server configuration.  If GIT_PROJECT_ROOT is not\n+set, 'git-http-backend' reads PATH_TRANSLATED, which is also set\n+automatically by the web server.\n \n EXAMPLES\n --------\n \n Apache 2.x::\n-\tTo serve all Git repositories contained within the '/git/'\n-\tsubdirectory of the DocumentRoot, ensure mod_cgi and\n-\tmod_alias are enabled, and create a ScriptAlias to the CGI:\n+\tEnsure mod_cgi, mod_alias, and mod_env are enabled, set\n+\tGIT_PROJECT_ROOT (or DocumentRoot) appropriately, and\n+\tcreate a ScriptAlias to the CGI:\n +\n ----------------------------------------------------------------\n-ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/git/\n-\n-<Directory /usr/libexec/git-core>\n-\tOptions None\n-</Directory>\n-<Files /usr/libexec/git-core/git-http-backend>\n-\tOptions ExecCGI\n-</Files>\n+SetEnv GIT_PROJECT_ROOT /var/www/git\n+ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/\n ----------------------------------------------------------------\n +\n To enable anonymous read access but authenticated write access,\n@@ -78,16 +73,16 @@ require authorization with a LocationMatch directive:\n </LocationMatch>\n ----------------------------------------------------------------\n +\n-To require authentication for both reads and writes, use a Directory\n+To require authentication for both reads and writes, use a Location\n directive around the repository, or one of its parent directories:\n +\n ----------------------------------------------------------------\n-<Directory /var/www/git/private>\n+<Location /git/private>\n \tAuthType Basic\n \tAuthName \"Private Git Access\"\n \tRequire group committers\n \t...\n-</Directory>\n+</Location>\n ----------------------------------------------------------------\n \n Accelerated static Apache 2.x::\n@@ -97,9 +92,9 @@ Accelerated static Apache 2.x::\n \tfile contents from the file system directly to the network:\n +\n ----------------------------------------------------------------\n-DocumentRoot /var/www\n+SetEnv GIT_PROJECT_ROOT /var/www/git\n \n-ScriptAlias /git/        /usr/libexec/git-core/git-http-backend/git/\n+ScriptAlias /git/        /usr/libexec/git-core/git-http-backend/\n Alias       /git_static/ /var/www/git/\n \n RewriteEngine on\n@@ -114,7 +109,7 @@ ENVIRONMENT\n 'git-http-backend' relies upon the CGI environment variables set\n by the invoking web server, including:\n \n-* PATH_TRANSLATED\n+* PATH_INFO (if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED)\n * REMOTE_USER\n * REMOTE_ADDR\n * CONTENT_TYPE\ndiff --git a/http-backend.c b/http-backend.c\nindex 67030b5..8e5c0a2 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -528,6 +528,26 @@ static NORETURN void die_webcgi(const char *err, va_list params)\n \texit(0);\n }\n \n+static char* getdir(void)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tchar *pathinfo = getenv(\"PATH_INFO\");\n+\tchar *root = getenv(\"GIT_PROJECT_ROOT\");\n+\tchar *path = getenv(\"PATH_TRANSLATED\");\n+\n+\tif (root && *root) {\n+\t\tif (!pathinfo || !*pathinfo)\n+\t\t\tdie(\"GIT_PROJECT_ROOT is set but PATH_INFO is not\");\n+\t\tstrbuf_addstr(&buf, root);\n+\t\tstrbuf_addstr(&buf, pathinfo);\n+\t\treturn strbuf_detach(&buf, NULL);\n+\t} else if (path && *path) {\n+\t\treturn xstrdup(path);\n+\t} else\n+\t\tdie(\"No GIT_PROJECT_ROOT or PATH_TRANSLATED from server\");\n+\treturn NULL;\n+}\n+\n static struct service_cmd {\n \tconst char *method;\n \tconst char *pattern;\n@@ -550,7 +570,7 @@ static struct service_cmd {\n int main(int argc, char **argv)\n {\n \tchar *method = getenv(\"REQUEST_METHOD\");\n-\tchar *dir = getenv(\"PATH_TRANSLATED\");\n+\tchar *dir;\n \tstruct service_cmd *cmd = NULL;\n \tchar *cmd_arg = NULL;\n \tint i;\n@@ -562,8 +582,7 @@ int main(int argc, char **argv)\n \t\tdie(\"No REQUEST_METHOD from server\");\n \tif (!strcmp(method, \"HEAD\"))\n \t\tmethod = \"GET\";\n-\tif (!dir)\n-\t\tdie(\"No PATH_TRANSLATED from server\");\n+\tdir = getdir();\n \n \tfor (i = 0; i < ARRAY_SIZE(services); i++) {\n \t\tstruct service_cmd *c = &services[i];\n-- \n1.6.5.1\n"},{"id":"125910","messageId":"1256493935-8680-3-git-send-email-lodatom@gmail.com","threadId":"21355","inReplyTo":"1256493935-8680-2-git-send-email-lodatom@gmail.com","subject":"[PATCH 2/5] http-backend: reword some documentation","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2009-10-25T18:05:32Z","receivedAt":"2009-10-25T18:05:32Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"Clarify some of the git-http-backend documentation, particularly:\n\n* In the Description, state that smart/dumb HTTP fetch and smart HTTP\n  push are supported, state that authenticated clients allow push, and\n  remove the note that this is only suited for read-only updates.\n\n* At the start of Examples, state explicitly what URL is mapping to what\n  location on disk.\n\nSigned-off-by: Mark Lodato <lodatom@gmail.com>\n---\n Documentation/git-http-backend.txt |   12 ++++++++----\n 1 files changed, 8 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt\nindex 99dbbfb..0b5e951 100644\n--- a/Documentation/git-http-backend.txt\n+++ b/Documentation/git-http-backend.txt\n@@ -14,13 +14,15 @@ DESCRIPTION\n -----------\n A simple CGI program to serve the contents of a Git repository to Git\n clients accessing the repository over http:// and https:// protocols.\n+The program supports clients fetching using both the smart HTTP protcol\n+and the backwards-compatible dumb HTTP protocol, as well as clients\n+pushing using the smart HTTP protocol.\n \n By default, only the `upload-pack` service is enabled, which serves\n 'git-fetch-pack' and 'git-ls-remote' clients, which are invoked from\n-'git-fetch', 'git-pull', and 'git-clone'.\n-\n-This is ideally suited for read-only updates, i.e., pulling from\n-git repositories.\n+'git-fetch', 'git-pull', and 'git-clone'.  If the client is authenticated,\n+the `receive-pack` service is enabled, which serves 'git-send-pack'\n+clients, which is invoked from 'git-push'.\n \n SERVICES\n --------\n@@ -50,6 +52,8 @@ automatically by the web server.\n \n EXAMPLES\n --------\n+All of the following examples map 'http://$hostname/git/foo/bar.git'\n+to '/var/www/git/foo/bar.git'.\n \n Apache 2.x::\n \tEnsure mod_cgi, mod_alias, and mod_env are enabled, set\n-- \n1.6.5.1\n"},{"id":"125911","messageId":"1256493935-8680-4-git-send-email-lodatom@gmail.com","threadId":"21355","inReplyTo":"1256493935-8680-3-git-send-email-lodatom@gmail.com","subject":"[PATCH 3/5] http-backend: use mod_alias instead of mod_rewrite","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2009-10-25T18:05:33Z","receivedAt":"2009-10-25T18:05:33Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"In the git-http-backend documentation, use mod_alias exlusively, instead\nof using a combination of mod_alias and mod_rewrite.  This makes the\nexample slightly shorted and a bit more clear.\n\nSigned-off-by: Mark Lodato <lodatom@gmail.com>\n---\n Documentation/git-http-backend.txt |   10 +++-------\n 1 files changed, 3 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt\nindex 0b5e951..e67519d 100644\n--- a/Documentation/git-http-backend.txt\n+++ b/Documentation/git-http-backend.txt\n@@ -98,13 +98,9 @@ Accelerated static Apache 2.x::\n ----------------------------------------------------------------\n SetEnv GIT_PROJECT_ROOT /var/www/git\n \n-ScriptAlias /git/        /usr/libexec/git-core/git-http-backend/\n-Alias       /git_static/ /var/www/git/\n-\n-RewriteEngine on\n-RewriteRule ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$    /git_static/$1 [PT]\n-RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.pack)$ /git_static/$1 [PT]\n-RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.idx)$  /git_static/$1 [PT]\n+AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$          /var/www/git/$1\n+AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1\n+ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/\n ----------------------------------------------------------------\n \n \n-- \n1.6.5.1\n"},{"id":"125909","messageId":"1256493935-8680-5-git-send-email-lodatom@gmail.com","threadId":"21355","inReplyTo":"1256493935-8680-4-git-send-email-lodatom@gmail.com","subject":"[PATCH 4/5] http-backend: add example for gitweb on same URL","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2009-10-25T18:05:34Z","receivedAt":"2009-10-25T18:05:34Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"In the git-http-backend documentation, add an example of how to set up\ngitweb and git-http-backend on the same URL by using a series of\nmod_alias commands.\n\nSigned-off-by: Mark Lodato <lodatom@gmail.com>\n---\n Documentation/git-http-backend.txt |   33 +++++++++++++++++++++++++++++++++\n 1 files changed, 33 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt\nindex e67519d..2989c9f 100644\n--- a/Documentation/git-http-backend.txt\n+++ b/Documentation/git-http-backend.txt\n@@ -88,6 +88,23 @@ directive around the repository, or one of its parent directories:\n \t...\n </Location>\n ----------------------------------------------------------------\n++\n+To serve gitweb at the same url, use a ScriptAliasMatch to only\n+those URLs that 'git-http-backend' can handle, and forward the\n+rest to gitweb:\n++\n+----------------------------------------------------------------\n+ScriptAliasMatch \\\n+\t\"(?x)^/git/(.*/(HEAD | \\\n+\t\t\tinfo/refs | \\\n+\t\t\tobjects/(info/[^/]+ | \\\n+\t\t\t\t [0-9a-f]{2}/[0-9a-f]{38} | \\\n+\t\t\t\t pack/pack-[0-9a-f]{40}\\.(pack|idx)) | \\\n+\t\t\tgit-(upload|receive)-pack))$\" \\\n+\t/usr/libexec/git-core/git-http-backend/$1\n+\n+ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/\n+----------------------------------------------------------------\n \n Accelerated static Apache 2.x::\n \tSimilar to the above, but Apache can be used to return static\n@@ -102,6 +119,22 @@ AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$          /var/www/git/$1\n AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1\n ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/\n ----------------------------------------------------------------\n++\n+This can be combined with the gitweb configuration:\n++\n+----------------------------------------------------------------\n+SetEnv GIT_PROJECT_ROOT /var/www/git\n+\n+AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$          /var/www/git/$1\n+AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1\n+ScriptAliasMatch \\\n+\t\"(?x)^/git/(.*/(HEAD | \\\n+\t\t\tinfo/refs | \\\n+\t\t\tobjects/info/[^/]+ | \\\n+\t\t\tgit-(upload|receive)-pack))$\" \\\n+\t/usr/libexec/git-core/git-http-backend/$1\n+ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/\n+----------------------------------------------------------------\n \n \n ENVIRONMENT\n-- \n1.6.5.1\n"},{"id":"125912","messageId":"1256493935-8680-6-git-send-email-lodatom@gmail.com","threadId":"21355","inReplyTo":"1256493935-8680-5-git-send-email-lodatom@gmail.com","subject":"[PATCH 5/5] http-backend: more explict LocationMatch","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2009-10-25T18:05:35Z","receivedAt":"2009-10-25T18:05:35Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"In the git-http-backend examples, only match git-receive-pack within\n/git/.\n\nSigned-off-by: Mark Lodato <lodatom@gmail.com>\n---\n Documentation/git-http-backend.txt |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt\nindex 2989c9f..f17251a 100644\n--- a/Documentation/git-http-backend.txt\n+++ b/Documentation/git-http-backend.txt\n@@ -69,7 +69,7 @@ To enable anonymous read access but authenticated write access,\n require authorization with a LocationMatch directive:\n +\n ----------------------------------------------------------------\n-<LocationMatch \".*/git-receive-pack$\">\n+<LocationMatch \"^/git/.*/git-receive-pack$\">\n \tAuthType Basic\n \tAuthName \"Git Access\"\n \tRequire group committers\n-- \n1.6.5.1\n"},{"id":"126062","messageId":"20091027222435.GJ10505@spearce.org","threadId":"21355","inReplyTo":"1256493935-8680-6-git-send-email-lodatom@gmail.com","subject":"Re: [PATCH 5/5] http-backend: more explict LocationMatch","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-27T22:24:35Z","receivedAt":"2009-10-27T22:24:35Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Mark Lodato <lodatom@gmail.com> wrote:\n> In the git-http-backend examples, only match git-receive-pack within\n> /git/.\n\nAll 5 patches:\n\nAcked-by: Shawn O. Pearce <spearce@spearce.org>\n\nJunio, add these to my smart-http topic please.  :-)\nThanks Mark!\n\n-- \nShawn.\n"},{"id":"126101","messageId":"7vzl7crnox.fsf@alter.siamese.dyndns.org","threadId":"21355","inReplyTo":"20091027222435.GJ10505@spearce.org","subject":"Re: [PATCH 5/5] http-backend: more explict LocationMatch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-28T07:18:38Z","receivedAt":"2009-10-28T07:18:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> Mark Lodato <lodatom@gmail.com> wrote:\n>> In the git-http-backend examples, only match git-receive-pack within\n>> /git/.\n>\n> All 5 patches:\n>\n> Acked-by: Shawn O. Pearce <spearce@spearce.org>\n>\n> Junio, add these to my smart-http topic please.  :-)\n> Thanks Mark!\n\nThanks.\n"}]}