{"thread":{"id":"5610","subject":"[PATCH] gitweb: Even more support for PATH_INFO based URLs","startedAt":"2006-09-19T22:49:51Z","lastAt":"2006-09-23T14:55:49Z","messageCount":4,"participants":["Jakub Narebski","Martin Waitz","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"27193","messageId":"200609200049.52036.jnareb@gmail.com","threadId":"5610","inReplyTo":null,"subject":"[PATCH] gitweb: Even more support for PATH_INFO based URLs","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-09-19T22:49:51Z","receivedAt":"2006-09-19T22:49:51Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Now the following types of path based URLs are supported:\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\nThe following shortcuts works (see explanation below):\n\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\nWe use ':' as separator between branch (ref) name and file name\n(pathname) because valid branch (ref) name cannot have ':' inside.\nThis limit applies to branch name only. This allow for hierarchical\nbranches e.g. topic branch 'topic/subtopic', separate remotes\ntracking branches e.g. 'refs/remotes/origin/HEAD', and discriminate\nbetween head (branch) and tag with the same name.\n\nEmpty branch should be interpreted as HEAD.\n\nIf pathname (the part after ':') ends with '/', we assume that pathname\nis name of directory, and we want to show contents of said directory\nusing \"tree\" view. If pathname is empty, it is equivalent to '/' (top\ndirectory).\n\nIf pathname (the part after ':') does not end with '/', we assume that\npathname is name of file, and we show contents of said file using\n\"blob_plain\" view.\n\nPathname is stripped of leading '/', so we can use ':/' to separate\nbranch from pathname. The rationale behind support for PATH_INFO based\nURLs was to support project web pages for small projects: just create\nan html branch and then use an URL like\n  http://nowhere.com/gitweb.cgi/project.git/html:/index.html\nThe ':/' syntax allow for working links between .html files served\nin such way, e.g. <a href=\"main.html\"> link inside \"index.html\"\nwould get\n  http://nowhere.com/gitweb.cgi/project.git/html:/main.html.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nAlternatively we could use git-cat-file -t (git_get_type subroutine)\nto distinguish between trees and files (blobs), but first it would\nslow gitweb somewhat (additional fork), and second git_get_type\nassumes that $git_dir is set... and this variable is defined later!\n\nSee also:\n  \"[PATCH] gitweb: more support for PATH_INFO based URLs\"\n  Message-ID: <20060916210832.GV17042@admingilde.org>\n  http://permalink.gmane.org/gmane.comp.version-control.git/27133\n(this email should be probably posted in this thread)\n\n gitweb/gitweb.perl |   29 ++++++++++++++++++++---------\n 1 files changed, 20 insertions(+), 9 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 9445fa7..839b232 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -274,13 +274,16 @@ sub evaluate_path_info {\n \treturn if defined $project;\n \tmy $path_info = $ENV{\"PATH_INFO\"};\n \treturn if !$path_info;\n-\t$path_info =~ s,(^/|/$),,gs;\n-\t$path_info = validate_input($path_info);\n+\t$path_info =~ s,^/+,,;\n \treturn if !$path_info;\n+\t# find which part of PATH_INFO is project\n \t$project = $path_info;\n+\t$project =~ s,/+$,,;\n \twhile ($project && !-e \"$projectroot/$project/HEAD\") {\n \t\t$project =~ s,/*[^/]*$,,;\n \t}\n+\t# validate project\n+\t$project = validate_input($project);\n \tif (!$project ||\n \t    ($export_ok && !-e \"$projectroot/$project/$export_ok\") ||\n \t    ($strict_export && !project_in_list($project))) {\n@@ -289,15 +292,23 @@ sub evaluate_path_info {\n \t}\n \t# do not change any parameters if an action is given using the query string\n \treturn if $action;\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 ||= validate_input($1);\n-\t\t$file_name ||= validate_input($2);\n-\t} elsif ($path_info =~ m,^$project/([^/]+)$,) {\n+\t$path_info =~ s,^$project/*,,;\n+\tmy ($refname, $pathname) = split(/:/, $path_info, 2);\n+\tif (defined $pathname) {\n+\t\t# we got \"project.git/branch:filename\" or \"project.git/branch:dir/\"\n+\t\t# we could use git_get_type(branch:pathname), but it needs $git_dir\n+\t\t$pathname =~ s,^/+,,;\n+\t\tif (!$pathname || substr($pathname, -1) eq \"/\") {\n+\t\t\t$action  ||= \"tree\";\n+\t\t} else {\n+\t\t\t$action  ||= \"blob_plain\";\n+\t\t}\n+\t\t$hash_base ||= validate_input($refname);\n+\t\t$file_name ||= validate_input($pathname);\n+\t} elsif (defined $refname) {\n \t\t# we got \"project.git/branch\"\n \t\t$action ||= \"shortlog\";\n-\t\t$hash   ||= validate_input($1);\n+\t\t$hash   ||= validate_input($refname);\n \t}\n }\n evaluate_path_info();\n-- \n1.4.2.1\n"},{"id":"27284","messageId":"20060920210411.GF31940@admingilde.org","threadId":"5610","inReplyTo":"200609200049.52036.jnareb@gmail.com","subject":"Re: [PATCH] gitweb: Even more support for PATH_INFO based URLs","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2006-09-20T21:04:11Z","receivedAt":"2006-09-20T21:04:11Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"hoi :)\n\nOn Wed, Sep 20, 2006 at 12:49:51AM +0200, Jakub Narebski wrote:\n> Now the following types of path based URLs are supported:\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> \n> The following shortcuts works (see explanation below):\n> \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\nvery nice! thanks a lot!\n\n-- \nMartin Waitz\n"},{"id":"27476","messageId":"20060923142941.GL8259@pasky.or.cz","threadId":"5610","inReplyTo":"200609200049.52036.jnareb@gmail.com","subject":"Re: [PATCH] gitweb: Even more support for PATH_INFO based URLs","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-09-23T14:29:41Z","receivedAt":"2006-09-23T14:29:41Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"  Hi,\n\nDear diary, on Wed, Sep 20, 2006 at 12:49:51AM CEST, I got a letter\nwhere Jakub Narebski <jnareb@gmail.com> said that...\n> Now the following types of path based URLs are supported:\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> \n> The following shortcuts works (see explanation below):\n> \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\n  I haven't followed this stuff carefully but just to confirm, there is\ncurrently no way to persuade gitweb to actually produce such links,\nright?\n\n  I like pathinfo and would like to use it for repo.or.cz's gitweb.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\n#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj\n$/=unpack('H*',$_);$_=`echo 16dio\\U$k\"SK$/SM$n\\EsN0p[lN*1\nlK[d2%Sa2/d0$^Ixp\"|dc`;s/\\W//g;$_=pack('H*',/((..)*)$/)\n"},{"id":"27477","messageId":"200609231655.49915.jnareb@gmail.com","threadId":"5610","inReplyTo":"20060923142941.GL8259@pasky.or.cz","subject":"Re: [PATCH] gitweb: Even more support for PATH_INFO based URLs","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-09-23T14:55:49Z","receivedAt":"2006-09-23T14:55:49Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Petr Baudis wrote:\n> Dear diary, on Wed, Sep 20, 2006 at 12:49:51AM CEST, I got a letter\n> where Jakub Narebski <jnareb@gmail.com> said that...\n> > Now the following types of path based URLs are supported:\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> > \n> > The following shortcuts works (see explanation below):\n> > \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> \n>   I haven't followed this stuff carefully but just to confirm, there is\n> currently no way to persuade gitweb to actually produce such links,\n> right?\n> \n>   I like pathinfo and would like to use it for repo.or.cz's gitweb.\n\nWell, all inner links go through href() subroutine, so this is where\nyou would want to make changes. Having project in pathinfo would be easy,\nhaving branch/ref harder because it might be in hash, or in hash_base\nparameter.\n\nPerhaps we should use\n\tmy $path_info = $ENV{MOD_PERL} ? $r->path_info() : $ENV{PATH_INFO};\n-- \nJakub Narebski\nPoland\n"}]}