# [PATCH] Add a --prefix option to git-daemon

3 messages from 2005-10-25 to 2005-10-25. Participants: Brad Roberts, Junio C Hamano, Petr Baudis.
Thread: https://gitlist.dev/t/2214

## Brad Roberts, 2005-10-25 07:08

Subject: [PATCH] Add a --prefix option to git-daemon
Message-ID: <200510250708.j9P78pG3024087@gameboy2.puremagic.com>
URL: https://gitlist.dev/e/200510250708.j9P78pG3024087%40gameboy2.puremagic.com

```
Add a --prefix option to git-daemon.  This path is prepended to the search
path for repositories.  In other words, git://hostname/path/to/gitdir will
result in looking for /prefix/path/to/gitdir.

Signed-off-by: Brad Roberts <braddr@puremagic.com>
---

 daemon.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

applies-to: ccef5ac580c68a9714f37dcd8ee433e9691b640a
4ab5253ba31370d151843ca14a8cabcadc37c974
diff --git a/daemon.c b/daemon.c
index 0c6182f..566bec6 100644
--- a/daemon.c
+++ b/daemon.c
@@ -15,7 +15,7 @@ static int verbose;
 
 static const char daemon_usage[] =
 "git-daemon [--verbose] [--syslog] [--inetd | --port=n] [--export-all]\n"
-"           [--timeout=n] [--init-timeout=n] [directory...]";
+"           [--timeout=n] [--init-timeout=n] [--prefix=directory] [directory...]";
 
 /* List of acceptable pathname prefixes */
 static char **ok_paths = NULL;
@@ -27,6 +27,9 @@ static int export_all_trees = 0;
 static unsigned int timeout = 0;
 static unsigned int init_timeout = 0;
 
+/* directory prefix for all repositories */
+static const char *directory_prefix = "";
+
 static void logreport(int priority, const char *err, va_list params)
 {
 	/* We should do a single write so that it is atomic and output
@@ -170,10 +173,10 @@ static int set_dir(const char *dir)
 static int upload(char *dir)
 {
 	/* Try paths in this order */
-	static const char *paths[] = { "%s", "%s/.git", "%s.git", "%s.git/.git", NULL };
+	static const char *paths[] = { "%s%s", "%s%s/.git", "%s%s.git", "%s%s.git/.git", NULL };
 	const char **pp;
 	/* Enough for the longest path above including final null */
-	int buflen = strlen(dir)+10;
+	int buflen = strlen(dir)+strlen(directory_prefix)+10;
 	char *dirbuf = xmalloc(buflen);
 	/* Timeout as string */
 	char timeout_buf[64];
@@ -181,7 +184,7 @@ static int upload(char *dir)
 	loginfo("Request for '%s'", dir);
 
 	for ( pp = paths ; *pp ; pp++ ) {
-		snprintf(dirbuf, buflen, *pp, dir);
+		snprintf(dirbuf, buflen, *pp, directory_prefix, dir);
 		if ( !set_dir(dirbuf) )
 			break;
 	}
@@ -615,6 +618,10 @@ int main(int argc, char **argv)
 		if (!strncmp(arg, "--init-timeout=", 15)) {
 			init_timeout = atoi(arg+15);
 		}
+		if (!strncmp(arg, "--prefix=", 9)) {
+			directory_prefix = arg+9;
+			continue;
+		}
 		if (!strcmp(arg, "--")) {
 			ok_paths = &argv[i+1];
 			break;
---
0.99.8.GIT

```

## Junio C Hamano, 2005-10-25 07:42

Subject: Re: [PATCH] Add a --prefix option to git-daemon
Message-ID: <7virvmjb4s.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7virvmjb4s.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <200510250708.j9P78pG3024087@gameboy2.puremagic.com>

```
Brad Roberts <braddr@gameboy2.puremagic.com> writes:

> Add a --prefix option to git-daemon.

What is your thought about my RFC last night [*1*], and how does
this patch address the concern raised in it, specifically what
is the plan for this --prefix option to work together with
upload-pack?

[Reference]

*1* http://marc.theaimsgroup.com/?l=git&m=113014402715697&w=2

```

## Petr Baudis, 2005-10-25 09:10

Subject: Re: [PATCH] Add a --prefix option to git-daemon
Message-ID: <20051025091057.GA30889@pasky.or.cz>
URL: https://gitlist.dev/e/20051025091057.GA30889%40pasky.or.cz
In-Reply-To: <200510250708.j9P78pG3024087@gameboy2.puremagic.com>

```
Dear diary, on Tue, Oct 25, 2005 at 09:08:51AM CEST, I got a letter
where Brad Roberts <braddr@gameboy2.puremagic.com> told me that...
> Add a --prefix option to git-daemon.  This path is prepended to the search
> path for repositories.  In other words, git://hostname/path/to/gitdir will
> result in looking for /prefix/path/to/gitdir.
> 
> Signed-off-by: Brad Roberts <braddr@puremagic.com>

You forgot to document the option. :-)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.

```
