Skip to content

Commit 73a7a65

Browse files
Jens Axboegitster
authored andcommitted
--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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 12ace0b commit 73a7a65

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Documentation/git-daemon.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ OPTIONS
5454
'git://example.com/hello.git', `git-daemon` will interpret the path
5555
as '/srv/git/hello.git'.
5656

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+
5763
--interpolated-path=pathtemplate::
5864
To support virtual hosting, an interpolated path template can be
5965
used to dynamically construct alternate paths. The template

daemon.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ static int reuseaddr;
1616
static const char daemon_usage[] =
1717
"git-daemon [--verbose] [--syslog] [--export-all]\n"
1818
" [--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"
2021
" [--interpolated-path=path]\n"
2122
" [--reuseaddr] [--detach] [--pid-file=file]\n"
2223
" [--[enable|disable|allow-override|forbid-override]=service]\n"
@@ -34,6 +35,7 @@ static int export_all_trees;
3435
/* Take all paths relative to this one if non-NULL */
3536
static char *base_path;
3637
static char *interpolated_path;
38+
static int base_path_relaxed;
3739

3840
/* Flag indicating client sent extra args. */
3941
static int saw_extended_args;
@@ -180,6 +182,7 @@ static char *path_ok(struct interp *itable)
180182
{
181183
static char rpath[PATH_MAX];
182184
static char interp_path[PATH_MAX];
185+
int retried_path = 0;
183186
char *path;
184187
char *dir;
185188

@@ -235,7 +238,22 @@ static char *path_ok(struct interp *itable)
235238
dir = rpath;
236239
}
237240

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);
239257

240258
if (!path) {
241259
logerror("'%s': unable to chdir or not a git archive", dir);
@@ -1061,6 +1079,10 @@ int main(int argc, char **argv)
10611079
base_path = arg+12;
10621080
continue;
10631081
}
1082+
if (!strcmp(arg, "--base-path-relaxed")) {
1083+
base_path_relaxed = 1;
1084+
continue;
1085+
}
10641086
if (!prefixcmp(arg, "--interpolated-path=")) {
10651087
interpolated_path = arg+20;
10661088
continue;

0 commit comments

Comments
 (0)