{"thread":{"id":"5579","subject":"[PATCH] gitweb: more support for PATH_INFO based URLs","startedAt":"2006-09-16T21:08:32Z","lastAt":"2006-09-19T09:49:53Z","messageCount":8,"participants":["Martin Waitz","Jakub Narebski","Matthias Lederhofer","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"27017","messageId":"20060916210832.GV17042@admingilde.org","threadId":"5579","inReplyTo":null,"subject":"[PATCH] gitweb: more support for PATH_INFO based URLs","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2006-09-16T21:08:32Z","receivedAt":"2006-09-16T21:08:32Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"Now three types of path based URLs are supported:\n\tgitweb.cgi/project.git\n\tgitweb.cgi/project.git/branch\n\tgitweb.cgi/project.git/branch/filename\n\nThe first one (show project summary) was already supported for a long time\nnow.  The other two are new: they show the shortlog of a branch or\nthe plain file contents of some file contained in the repository.\n\nThis is especially useful to support project web pages for small\nprojects: just create an html branch and then use an URL like\ngitweb.cgi/project.git/html/index.html.\n\nSigned-off-by: Martin Waitz <tali@admingilde.org>\n---\n gitweb/gitweb.perl |   34 +++++++++++++++++++++++++++-------\n 1 files changed, 27 insertions(+), 7 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 9324d71..2789657 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -171,12 +171,7 @@ if (defined $action) {\n \t}\n }\n \n-our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});\n-if (defined $project) {\n-\t$project =~ s|^/||;\n-\t$project =~ s|/$||;\n-\t$project = undef unless $project;\n-}\n+our $project = $cgi->param('p');\n if (defined $project) {\n \tif (!validate_input($project)) {\n \t\tdie_error(undef, \"Invalid project parameter\");\n@@ -187,7 +182,6 @@ if (defined $project) {\n \tif (!(-e \"$projectroot/$project/HEAD\")) {\n \t\tdie_error(undef, \"No such project\");\n \t}\n-\t$git_dir = \"$projectroot/$project\";\n }\n \n our $file_name = $cgi->param('f');\n@@ -247,6 +241,32 @@ if (defined $searchtext) {\n \t$searchtext = quotemeta $searchtext;\n }\n \n+# now read PATH_INFO and use it as alternative to parameters\n+our $path_info = $ENV{\"PATH_INFO\"};\n+$path_info =~ s|^/||;\n+$path_info =~ s|/$||;\n+if (validate_input($path_info) && !defined $project) {\n+\t$project = $path_info;\n+\twhile ($project && !-e \"$projectroot/$project/HEAD\") {\n+\t\t$project =~ s,/*[^/]*$,,;\n+\t}\n+\tif (defined $project) {\n+\t\t$project = undef unless $project;\n+\t}\n+\tif ($path_info =~ m,^$project/([^/]+)/(.+)$,) {\n+\t\t# we got \"project.git/branch/filename\"\n+\t\t$action    ||= \"blob_plain\";\n+\t\t$hash_base ||= $1;\n+\t\t$file_name ||= $2;\n+\t} elsif ($path_info =~ m,^$project/([^/]+)$,) {\n+\t\t# we got \"project.git/branch\"\n+\t\t$action ||= \"shortlog\";\n+\t\t$hash   ||= $1;\n+\t}\n+}\n+\n+$git_dir = \"$projectroot/$project\";\n+\n # dispatch\n my %actions = (\n \t\"blame\" => \\&git_blame2,\n-- \n1.4.2.gb8b6b\n\n-- \nMartin Waitz\n"},{"id":"27022","messageId":"eehrad$5i0$2@sea.gmane.org","threadId":"5579","inReplyTo":"20060916210832.GV17042@admingilde.org","subject":"Re: [PATCH] gitweb: more support for PATH_INFO based URLs","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-09-16T21:46:28Z","receivedAt":"2006-09-16T21:46:28Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Martin Waitz wrote:\n\n> Now three types of path based URLs are supported:\n>         gitweb.cgi/project.git\n>         gitweb.cgi/project.git/branch\n>         gitweb.cgi/project.git/branch/filename\n> \n> The first one (show project summary) was already supported for a long time\n> now.  The other two are new: they show the shortlog of a branch or\n> the plain file contents of some file contained in the repository.\n> \n> This is especially useful to support project web pages for small\n> projects: just create an html branch and then use an URL like\n> gitweb.cgi/project.git/html/index.html.\n\nVery nice.\n\nAcked-by: Jakub Narebski <jnareb@gmail.com>\n\n(if it matters)\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"27074","messageId":"20060917121408.GA19860@moooo.ath.cx","threadId":"5579","inReplyTo":"20060916210832.GV17042@admingilde.org","subject":"[PATCH] gitweb: fix warnings from dd70235f5a81e (PATH_INFO)","fromName":"Matthias Lederhofer","fromEmail":"matled@gmx.net","sentAt":"2006-09-17T12:14:08Z","receivedAt":"2006-09-17T12:14:08Z","isPatch":true,"sender":{"key":"matled@gmx.net","avatar":null},"body":"And removed if in if where one if is enough.\n---\nMartin Waitz <tali@admingilde.org> wrote:\n> +\tif (defined $project) {\n> +\t\t$project = undef unless $project;\n> +\t}\nThis is an if in an if, one if is enough.\n\n> +\tif ($path_info =~ m,^$project/([^/]+)/(.+)$,) {\nWarning if $project is undef.\n> +\t} elsif ($path_info =~ m,^$project/([^/]+)$,) {\nThe same.\n> +$git_dir = \"$projectroot/$project\";\nThe same.\n\nWe really need a gitweb test target.\n\nSomething else I noted:\n> +\twhile ($project && !-e \"$projectroot/$project/HEAD\") {\nEvaluating $project boolean value leads to problems if a repository is\nnamed \"0\" (I dunno if there are other strings than \"\" and \"0\" which\nevaluate to false in perl).  There are multiple places where this is\nused so I did not change it in this patch (even added one more).\nShould this be changed?\n---\n gitweb/gitweb.perl |   10 ++++------\n 1 files changed, 4 insertions(+), 6 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 346c15c..4d39525 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -281,22 +281,20 @@ if (validate_input($path_info) && !defin\n \twhile ($project && !-e \"$projectroot/$project/HEAD\") {\n \t\t$project =~ s,/*[^/]*$,,;\n \t}\n-\tif (defined $project) {\n-\t\t$project = undef unless $project;\n-\t}\n-\tif ($path_info =~ m,^$project/([^/]+)/(.+)$,) {\n+\t$project = undef if !$project;\n+\tif ($project && $path_info =~ m,^$project/([^/]+)/(.+)$,) {\n \t\t# we got \"project.git/branch/filename\"\n \t\t$action    ||= \"blob_plain\";\n \t\t$hash_base ||= $1;\n \t\t$file_name ||= $2;\n-\t} elsif ($path_info =~ m,^$project/([^/]+)$,) {\n+\t} elsif ($project && $path_info =~ m,^$project/([^/]+)$,) {\n \t\t# we got \"project.git/branch\"\n \t\t$action ||= \"shortlog\";\n \t\t$hash   ||= $1;\n \t}\n }\n \n-$git_dir = \"$projectroot/$project\";\n+$git_dir = \"$projectroot/$project\" if $project;\n \n # dispatch\n my %actions = (\n-- \n1.4.2.1.ge767\n"},{"id":"27075","messageId":"eejhtr$paa$1@sea.gmane.org","threadId":"5579","inReplyTo":"20060916210832.GV17042@admingilde.org","subject":"Re: [PATCH] gitweb: more support for PATH_INFO based URLs","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-09-17T13:18:29Z","receivedAt":"2006-09-17T13:18:29Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Martin Waitz wrote:\n\n> Now three types of path based URLs are supported:\n>       gitweb.cgi/project.git\n>       gitweb.cgi/project.git/branch\n>       gitweb.cgi/project.git/branch/filename\n> \n> The first one (show project summary) was already supported for a long time\n> now.  The other two are new: they show the shortlog of a branch or\n> the plain file contents of some file contained in the repository.\n\n> +     if ($path_info =~ m,^$project/([^/]+)/(.+)$,) {\n> +             # we got \"project.git/branch/filename\"\n> +             $action    ||= \"blob_plain\";\n> +             $hash_base ||= $1;\n> +             $file_name ||= $2;\n> +     } elsif ($path_info =~ m,^$project/([^/]+)$,) {\n> +             # we got \"project.git/branch\"\n> +             $action ||= \"shortlog\";\n> +             $hash   ||= $1;\n> +     }\n\nI'm sorry, but I realized that I didn't think and check this patch through.\n\nFirst, this patch spews a bunch of warnings: when PATH_INFO is empty, when\nwe undefine $project etc. The patches by me and by matled try to address\nand remove those warnings, but I'm sure we missed some.\n\nSecond, the whole concept of third type of path (path_info) based URL is\nflawed: branches can also be hierarchical (for example Junio uses\n<initals>/<topic> topic branches, although they are not published).\nTherefore it is much harder to distinguish where branchname ends and\nfilename begins. The patch assumes that branches are flat. So for example\nfor branch with the name like \"gitweb/xmms2\" the types 2 and 3 wouldn't\nwork; and type 1 worked before this patch.\n\nTherefore I rescind my Ack.\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"27078","messageId":"eejlht$870$1@sea.gmane.org","threadId":"5579","inReplyTo":"eejhtr$paa$1@sea.gmane.org","subject":"Re: [PATCH] gitweb: more support for PATH_INFO based URLs","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-09-17T14:20:23Z","receivedAt":"2006-09-17T14:20:23Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"matled (Matthias Lederhofer) on #git proposed to use ':' as a separator\nbetween branch and filename (as branch doesn't need to be flat, \ne.g. \"jc/diff\" like branch name), because valid branch name cannot contain\n':' (and this limit is only for branch name).\n\nHe also said that filename doesn't need to be necessary file (which would be\nthen present in \"blob_plain\" view), but it can be also a directory (which\nthen would be present in \"tree\" view). We can either check type using\ngit-cat-file -t via git_get_type subroutine, or assume that if we want for\ndirectory to be shown, it should end with \"/\".\n\nLet's assume for simplicity that empty branch name equals to HEAD branch,\nand empty filename equals to top (root) directory of project.\n\nSo we would have the following types of path based URLs:\n\n* project              overview (summary) page of project\n* project/branch       shortlog of branch\n* project/branch:file  file in branch, blob_plain view\n* project/branch:dir/  directory listing of dir in branch, tree view\n\nPossible shortcuts:\n* project/branch:      directory listing of branch, main tree view\n* project/:file        file in HEAD (raw)\n* project/:dir/        directory listing of dir in HEAD\n* project/:            directory listing of project's HEAD\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"27091","messageId":"7vfyeq2n57.fsf@assigned-by-dhcp.cox.net","threadId":"5579","inReplyTo":"20060917121408.GA19860@moooo.ath.cx","subject":"Re: [PATCH] gitweb: fix warnings from dd70235f5a81e (PATH_INFO)","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-17T21:34:12Z","receivedAt":"2006-09-17T21:34:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthias Lederhofer <matled@gmx.net> writes:\n\n> We really need a gitweb test target.\n\nYes, really.  Any takers who cares truly about gitweb?\n\n> Something else I noted:\n>> +\twhile ($project && !-e \"$projectroot/$project/HEAD\") {\n> Evaluating $project boolean value leads to problems if a repository is\n> named \"0\" (I dunno if there are other strings than \"\" and \"0\" which\n> evaluate to false in perl).  There are multiple places where this is\n> used so I did not change it in this patch (even added one more).\n> Should this be changed?\n\nYes, there are tons of places that says if ($foo) and/or while\n($bar) and fail miserably when $foo or $bar _can_ be \"0\".  For\nproject names \"0\" is probably not something people would want to\nuse but there is no inherent reason to forbid it.\n\nHow many places, like this, that we should say \"defined()\"\ninstead in the current code I wonder?\n\n> -\t} elsif ($path_info =~ m,^$project/([^/]+)$,) {\n> +\t} elsif ($project && $path_info =~ m,^$project/([^/]+)$,) {\n"},{"id":"27150","messageId":"20060919081933.GB31940@admingilde.org","threadId":"5579","inReplyTo":"eejlht$870$1@sea.gmane.org","subject":"Re: [PATCH] gitweb: more support for PATH_INFO based URLs","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2006-09-19T08:19:33Z","receivedAt":"2006-09-19T08:19:33Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"hoi :)\n\nOn Sun, Sep 17, 2006 at 04:20:23PM +0200, Jakub Narebski wrote:\n> matled (Matthias Lederhofer) on #git proposed to use ':' as a separator\n> between branch and filename (as branch doesn't need to be flat, \n> e.g. \"jc/diff\" like branch name), because valid branch name cannot contain\n> ':' (and this limit is only for branch name).\n\nyou are right, my patch doesn't work with hierarchical branch names.\nHowever using \":\" alone does not work eighter.\nMy main motivation for this patch was to be able to export .html files\nand to have working links between them.\nHowever a <a href=\"main.html\"> link inside \"branch:index.html\" would\ntry to get \"main.html\" and not \"branch:main.html\".\n\nPerhaps use \":/\" as separator?\nOr try to add more words to the branch name until we get a valid one.\nBut I don't know how this plays with Linus' latest ref-pack work\nwhere both \"a\" and \"a/b\" are valid branch names (If I understood it\ncorrectly).  Perhaps use a similiar algorith as the one I used\nto get the project path?\n\n> He also said that filename doesn't need to be necessary file (which would be\n> then present in \"blob_plain\" view), but it can be also a directory (which\n> then would be present in \"tree\" view). We can either check type using\n> git-cat-file -t via git_get_type subroutine, or assume that if we want for\n> directory to be shown, it should end with \"/\".\n\nyes, this was something I wanted to do later, too.\n\n-- \nMartin Waitz\n"},{"id":"27154","messageId":"eeoeee$q4u$1@sea.gmane.org","threadId":"5579","inReplyTo":"20060919081933.GB31940@admingilde.org","subject":"Re: [PATCH] gitweb: more support for PATH_INFO based URLs","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-09-19T09:49:53Z","receivedAt":"2006-09-19T09:49:53Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Martin Waitz wrote:\n\n> On Sun, Sep 17, 2006 at 04:20:23PM +0200, Jakub Narebski wrote:\n>> matled (Matthias Lederhofer) on #git proposed to use ':' as a separator\n>> between branch and filename (as branch doesn't need to be flat, \n>> e.g. \"jc/diff\" like branch name), because valid branch name cannot contain\n>> ':' (and this limit is only for branch name).\n> \n> you are right, my patch doesn't work with hierarchical branch names.\n> However using \":\" alone does not work eighter.\n> My main motivation for this patch was to be able to export .html files\n> and to have working links between them.\n> However a <a href=\"main.html\"> link inside \"branch:index.html\" would\n> try to get \"main.html\" and not \"branch:main.html\".\n> \n> Perhaps use \":/\" as separator?\n\nThat would be _very_ easy to add. Just strip leading \"/\" from pathname,\nand we can have\n\n        path/to/project.git/hierarchical/branch:/path/to/filename\n\nBy the way, besides hierarchical branches, we might need this if\nthe repository (project) has the branch (head) and tag with the same name,\nand we want to select one or the other.\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"}]}