--base-path-relaxed option
I switched git.kernel.dk to --base-path a few minutes ago, to get rid of a /data/git postfix in the posted urls. But transitioning is tricky, since now all old paths will fail miserably. So I added this --base-path-relaxed option, that will make git-daemon try the absolute path without prefixing --base-path before giving up. With this in place and --base-path-relaxed added, both my new url of git://git.kernel.dk/linux-2.6-block.git and the old git://git.kernel.dk/data/git/linux-2.6-block.git work fine. Signed-off-by: Jens Axboe <jens.axboe@oracle.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jens Axboe committed
Jul 27, 2007 at 14:00 UTC
73a7a65663223d08d8cabac8d873de21b7e9678d
2 files changed
+30
-2
Documentation/git-daemon.txt
+6
@@ -54,6 +54,12 @@ OPTIONS
54
'git://example.com/hello.git', `git-daemon` will interpret the path
55
as '/srv/git/hello.git'.
56
57
+--base-path-relaxed::
58
+ If --base-path is enabled and repo lookup fails, with this option
59
+ `git-daemon` will attempt to lookup without prefixing the base path.
60
+ This is useful for switching to --base-path usage, while still
61
+ allowing the old paths.
62
+
63
--interpolated-path=pathtemplate::
64
To support virtual hosting, an interpolated path template can be
65
used to dynamically construct alternate paths. The template
daemon.c
+24
-2
@@ -16,7 +16,8 @@ static int reuseaddr;
16
static const char daemon_usage[] =
17
"git-daemon [--verbose] [--syslog] [--export-all]\n"
18
" [--timeout=n] [--init-timeout=n] [--strict-paths]\n"
19
-" [--base-path=path] [--user-path | --user-path=path]\n"
19
+" [--base-path=path] [--base-path-relaxed]\n"
20
+" [--user-path | --user-path=path]\n"
21
" [--interpolated-path=path]\n"
22
" [--reuseaddr] [--detach] [--pid-file=file]\n"
23
" [--[enable|disable|allow-override|forbid-override]=service]\n"
@@ -34,6 +35,7 @@ static int export_all_trees;
35
/* Take all paths relative to this one if non-NULL */
36
static char *base_path;
37
static char *interpolated_path;
38
+static int base_path_relaxed;
39
40
/* Flag indicating client sent extra args. */
41
static int saw_extended_args;
@@ -180,6 +182,7 @@ static char *path_ok(struct interp *itable)
182
{
183
static char rpath[PATH_MAX];
184
static char interp_path[PATH_MAX];
185
+ int retried_path = 0;
186
char *path;
187
char *dir;
188
@@ -235,7 +238,22 @@ static char *path_ok(struct interp *itable)
238
dir = rpath;
239
}
240
238
- path = enter_repo(dir, strict_paths);
241
+ do {
242
+ path = enter_repo(dir, strict_paths);
243
+ if (path)
244
+ break;
245
+
246
+ /*
247
+ * if we fail and base_path_relaxed is enabled, try without
248
+ * prefixing the base path
249
+ */
250
+ if (base_path && base_path_relaxed && !retried_path) {
251
+ dir = itable[INTERP_SLOT_DIR].value;
252
+ retried_path = 1;
253
+ continue;
254
+ }
255
+ break;
256
+ } while (1);
257
258
if (!path) {
259
logerror("'%s': unable to chdir or not a git archive", dir);
@@ -1061,6 +1079,10 @@ int main(int argc, char **argv)
1079
base_path = arg+12;
1080
continue;
1081
}
1082
+ if (!strcmp(arg, "--base-path-relaxed")) {
1083
+ base_path_relaxed = 1;
1084
+ continue;
1085
+ }
1086
if (!prefixcmp(arg, "--interpolated-path=")) {
1087
interpolated_path = arg+20;
1088
continue;