Skip to content

Commit

Permalink
--base-path-relaxed option
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jens Axboe authored and Junio C Hamano committed Aug 1, 2007
1 parent 12ace0b commit 73a7a65
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Documentation/git-daemon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ OPTIONS
'git://example.com/hello.git', `git-daemon` will interpret the path
as '/srv/git/hello.git'.

--base-path-relaxed::
If --base-path is enabled and repo lookup fails, with this option
`git-daemon` will attempt to lookup without prefixing the base path.
This is useful for switching to --base-path usage, while still
allowing the old paths.

--interpolated-path=pathtemplate::
To support virtual hosting, an interpolated path template can be
used to dynamically construct alternate paths. The template
Expand Down
26 changes: 24 additions & 2 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ static int reuseaddr;
static const char daemon_usage[] =
"git-daemon [--verbose] [--syslog] [--export-all]\n"
" [--timeout=n] [--init-timeout=n] [--strict-paths]\n"
" [--base-path=path] [--user-path | --user-path=path]\n"
" [--base-path=path] [--base-path-relaxed]\n"
" [--user-path | --user-path=path]\n"
" [--interpolated-path=path]\n"
" [--reuseaddr] [--detach] [--pid-file=file]\n"
" [--[enable|disable|allow-override|forbid-override]=service]\n"
Expand All @@ -34,6 +35,7 @@ static int export_all_trees;
/* Take all paths relative to this one if non-NULL */
static char *base_path;
static char *interpolated_path;
static int base_path_relaxed;

/* Flag indicating client sent extra args. */
static int saw_extended_args;
Expand Down Expand Up @@ -180,6 +182,7 @@ static char *path_ok(struct interp *itable)
{
static char rpath[PATH_MAX];
static char interp_path[PATH_MAX];
int retried_path = 0;
char *path;
char *dir;

Expand Down Expand Up @@ -235,7 +238,22 @@ static char *path_ok(struct interp *itable)
dir = rpath;
}

path = enter_repo(dir, strict_paths);
do {
path = enter_repo(dir, strict_paths);
if (path)
break;

/*
* if we fail and base_path_relaxed is enabled, try without
* prefixing the base path
*/
if (base_path && base_path_relaxed && !retried_path) {
dir = itable[INTERP_SLOT_DIR].value;
retried_path = 1;
continue;
}
break;
} while (1);

if (!path) {
logerror("'%s': unable to chdir or not a git archive", dir);
Expand Down Expand Up @@ -1061,6 +1079,10 @@ int main(int argc, char **argv)
base_path = arg+12;
continue;
}
if (!strcmp(arg, "--base-path-relaxed")) {
base_path_relaxed = 1;
continue;
}
if (!prefixcmp(arg, "--interpolated-path=")) {
interpolated_path = arg+20;
continue;
Expand Down

0 comments on commit 73a7a65

Please sign in to comment.