git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/5] Updates for git-http-backend
@ 2009-10-25 18:05 Mark Lodato
  2009-10-25 18:05 ` [PATCH 1/5] http-backend: add GIT_PROJECT_ROOT environment var Mark Lodato
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Lodato @ 2009-10-25 18:05 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano, Shawn O. Pearce, Mark Lodato

This patch series applies to pu.  It adds a GIT_PROJECT_ROOT environment
variable, which makes git-http-backend much easier to configure, and it
updates the documentation to add more useful examples and to clarify some
things.

I originally posted this same series as a single patch in one of the replies
to Return of Smart HTTP.  Here, I'm posting it as a set of proper series of
patch, each of which is a unit and has a proper signed-off-by line.

Mark Lodato (5):
  http-backend: add GIT_PROJECT_ROOT environment var
  http-backend: reword some documentation
  http-backend: use mod_alias instead of mod_rewrite
  http-backend: add example for gitweb on same URL
  http-backend: more explict LocationMatch

 Documentation/git-http-backend.txt |   94 +++++++++++++++++++++++-------------
 http-backend.c                     |   25 ++++++++-
 2 files changed, 83 insertions(+), 36 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/5] http-backend: add GIT_PROJECT_ROOT environment var
  2009-10-25 18:05 [PATCH 0/5] Updates for git-http-backend Mark Lodato
@ 2009-10-25 18:05 ` Mark Lodato
  2009-10-25 18:05   ` [PATCH 2/5] http-backend: reword some documentation Mark Lodato
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Lodato @ 2009-10-25 18:05 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano, Shawn O. Pearce, Mark Lodato

Add a new environment variable, GIT_PROJECT_ROOT, to override the
method of using PATH_TRANSLATED to find the git repository on disk.
This makes it much easier to configure the web server, especially when
the web server's DocumentRoot does not contain the git repositories,
which is the usual case.

Signed-off-by: Mark Lodato <lodatom@gmail.com>
---
 Documentation/git-http-backend.txt |   39 +++++++++++++++--------------------
 http-backend.c                     |   25 ++++++++++++++++++++--
 2 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt
index 022a243..99dbbfb 100644
--- a/Documentation/git-http-backend.txt
+++ b/Documentation/git-http-backend.txt
@@ -41,29 +41,24 @@ http.receivepack::
 
 URL TRANSLATION
 ---------------
-'git-http-backend' relies on the invoking web server to perform
-URL to path translation, and store the repository path into the
-PATH_TRANSLATED environment variable.  Most web servers will do
-this translation automatically, resolving the suffix after the
-CGI name relative to the server's document root.
+To determine the location of the repository on disk, 'git-http-backend'
+concatenates the environment variables PATH_INFO, which is set
+automatically by the web server, and GIT_PROJECT_ROOT, which must be set
+manually in the web server configuration.  If GIT_PROJECT_ROOT is not
+set, 'git-http-backend' reads PATH_TRANSLATED, which is also set
+automatically by the web server.
 
 EXAMPLES
 --------
 
 Apache 2.x::
-	To serve all Git repositories contained within the '/git/'
-	subdirectory of the DocumentRoot, ensure mod_cgi and
-	mod_alias are enabled, and create a ScriptAlias to the CGI:
+	Ensure mod_cgi, mod_alias, and mod_env are enabled, set
+	GIT_PROJECT_ROOT (or DocumentRoot) appropriately, and
+	create a ScriptAlias to the CGI:
 +
 ----------------------------------------------------------------
-ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/git/
-
-<Directory /usr/libexec/git-core>
-	Options None
-</Directory>
-<Files /usr/libexec/git-core/git-http-backend>
-	Options ExecCGI
-</Files>
+SetEnv GIT_PROJECT_ROOT /var/www/git
+ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
 ----------------------------------------------------------------
 +
 To enable anonymous read access but authenticated write access,
@@ -78,16 +73,16 @@ require authorization with a LocationMatch directive:
 </LocationMatch>
 ----------------------------------------------------------------
 +
-To require authentication for both reads and writes, use a Directory
+To require authentication for both reads and writes, use a Location
 directive around the repository, or one of its parent directories:
 +
 ----------------------------------------------------------------
-<Directory /var/www/git/private>
+<Location /git/private>
 	AuthType Basic
 	AuthName "Private Git Access"
 	Require group committers
 	...
-</Directory>
+</Location>
 ----------------------------------------------------------------
 
 Accelerated static Apache 2.x::
@@ -97,9 +92,9 @@ Accelerated static Apache 2.x::
 	file contents from the file system directly to the network:
 +
 ----------------------------------------------------------------
-DocumentRoot /var/www
+SetEnv GIT_PROJECT_ROOT /var/www/git
 
-ScriptAlias /git/        /usr/libexec/git-core/git-http-backend/git/
+ScriptAlias /git/        /usr/libexec/git-core/git-http-backend/
 Alias       /git_static/ /var/www/git/
 
 RewriteEngine on
@@ -114,7 +109,7 @@ ENVIRONMENT
 'git-http-backend' relies upon the CGI environment variables set
 by the invoking web server, including:
 
-* PATH_TRANSLATED
+* PATH_INFO (if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED)
 * REMOTE_USER
 * REMOTE_ADDR
 * CONTENT_TYPE
diff --git a/http-backend.c b/http-backend.c
index 67030b5..8e5c0a2 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -528,6 +528,26 @@ static NORETURN void die_webcgi(const char *err, va_list params)
 	exit(0);
 }
 
+static char* getdir(void)
+{
+	struct strbuf buf = STRBUF_INIT;
+	char *pathinfo = getenv("PATH_INFO");
+	char *root = getenv("GIT_PROJECT_ROOT");
+	char *path = getenv("PATH_TRANSLATED");
+
+	if (root && *root) {
+		if (!pathinfo || !*pathinfo)
+			die("GIT_PROJECT_ROOT is set but PATH_INFO is not");
+		strbuf_addstr(&buf, root);
+		strbuf_addstr(&buf, pathinfo);
+		return strbuf_detach(&buf, NULL);
+	} else if (path && *path) {
+		return xstrdup(path);
+	} else
+		die("No GIT_PROJECT_ROOT or PATH_TRANSLATED from server");
+	return NULL;
+}
+
 static struct service_cmd {
 	const char *method;
 	const char *pattern;
@@ -550,7 +570,7 @@ static struct service_cmd {
 int main(int argc, char **argv)
 {
 	char *method = getenv("REQUEST_METHOD");
-	char *dir = getenv("PATH_TRANSLATED");
+	char *dir;
 	struct service_cmd *cmd = NULL;
 	char *cmd_arg = NULL;
 	int i;
@@ -562,8 +582,7 @@ int main(int argc, char **argv)
 		die("No REQUEST_METHOD from server");
 	if (!strcmp(method, "HEAD"))
 		method = "GET";
-	if (!dir)
-		die("No PATH_TRANSLATED from server");
+	dir = getdir();
 
 	for (i = 0; i < ARRAY_SIZE(services); i++) {
 		struct service_cmd *c = &services[i];
-- 
1.6.5.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/5] http-backend: reword some documentation
  2009-10-25 18:05 ` [PATCH 1/5] http-backend: add GIT_PROJECT_ROOT environment var Mark Lodato
@ 2009-10-25 18:05   ` Mark Lodato
  2009-10-25 18:05     ` [PATCH 3/5] http-backend: use mod_alias instead of mod_rewrite Mark Lodato
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Lodato @ 2009-10-25 18:05 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano, Shawn O. Pearce, Mark Lodato

Clarify some of the git-http-backend documentation, particularly:

* In the Description, state that smart/dumb HTTP fetch and smart HTTP
  push are supported, state that authenticated clients allow push, and
  remove the note that this is only suited for read-only updates.

* At the start of Examples, state explicitly what URL is mapping to what
  location on disk.

Signed-off-by: Mark Lodato <lodatom@gmail.com>
---
 Documentation/git-http-backend.txt |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt
index 99dbbfb..0b5e951 100644
--- a/Documentation/git-http-backend.txt
+++ b/Documentation/git-http-backend.txt
@@ -14,13 +14,15 @@ DESCRIPTION
 -----------
 A simple CGI program to serve the contents of a Git repository to Git
 clients accessing the repository over http:// and https:// protocols.
+The program supports clients fetching using both the smart HTTP protcol
+and the backwards-compatible dumb HTTP protocol, as well as clients
+pushing using the smart HTTP protocol.
 
 By default, only the `upload-pack` service is enabled, which serves
 'git-fetch-pack' and 'git-ls-remote' clients, which are invoked from
-'git-fetch', 'git-pull', and 'git-clone'.
-
-This is ideally suited for read-only updates, i.e., pulling from
-git repositories.
+'git-fetch', 'git-pull', and 'git-clone'.  If the client is authenticated,
+the `receive-pack` service is enabled, which serves 'git-send-pack'
+clients, which is invoked from 'git-push'.
 
 SERVICES
 --------
@@ -50,6 +52,8 @@ automatically by the web server.
 
 EXAMPLES
 --------
+All of the following examples map 'http://$hostname/git/foo/bar.git'
+to '/var/www/git/foo/bar.git'.
 
 Apache 2.x::
 	Ensure mod_cgi, mod_alias, and mod_env are enabled, set
-- 
1.6.5.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/5] http-backend: use mod_alias instead of mod_rewrite
  2009-10-25 18:05   ` [PATCH 2/5] http-backend: reword some documentation Mark Lodato
@ 2009-10-25 18:05     ` Mark Lodato
  2009-10-25 18:05       ` [PATCH 4/5] http-backend: add example for gitweb on same URL Mark Lodato
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Lodato @ 2009-10-25 18:05 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano, Shawn O. Pearce, Mark Lodato

In the git-http-backend documentation, use mod_alias exlusively, instead
of using a combination of mod_alias and mod_rewrite.  This makes the
example slightly shorted and a bit more clear.

Signed-off-by: Mark Lodato <lodatom@gmail.com>
---
 Documentation/git-http-backend.txt |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt
index 0b5e951..e67519d 100644
--- a/Documentation/git-http-backend.txt
+++ b/Documentation/git-http-backend.txt
@@ -98,13 +98,9 @@ Accelerated static Apache 2.x::
 ----------------------------------------------------------------
 SetEnv GIT_PROJECT_ROOT /var/www/git
 
-ScriptAlias /git/        /usr/libexec/git-core/git-http-backend/
-Alias       /git_static/ /var/www/git/
-
-RewriteEngine on
-RewriteRule ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$    /git_static/$1 [PT]
-RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.pack)$ /git_static/$1 [PT]
-RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.idx)$  /git_static/$1 [PT]
+AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$          /var/www/git/$1
+AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1
+ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
 ----------------------------------------------------------------
 
 
-- 
1.6.5.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/5] http-backend: add example for gitweb on same URL
  2009-10-25 18:05     ` [PATCH 3/5] http-backend: use mod_alias instead of mod_rewrite Mark Lodato
@ 2009-10-25 18:05       ` Mark Lodato
  2009-10-25 18:05         ` [PATCH 5/5] http-backend: more explict LocationMatch Mark Lodato
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Lodato @ 2009-10-25 18:05 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano, Shawn O. Pearce, Mark Lodato

In the git-http-backend documentation, add an example of how to set up
gitweb and git-http-backend on the same URL by using a series of
mod_alias commands.

Signed-off-by: Mark Lodato <lodatom@gmail.com>
---
 Documentation/git-http-backend.txt |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt
index e67519d..2989c9f 100644
--- a/Documentation/git-http-backend.txt
+++ b/Documentation/git-http-backend.txt
@@ -88,6 +88,23 @@ directive around the repository, or one of its parent directories:
 	...
 </Location>
 ----------------------------------------------------------------
++
+To serve gitweb at the same url, use a ScriptAliasMatch to only
+those URLs that 'git-http-backend' can handle, and forward the
+rest to gitweb:
++
+----------------------------------------------------------------
+ScriptAliasMatch \
+	"(?x)^/git/(.*/(HEAD | \
+			info/refs | \
+			objects/(info/[^/]+ | \
+				 [0-9a-f]{2}/[0-9a-f]{38} | \
+				 pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
+			git-(upload|receive)-pack))$" \
+	/usr/libexec/git-core/git-http-backend/$1
+
+ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/
+----------------------------------------------------------------
 
 Accelerated static Apache 2.x::
 	Similar to the above, but Apache can be used to return static
@@ -102,6 +119,22 @@ AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$          /var/www/git/$1
 AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1
 ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
 ----------------------------------------------------------------
++
+This can be combined with the gitweb configuration:
++
+----------------------------------------------------------------
+SetEnv GIT_PROJECT_ROOT /var/www/git
+
+AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$          /var/www/git/$1
+AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1
+ScriptAliasMatch \
+	"(?x)^/git/(.*/(HEAD | \
+			info/refs | \
+			objects/info/[^/]+ | \
+			git-(upload|receive)-pack))$" \
+	/usr/libexec/git-core/git-http-backend/$1
+ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/
+----------------------------------------------------------------
 
 
 ENVIRONMENT
-- 
1.6.5.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/5] http-backend: more explict LocationMatch
  2009-10-25 18:05       ` [PATCH 4/5] http-backend: add example for gitweb on same URL Mark Lodato
@ 2009-10-25 18:05         ` Mark Lodato
  2009-10-27 22:24           ` Shawn O. Pearce
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Lodato @ 2009-10-25 18:05 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano, Shawn O. Pearce, Mark Lodato

In the git-http-backend examples, only match git-receive-pack within
/git/.

Signed-off-by: Mark Lodato <lodatom@gmail.com>
---
 Documentation/git-http-backend.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt
index 2989c9f..f17251a 100644
--- a/Documentation/git-http-backend.txt
+++ b/Documentation/git-http-backend.txt
@@ -69,7 +69,7 @@ To enable anonymous read access but authenticated write access,
 require authorization with a LocationMatch directive:
 +
 ----------------------------------------------------------------
-<LocationMatch ".*/git-receive-pack$">
+<LocationMatch "^/git/.*/git-receive-pack$">
 	AuthType Basic
 	AuthName "Git Access"
 	Require group committers
-- 
1.6.5.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 5/5] http-backend: more explict LocationMatch
  2009-10-25 18:05         ` [PATCH 5/5] http-backend: more explict LocationMatch Mark Lodato
@ 2009-10-27 22:24           ` Shawn O. Pearce
  2009-10-28  7:18             ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Shawn O. Pearce @ 2009-10-27 22:24 UTC (permalink / raw
  To: Mark Lodato; +Cc: git, Junio C Hamano

Mark Lodato <lodatom@gmail.com> wrote:
> In the git-http-backend examples, only match git-receive-pack within
> /git/.

All 5 patches:

Acked-by: Shawn O. Pearce <spearce@spearce.org>

Junio, add these to my smart-http topic please.  :-)
Thanks Mark!

-- 
Shawn.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5/5] http-backend: more explict LocationMatch
  2009-10-27 22:24           ` Shawn O. Pearce
@ 2009-10-28  7:18             ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2009-10-28  7:18 UTC (permalink / raw
  To: Shawn O. Pearce; +Cc: Mark Lodato, git, Junio C Hamano

"Shawn O. Pearce" <spearce@spearce.org> writes:

> Mark Lodato <lodatom@gmail.com> wrote:
>> In the git-http-backend examples, only match git-receive-pack within
>> /git/.
>
> All 5 patches:
>
> Acked-by: Shawn O. Pearce <spearce@spearce.org>
>
> Junio, add these to my smart-http topic please.  :-)
> Thanks Mark!

Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-10-28  7:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-25 18:05 [PATCH 0/5] Updates for git-http-backend Mark Lodato
2009-10-25 18:05 ` [PATCH 1/5] http-backend: add GIT_PROJECT_ROOT environment var Mark Lodato
2009-10-25 18:05   ` [PATCH 2/5] http-backend: reword some documentation Mark Lodato
2009-10-25 18:05     ` [PATCH 3/5] http-backend: use mod_alias instead of mod_rewrite Mark Lodato
2009-10-25 18:05       ` [PATCH 4/5] http-backend: add example for gitweb on same URL Mark Lodato
2009-10-25 18:05         ` [PATCH 5/5] http-backend: more explict LocationMatch Mark Lodato
2009-10-27 22:24           ` Shawn O. Pearce
2009-10-28  7:18             ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).