{"thread":{"id":"9266","subject":"[PATCH] --base-path-relaxed option","startedAt":"2007-07-27T21:00:29Z","lastAt":"2007-07-27T21:00:29Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"48841","messageId":"7vy7h1woia.fsf@assigned-by-dhcp.cox.net","threadId":"9266","inReplyTo":"20070727083814.GE32258@kernel.dk","subject":"[PATCH] --base-path-relaxed option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-27T21:00:29Z","receivedAt":"2007-07-27T21:00:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Jens Axboe <jens.axboe@oracle.com>\n\nI switched git.kernel.dk to --base-path a few minutes ago, to get rid of\na /data/git postfix in the posted urls. But transitioning is tricky,\nsince now all old paths will fail miserably.\n\nSo I added this --base-path-relaxed option, that will make git-daemon\ntry the absolute path without prefixing --base-path before giving up.\nWith this in place and --base-path-relaxed added, both my new url of\n\n    git://git.kernel.dk/linux-2.6-block.git\n\nand the old\n\n    git://git.kernel.dk/data/git/linux-2.6-block.git\n\nwork fine.\n\nSigned-off-by: Jens Axboe <jens.axboe@oracle.com>\n\n---\n\n * I think this patch is a right step; we would need to help\n   people transitioning their repository URL, not necessarily\n   limited to --base-path usage.  This patch only deals with\n   \"with this base path or without\" case, and does not help\n   people who used to use base-path A and now wants to use\n   different base-path B, so in that sense there *might* still\n   be a room for improvement.  It could be as simple as allowing\n   more than than one base-path and taking the first match.\n\n   If you set one of them to an empty string, it would cover the\n   case this patch addresses, I think.\n\n   I personally do not think we would want to try 47 different\n   base-paths, though.  List?\n\n Documentation/git-daemon.txt |    6 ++++++\n daemon.c                     |   26 ++++++++++++++++++++++++--\n 2 files changed, 30 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt\nindex 4b30b18..f902161 100644\n--- a/Documentation/git-daemon.txt\n+++ b/Documentation/git-daemon.txt\n@@ -54,6 +54,12 @@ OPTIONS\n \t'git://example.com/hello.git', `git-daemon` will interpret the path\n \tas '/srv/git/hello.git'.\n \n+--base-path-relaxed::\n+\tIf --base-path is enabled and repo lookup fails, with this option\n+\t`git-daemon` will attempt to lookup without prefixing the base path.\n+\tThis is useful for switching to --base-path usage, while still\n+\tallowing the old paths.\n+\n --interpolated-path=pathtemplate::\n \tTo support virtual hosting, an interpolated path template can be\n \tused to dynamically construct alternate paths.  The template\ndiff --git a/daemon.c b/daemon.c\nindex a3f2ac1..9cf22fe 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -16,7 +16,8 @@ static int reuseaddr;\n static const char daemon_usage[] =\n \"git-daemon [--verbose] [--syslog] [--export-all]\\n\"\n \"           [--timeout=n] [--init-timeout=n] [--strict-paths]\\n\"\n-\"           [--base-path=path] [--user-path | --user-path=path]\\n\"\n+\"           [--base-path=path] [--base-path-relaxed]\\n\"\n+\"           [--user-path | --user-path=path]\\n\"\n \"           [--interpolated-path=path]\\n\"\n \"           [--reuseaddr] [--detach] [--pid-file=file]\\n\"\n \"           [--[enable|disable|allow-override|forbid-override]=service]\\n\"\n@@ -34,6 +35,7 @@ static int export_all_trees;\n /* Take all paths relative to this one if non-NULL */\n static char *base_path;\n static char *interpolated_path;\n+static int base_path_relaxed;\n \n /* Flag indicating client sent extra args. */\n static int saw_extended_args;\n@@ -180,6 +182,7 @@ static char *path_ok(struct interp *itable)\n {\n \tstatic char rpath[PATH_MAX];\n \tstatic char interp_path[PATH_MAX];\n+\tint retried_path = 0;\n \tchar *path;\n \tchar *dir;\n \n@@ -235,7 +238,22 @@ static char *path_ok(struct interp *itable)\n \t\tdir = rpath;\n \t}\n \n-\tpath = enter_repo(dir, strict_paths);\n+\tdo {\n+\t\tpath = enter_repo(dir, strict_paths);\n+\t\tif (path)\n+\t\t\tbreak;\n+\n+\t\t/*\n+\t\t * if we fail and base_path_relaxed is enabled, try without\n+\t\t * prefixing the base path\n+\t\t */\n+\t\tif (base_path && base_path_relaxed && !retried_path) {\n+\t\t\tdir = itable[INTERP_SLOT_DIR].value;\n+\t\t\tretried_path = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tbreak;\n+\t} while (1);\n \n \tif (!path) {\n \t\tlogerror(\"'%s': unable to chdir or not a git archive\", dir);\n@@ -1061,6 +1079,10 @@ int main(int argc, char **argv)\n \t\t\tbase_path = arg+12;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--base-path-relaxed\")) {\n+\t\t\tbase_path_relaxed = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (!prefixcmp(arg, \"--interpolated-path=\")) {\n \t\t\tinterpolated_path = arg+20;\n \t\t\tcontinue;\n\n-- \nJens Axboe\n"}]}