{"thread":{"id":"4028","subject":"[PATCH] gitweb: Add shorthand URLs for summary and a special html branch","startedAt":"2006-05-02T23:25:23Z","lastAt":"2006-05-02T23:25:23Z","messageCount":1,"participants":["Martin Waitz"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"19385","messageId":"20060502232523.GN20847@admingilde.org","threadId":"4028","inReplyTo":null,"subject":"[PATCH] gitweb: Add shorthand URLs for summary and a special html branch","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2006-05-02T23:25:23Z","receivedAt":"2006-05-02T23:25:23Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"gitweb now supports URLs like .../gitweb.cgi/<projectpath> as a shortcut\nfor the project summary page and .../gitweb.cgi/<projectpath>/<file.html>\nto access .html pages in an \"html\" branch.\n\nSigned-off-by: Martin Waitz <tali@admingilde.org>\n\n---\n\n gitweb.cgi |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----\n 1 files changed, 56 insertions(+), 4 deletions(-)\n\n05d0376478ccc273d12dbe177cf11c62c86ab848\ndiff --git a/gitweb.cgi b/gitweb.cgi\nindex c1bb624..959ca3e 100755\n--- a/gitweb.cgi\n+++ b/gitweb.cgi\n@@ -20,6 +20,7 @@ my $cgi = new CGI;\n my $version =\t\t\"264\";\n my $my_url =\t\t$cgi->url();\n my $my_uri =\t\t$cgi->url(-absolute => 1);\n+my $my_path =\t\t$cgi->url(-path => 1);\n my $rss_link =\t\t\"\";\n \n # absolute fs-path which will be prepended to the project path\n@@ -42,8 +43,30 @@ # source of projects list\n #my $projects_list =\t$projectroot;\n my $projects_list =\t\"index/index.aux\";\n \n+\n+my ($action, $project, $file_name, $hash);\n+\n+# rewrite to support direct access to .html files in the \"html\" branch\n+if ($my_path =~ /^$my_url\\/(.*\\.git)\\/?$/) {\n+\t$action = \"summary\";\n+\t$project = validate_input($1);\n+} elsif ($my_path =~ /^$my_url\\/(.*\\.git)\\/(.*\\.html)$/) {\n+\t$action = \"blob_html\";\n+\t$project = validate_input($1);\n+\t$file_name = validate_input($2);\n+\t$hash = \"html:$file_name\";\n+} elsif ($my_path =~ /^$my_url\\/(.*\\.git)\\/(HEAD|objects\\/info\\/packs|info\\/refs|refs\\/.*)$/) {\n+\t$action = \"direct_text\";\n+\t$project = validate_input($1);\n+\t$file_name = validate_input($2);\n+} elsif ($my_path =~ /^$my_url\\/(.*\\.git)\\/(objects\\/.*)$/) {\n+\t$action = \"direct_object\";\n+\t$project = validate_input($1);\n+\t$file_name = validate_input($2);\n+}\n+\n # input validation and dispatch\n-my $action = $cgi->param('a');\n+$action ||= $cgi->param('a');\n if (defined $action) {\n \tif ($action =~ m/[^0-9a-zA-Z\\.\\-_]/) {\n \t\tundef $action;\n@@ -66,7 +89,7 @@ if (defined $order) {\n \t}\n }\n \n-my $project = $cgi->param('p');\n+$project ||= $cgi->param('p');\n if (defined $project) {\n \t$project = validate_input($project);\n \tif (!defined($project)) {\n@@ -88,7 +111,7 @@ if (defined $project) {\n \texit;\n }\n \n-my $file_name = $cgi->param('f');\n+$file_name ||= $cgi->param('f');\n if (defined $file_name) {\n \t$file_name = validate_input($file_name);\n \tif (!defined($file_name)) {\n@@ -96,7 +119,7 @@ if (defined $file_name) {\n \t}\n }\n \n-my $hash = $cgi->param('h');\n+$hash ||= $cgi->param('h');\n if (defined $hash) {\n \t$hash = validate_input($hash);\n \tif (!defined($hash)) {\n@@ -167,6 +190,9 @@ if (!defined $action || $action eq \"summ\n } elsif ($action eq \"blob_plain\") {\n \tgit_blob_plain();\n \texit;\n+} elsif ($action eq \"blob_html\") {\n+\tgit_blob_html();\n+\texit;\n } elsif ($action eq \"tree\") {\n \tgit_tree();\n \texit;\n@@ -203,6 +229,10 @@ if (!defined $action || $action eq \"summ\n } elsif ($action eq \"tag\") {\n \tgit_tag();\n \texit;\n+} elsif ($action eq \"direct_text\") {\n+\tgit_direct_text();\n+} elsif ($action eq \"direct_object\") {\n+\tgit_direct_object();\n } else {\n \tundef $action;\n \tdie_error(undef, \"Unknown action.\");\n@@ -1423,6 +1453,28 @@ sub git_blob_plain {\n \tclose $fd;\n }\n \n+sub git_blob_html {\n+\tmy $save_as = \"$hash\";\n+\tif (defined $file_name) {\n+\t\t$save_as = $file_name;\n+\t}\n+\tprint $cgi->header(-type => \"text/html\", -charset => 'utf-8', '-content-disposition' => \"inline; filename=\\\"$save_as\\\"\");\n+\topen my $fd, \"-|\", \"$gitbin/git-cat-file blob $hash\" or return;\n+\tundef $/;\n+\tprint <$fd>;\n+\t$/ = \"\\n\";\n+\tclose $fd;\n+}\n+\n+sub git_direct_text {\n+\tprint $cgi->header(-type => \"test/plain\");\n+\texec(\"cat\", \"$projectroot/$project/$file_name\");\n+}\n+sub git_direct_object {\n+\tprint $cgi->header(-type => \"application/binary\", -expires => \"+1y\");\n+\texec(\"cat\", \"$projectroot/$project/$file_name\");\n+}\n+\n sub git_tree {\n \tif (!defined $hash) {\n \t\t$hash = git_read_head($project);\n-- \n1.3.1.g6ef7\n\n\n-- \nMartin Waitz\n"}]}