git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Waitz <tali@admingilde.org>
To: git@vger.kernel.org
Subject: [PATCH] gitweb: Add shorthand URLs for summary and a special html branch
Date: Wed, 3 May 2006 01:25:23 +0200	[thread overview]
Message-ID: <20060502232523.GN20847@admingilde.org> (raw)

gitweb now supports URLs like .../gitweb.cgi/<projectpath> as a shortcut
for the project summary page and .../gitweb.cgi/<projectpath>/<file.html>
to access .html pages in an "html" branch.

Signed-off-by: Martin Waitz <tali@admingilde.org>

---

 gitweb.cgi |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 56 insertions(+), 4 deletions(-)

05d0376478ccc273d12dbe177cf11c62c86ab848
diff --git a/gitweb.cgi b/gitweb.cgi
index c1bb624..959ca3e 100755
--- a/gitweb.cgi
+++ b/gitweb.cgi
@@ -20,6 +20,7 @@ my $cgi = new CGI;
 my $version =		"264";
 my $my_url =		$cgi->url();
 my $my_uri =		$cgi->url(-absolute => 1);
+my $my_path =		$cgi->url(-path => 1);
 my $rss_link =		"";
 
 # absolute fs-path which will be prepended to the project path
@@ -42,8 +43,30 @@ # source of projects list
 #my $projects_list =	$projectroot;
 my $projects_list =	"index/index.aux";
 
+
+my ($action, $project, $file_name, $hash);
+
+# rewrite to support direct access to .html files in the "html" branch
+if ($my_path =~ /^$my_url\/(.*\.git)\/?$/) {
+	$action = "summary";
+	$project = validate_input($1);
+} elsif ($my_path =~ /^$my_url\/(.*\.git)\/(.*\.html)$/) {
+	$action = "blob_html";
+	$project = validate_input($1);
+	$file_name = validate_input($2);
+	$hash = "html:$file_name";
+} elsif ($my_path =~ /^$my_url\/(.*\.git)\/(HEAD|objects\/info\/packs|info\/refs|refs\/.*)$/) {
+	$action = "direct_text";
+	$project = validate_input($1);
+	$file_name = validate_input($2);
+} elsif ($my_path =~ /^$my_url\/(.*\.git)\/(objects\/.*)$/) {
+	$action = "direct_object";
+	$project = validate_input($1);
+	$file_name = validate_input($2);
+}
+
 # input validation and dispatch
-my $action = $cgi->param('a');
+$action ||= $cgi->param('a');
 if (defined $action) {
 	if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
 		undef $action;
@@ -66,7 +89,7 @@ if (defined $order) {
 	}
 }
 
-my $project = $cgi->param('p');
+$project ||= $cgi->param('p');
 if (defined $project) {
 	$project = validate_input($project);
 	if (!defined($project)) {
@@ -88,7 +111,7 @@ if (defined $project) {
 	exit;
 }
 
-my $file_name = $cgi->param('f');
+$file_name ||= $cgi->param('f');
 if (defined $file_name) {
 	$file_name = validate_input($file_name);
 	if (!defined($file_name)) {
@@ -96,7 +119,7 @@ if (defined $file_name) {
 	}
 }
 
-my $hash = $cgi->param('h');
+$hash ||= $cgi->param('h');
 if (defined $hash) {
 	$hash = validate_input($hash);
 	if (!defined($hash)) {
@@ -167,6 +190,9 @@ if (!defined $action || $action eq "summ
 } elsif ($action eq "blob_plain") {
 	git_blob_plain();
 	exit;
+} elsif ($action eq "blob_html") {
+	git_blob_html();
+	exit;
 } elsif ($action eq "tree") {
 	git_tree();
 	exit;
@@ -203,6 +229,10 @@ if (!defined $action || $action eq "summ
 } elsif ($action eq "tag") {
 	git_tag();
 	exit;
+} elsif ($action eq "direct_text") {
+	git_direct_text();
+} elsif ($action eq "direct_object") {
+	git_direct_object();
 } else {
 	undef $action;
 	die_error(undef, "Unknown action.");
@@ -1423,6 +1453,28 @@ sub git_blob_plain {
 	close $fd;
 }
 
+sub git_blob_html {
+	my $save_as = "$hash";
+	if (defined $file_name) {
+		$save_as = $file_name;
+	}
+	print $cgi->header(-type => "text/html", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\"");
+	open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
+	undef $/;
+	print <$fd>;
+	$/ = "\n";
+	close $fd;
+}
+
+sub git_direct_text {
+	print $cgi->header(-type => "test/plain");
+	exec("cat", "$projectroot/$project/$file_name");
+}
+sub git_direct_object {
+	print $cgi->header(-type => "application/binary", -expires => "+1y");
+	exec("cat", "$projectroot/$project/$file_name");
+}
+
 sub git_tree {
 	if (!defined $hash) {
 		$hash = git_read_head($project);
-- 
1.3.1.g6ef7


-- 
Martin Waitz

                 reply	other threads:[~2006-05-02 23:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060502232523.GN20847@admingilde.org \
    --to=tali@admingilde.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).