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

Subsystems: the rest

DORMANTno replies

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

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

From: Brad Roberts <hidden>
Date: 2016-06-15 22:42:09

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 <redacted>
---

 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

Re: [PATCH] Add a --prefix option to git-daemon

From: Petr Baudis <hidden>
Date: 2016-06-15 22:42:09

Dear diary, on Tue, Oct 25, 2005 at 09:08:51AM CEST, I got a letter
where Brad Roberts [off-list ref] 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 <redacted>
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help