Skip to contentSkip to conversation

Add virtualization support to git-daemon

PATCH New Jon Loeliger 2 participants 3 messages Jun 15, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add virtualization support to git-daemon

Signed-off-by Jon Loeliger

---

Avast Matey! [*1*]

Phat loot!

Here be the promised respin o' me patch. We be supportin' git-daemon virtualization with this one. No more dreaded hackery for multiple hosts, eh? A flaggon of mead around! Aye, it's a bloody good start, here, eh?, but she could sure use some keel-haulin' and testin'!

Cap'n jdl

[*1*] http://talklikeapirate.com/

 Documentation/git-daemon.txt |   47 ++++++++++++++++++++++
 Makefile                     |    4 +-
 daemon.c                     |   89 +++++++++++++++++++++++++++++++++++++-----
 interpolate.c                |   82 +++++++++++++++++++++++++++++++++++++++
 interpolate.h                |   18 ++++++++
 5 files changed, 229 insertions(+), 11 deletions(-)
Documentation/git-daemon.txt +47 -0
index 741f2c6..87444b4 100644
@@ -11,6 +11,7 @@ SYNOPSIS
 'git-daemon' [--verbose] [--syslog] [--inetd | --port=n] [--export-all]
              [--timeout=n] [--init-timeout=n] [--strict-paths]
              [--base-path=path] [--user-path | --user-path=path]
+             [--interpolated-path=pathtemplate]
              [--enable=service] [--disable=service]
 	     [--allow-override=service] [--forbid-override=service]
              [--reuseaddr] [--detach] [--pid-file=file]
@@ -50,6 +51,12 @@ OPTIONS
 	'git://example.com/hello.git', `git-daemon` will interpret the path
 	as '/srv/git/hello.git'.
 
+--interpolated-path=pathtemplate::
+	To support virtual hosting, an interpolated path template can be
+	used to dynamically construct alternate paths.  The template
+	supports %H for the target hostname as supplied by the client,
+	and %D for the absolute path of the named repository.	
+
 --export-all::
 	Allow pulling from all directories that look like GIT repositories
 	(have the 'objects' and 'refs' subdirectories), even if they
@@ -135,6 +142,46 @@ upload-pack::
 	disable it by setting `daemon.uploadpack` configuration
 	item to `false`.
 
+EXAMPLES
+--------
+git-daemon as inetd server::
+	To set up `git-daemon` as an inetd service that handles any
+	repository under the whitelisted set of directories, /pub/foo
+	and /pub/bar, place an entry like the following into
+	/etc/inetd all on one line:
++
+------------------------------------------------
+	git stream tcp nowait nobody  /usr/bin/git-daemon
+		git-daemon --inetd --verbose
+		--syslog --export-all
+		/pub/foo /pub/bar
+------------------------------------------------
+
+
+git-daemon as inetd server for virtual hosts::
+	To set up `git-daemon` as an inetd service that handles
+	repositories for different virtual hosts, `www.example.com`
+	and `www.example.org`, place an entry like the following into
+	`/etc/inetd` all on one line:
++
+------------------------------------------------
+	git stream tcp nowait nobody /usr/bin/git-daemon
+		git-daemon --inetd --verbose
+		--syslog --export-all
+		--interpolated-path=/pub/%H%D
+		/pub/www.example.org/software
+		/pub/www.example.com/software
+		/software
+------------------------------------------------
++
+In this example, the root-level directory `/pub` will contain
+a subdirectory for each virtual host name supported.
+Further, both hosts advertise repositories simply as
+`git://www.example.com/software/repo.git`.  For pre-1.4.0
+clients, a symlink from `/software` into the appropriate
+default repository could be made as well.
+
+
 Author
 ------
 Written by Linus Torvalds <[email protected]>, YOSHIFUJI Hideaki
Makefile +3 -1
index 7b3114f..673ba2d 100644
@@ -244,7 +244,9 @@ DIFF_OBJS = \
 
 LIB_OBJS = \
 	blob.o commit.o connect.o csum-file.o cache-tree.o base85.o \
-	date.o diff-delta.o entry.o exec_cmd.o ident.o lockfile.o \
+	date.o diff-delta.o entry.o exec_cmd.o ident.o \
+	interpolate.o \
+	lockfile.o \
 	object.o pack-check.o patch-delta.o path.o pkt-line.o \
 	quote.o read-cache.o refs.o run-command.o dir.o object-refs.o \
 	server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
daemon.c +79 -10

173 lines not on this page · raw message

interpolate.c new file +82 -0

82 lines not on this page · raw message

interpolate.h new file +18 -0
new file mode 100644
index 0000000..00c63a5
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2006 Jon Loeliger
+ */
+
+#ifndef INTERPOLATE_H
+#define INTERPOLATE_H
+
+
+struct interp {
+	char *name;
+	char *value;
+};
+
+extern int interpolate(char *result, int reslen,
+		       char *orig,
+		       struct interp *interps, int ninterps);
+
+#endif /* INTERPOLATE_H */
#1 lore raw

PATCH 1/1 Use const for interpolate arguments

---
 interpolate.c |    6 +++---
 interpolate.h |    9 +++++++--
 2 files changed, 10 insertions(+), 5 deletions(-)
interpolate.c +3 -3
index d82f1b5..4570c12 100644
@@ -25,10 +25,10 @@ #include "interpolate.h"
  */
 
 int interpolate(char *result, int reslen,
-		char *orig,
-		struct interp *interps, int ninterps)
+		const char *orig,
+		const struct interp *interps, int ninterps)
 {
-	char *src = orig;
+	const char *src = orig;
 	char *dest = result;
 	int newlen = 0;
 	char *name, *value;
interpolate.h +7 -2
index 00c63a5..d16f924 100644
@@ -5,6 +5,11 @@
 #ifndef INTERPOLATE_H
 #define INTERPOLATE_H
 
+/*
+ * Convert a NUL-terminated string in buffer orig,
+ * performing substitutions on %-named sub-strings from
+ * the interpretation table.
+ */
 
 struct interp {
 	char *name;
@@ -12,7 +17,7 @@ struct interp {
 };
 
 extern int interpolate(char *result, int reslen,
-		       char *orig,
-		       struct interp *interps, int ninterps);
+		       const char *orig,
+		       const struct interp *interps, int ninterps);
 
 #endif /* INTERPOLATE_H */
Signature · 1 line
1.4.2.1.g6b47-dirty
#2 lore raw

PATCH 1/1 Use const for interpolate arguments

In reply to Jon Loeliger

---

Resending. jdl.com blacklisted my IP, for whatever it has done to him.

 interpolate.c |    6 +++---
 interpolate.h |    9 +++++++--
 2 files changed, 10 insertions(+), 5 deletions(-)
interpolate.c +3 -3
index d82f1b5..4570c12 100644
@@ -25,10 +25,10 @@ #include "interpolate.h"
  */
 
 int interpolate(char *result, int reslen,
-		char *orig,
-		struct interp *interps, int ninterps)
+		const char *orig,
+		const struct interp *interps, int ninterps)
 {
-	char *src = orig;
+	const char *src = orig;
 	char *dest = result;
 	int newlen = 0;
 	char *name, *value;
interpolate.h +7 -2
index 00c63a5..d16f924 100644
@@ -5,6 +5,11 @@
 #ifndef INTERPOLATE_H
 #define INTERPOLATE_H
 
+/*
+ * Convert a NUL-terminated string in buffer orig,
+ * performing substitutions on %-named sub-strings from
+ * the interpretation table.
+ */
 
 struct interp {
 	char *name;
@@ -12,7 +17,7 @@ struct interp {
 };
 
 extern int interpolate(char *result, int reslen,
-		       char *orig,
-		       struct interp *interps, int ninterps);
+		       const char *orig,
+		       const struct interp *interps, int ninterps);
 
 #endif /* INTERPOLATE_H */
Signature · 1 line
1.4.2.1.g6b47-dirty