From 823d5dc81f7452395725cf771e5710b113c7b27c Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sun, 7 Aug 2005 19:57:58 +0200 Subject: [PATCH] v005 --- gitweb.pl | 63 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/gitweb.pl b/gitweb.pl index 09e0eca70a..25bd65e5f2 100755 --- a/gitweb.pl +++ b/gitweb.pl @@ -2,11 +2,12 @@ # gitweb.pl - simple web interface to track changes in git repositories # -# Version 004 +# Version 005 # -# This file is licensed under the GPL v2, or a later version # (C) 2005, Kay Sievers # (C) 2005, Christian Gierke +# +# This file is licensed under the GPL v2, or a later version use strict; use warnings; @@ -22,15 +23,15 @@ my $myself = $cgi->url(-relative => 1); my $project = $cgi->param("project") || ""; my $action = $cgi->param("action") || ""; my $hash = $cgi->param("hash") || ""; -my $parent = $cgi->param("parent") || ""; +my $hash_parent = $cgi->param("hash_parent") || ""; my $view_back = $cgi->param("view_back") || 60*60*24; my $projectroot = "$gitroot/$project"; -$ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/.git/objects"; - $hash =~ s/[^0-9a-fA-F]//g; -$parent =~ s/[^0-9a-fA-F]//g; +$hash_parent =~ s/[^0-9a-fA-F]//g; $project =~ s/[^0-9a-zA-Z\-\._]//g; +$ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/.git/objects"; + sub git_header { print $cgi->header(-type => 'text/html; charset: utf-8'); print <\n"; print "" . $age_string . "\n"; - print "" . $cgi->a({-href => "$myself?project=$project;action=commit;hash=$commit;parent=$parent"}, $shortlog) . ""; + print "" . $cgi->a({-href => "$myself?project=$project;action=commit;hash=$commit"}, $shortlog) . ""; print "\n"; print "\n"; print ""; - print $cgi->a({-href => "$myself?project=$project;action=treediff;hash=$commit;parent=$parent"}, "view diff") . "
\n"; - print $cgi->a({-href => "$myself?project=$project;action=commit;hash=$commit;parent=$parent"}, "view commit") . "
\n"; + print $cgi->a({-href => "$myself?project=$project;action=treediff;hash=$commit"}, "view diff") . "
\n"; + print $cgi->a({-href => "$myself?project=$project;action=commit;hash=$commit"}, "view commit") . "
\n"; print $cgi->a({-href => "$myself?project=$project;action=tree;hash=$tree"}, "view tree") . "
\n"; print "\n"; print "\n"; @@ -335,13 +336,27 @@ if ($action eq "blob") { print "\n"; git_footer(); } elsif ($action eq "commit") { - open my $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash; + my $parent = ""; + open my $fd, "-|", "$gitbin/cat-file", "commit", $hash; + while (my $line = <$fd>) { + chomp($line); + last if $line eq ""; + if ($line =~ m/^parent (.*)$/ && $parent eq "") { + $parent = $1; + } + } + my $shortlog = <$fd>; + $shortlog = escapeHTML($shortlog); + close $fd; + + open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash; my (@difftree) = map { chomp; $_ } <$fd>; close $fd; git_header(); - print "
\n"; - print "view " . $cgi->a({-href => "$myself?project=$project;action=treediff;hash=$hash;parent=$parent"}, "diff") . "

\n"; + print "
\n"; + print "view " . $cgi->a({-href => "$myself?project=$project;action=treediff;hash=$hash"}, "diff") . "


\n"; + print "$shortlog
\n"; print "
\n";
 	foreach my $line (@difftree) {
 		# '*100644->100644	blob	9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596	net/ipv4/route.c'
@@ -361,7 +376,7 @@ if ($action eq "blob") {
 				$id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
 				my $old = $1;
 				my $new = $2;
-				print "CHANGED\t" . $cgi->a({-href => "$myself?project=$project;action=diff;hash=$old;parent=$new"}, $file) . "\n";
+				print "CHANGED\t" . $cgi->a({-href => "$myself?project=$project;action=diff;hash=$old;hash_parent=$new"}, $file) . "\n";
 			}
 		}
 	}
@@ -372,18 +387,32 @@ if ($action eq "blob") {
 	git_header();
 	print "

\n"; print "
\n";
-	git_diff($hash, $parent, $hash, $parent);
+	git_diff($hash, $hash_parent, $hash, $hash_parent);
 	print "
\n"; print "
"; git_footer(); } elsif ($action eq "treediff") { - open my $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash; + my $parent = ""; + open my $fd, "-|", "$gitbin/cat-file", "commit", $hash; + while (my $line = <$fd>) { + chomp($line); + last if $line eq ""; + if ($line =~ m/^parent (.*)$/ && $parent eq "") { + $parent = $1; + } + } + my $shortlog = <$fd>; + $shortlog = escapeHTML($shortlog); + close $fd; + + open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash; my (@difftree) = map { chomp; $_ } <$fd>; close $fd; git_header(); - print "
\n"; - print "view " . $cgi->a({-href => "$myself?project=$project;action=commit;hash=$hash;parent=$parent"}, "commit") . "

\n"; + print "
\n"; + print "view " . $cgi->a({-href => "$myself?project=$project;action=commit;hash=$hash"}, "commit") . "


\n"; + print "$shortlog
\n"; print "
\n";
 	foreach my $line (@difftree) {
 		# '*100644->100644	blob	8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154	Makefile'