X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/6862b4874af58c044b00469c1686ab6313206b8ad8356f4cfffd9da468b96dcb..c8d1b5d66fe9fbf4a010cb88c8f5186a0bd8174dedd969a6918358321b4d9abb:/gitweb.pl diff --git a/gitweb.pl b/gitweb.pl index 504c1fb..94df765 100755 --- a/gitweb.pl +++ b/gitweb.pl @@ -2,7 +2,7 @@ # gitweb.pl - simple web interface to track changes in git repositories # -# Version 016 +# Version 021 # # (C) 2005, Kay Sievers # (C) 2005, Christian Gierke @@ -14,9 +14,10 @@ use warnings; use CGI qw(:standard :escapeHTML); use CGI::Carp qw(fatalsToBrowser); -my $gitbin = "/home/kay/bin/git"; # path to the git executables -my $gitroot = "/home/kay/public_html"; # path to the git repositories -my $gittmp = "/tmp"; # temporary files location +my $projectroot = "/home/kay/public_html"; +my $defaultprojects = "."; +my $gitbin = "/home/kay/bin/git"; +my $gittmp = "/tmp"; my $cgi = new CGI; my $project = ""; @@ -29,35 +30,39 @@ my $url_parm = $cgi->url(-path => 1); $url_parm =~ s/.*$myself//; # get values from url -if ($url_parm =~ m#/([^/]+)/commit/([0-9a-fA-F]+)$#) { +if ($url_parm =~ m#/(.+)/commit/([0-9a-fA-F]+)$#) { $project = $1; $action = "commit"; $hash = $2; -} elsif ($url_parm =~ m#/([^/]+)/treediff/([0-9a-fA-F]+)$#) { +} elsif ($url_parm =~ m#/(.+)/commitdiff/([0-9a-fA-F]+)$#) { $project = $1; - $action = "treediff"; + $action = "commitdiff"; $hash = $2; -} elsif ($url_parm =~ m#/([^/]+)/diff/([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) { +} elsif ($url_parm =~ m#/(.+)/blobdiff/([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) { $project = $1; - $action = "diff"; + $action = "blobdiff"; $hash = $2; $hash_parent = $3; -} elsif ($url_parm =~ m#/([^/]+)/blob/([0-9a-fA-F]+)$#) { +} elsif ($url_parm =~ m#/(.+)/blob/([0-9a-fA-F]+)$#) { $project = $1; $action = "blob"; $hash = $2; -} elsif ($url_parm =~ m#/([^/]+)/tree/([0-9a-fA-F]+)$#) { +} elsif ($url_parm =~ m#/(.+)/tree/([0-9a-fA-F]+)$#) { $project = $1; $action = "tree"; $hash = $2; -} elsif ($url_parm =~ m#/([^/]+)/log/([0-9]+)$#) { +} elsif ($url_parm =~ m#/(.+)/log/([0-9]+)$#) { $project = $1; $action = "log"; $view_back = $2; -} elsif ($url_parm =~ m#/([^/]+)/log$#) { +} elsif ($url_parm =~ m#/(.+)/log$#) { $project = $1; $action = "log"; $view_back = 1; +} elsif ($url_parm =~ m#/(.+)/rss$#) { + $project = $1; + $action = "rss"; + $view_back = 1; } elsif ($url_parm =~ m#/git-logo.png$#) { print $cgi->header(-type => 'image/png'); print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122". @@ -74,19 +79,16 @@ if ($url_parm =~ m#/([^/]+)/commit/([0-9a-fA-F]+)$#) { "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305". "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202"; exit; -} elsif ($url_parm =~ m#/([^/]+)$#) { +} elsif ($url_parm =~ m#/(.+)$#) { $project = $1; $action = "log"; $view_back = 1; } # sanitize input -$hash =~ s/[^0-9a-fA-F]//g; -$hash_parent =~ s/[^0-9a-fA-F]//g; -$project =~ s/[^0-9a-zA-Z\-\._]//g; +$project =~ s#\/\.+##g; -my $projectroot = "$gitroot/$project"; -$ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/.git/objects"; +$ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/.git/objects"; sub git_header { print $cgi->header(-type => 'text/html; charset: utf-8'); @@ -95,6 +97,7 @@ print < git - $project $action + @@ -129,9 +132,11 @@ EOF print "
\n"; print "
"; print "\"git\""; - print $cgi->a({-href => "$myself"}, "projects"); + if ($defaultprojects ne "") { + print $cgi->a({-href => "$myself"}, "projects") . " / "; + } if ($project ne "") { - print " / " . $cgi->a({-href => "$myself/$project/log"}, $project); + print $cgi->a({-href => "$myself/$project/log"}, $project); } if ($action ne "") { print " / $action"; @@ -209,29 +214,25 @@ sub git_diff { } if ($project eq "") { - opendir(my $fd, $gitroot); + opendir(my $fd, "$projectroot/$defaultprojects"); my (@path) = grep(!/^\./, readdir($fd)); closedir($fd); git_header(); - print "

\n"; + print "
\n"; + print "

\n"; foreach my $line (@path) { - if (-e "$gitroot/$line/.git/HEAD") { - print $cgi->a({-href => "$myself/$line/log"}, $line) . "
\n"; + if (-e "$projectroot/$defaultprojects/$line/.git/HEAD") { + print $cgi->a({-href => "$myself/$defaultprojects/$line/log"}, $line) . "
\n"; } } - print "
"; + print "

"; git_footer(); exit; } -if ($action eq "") { - print $cgi->redirect("$myself/$project/log/$view_back"); - exit; -} - if ($action eq "blob") { git_header(); - print "

\n"; + print "

\n"; print "
\n";
 	open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
 	my $nr;
@@ -241,11 +242,11 @@ if ($action eq "blob") {
 	}
 	close $fd;
 	print "
\n"; - print "
"; + print "
"; git_footer(); } elsif ($action eq "tree") { if ($hash eq "") { - open my $fd, "$projectroot/.git/HEAD"; + open my $fd, "$projectroot/$project/.git/HEAD"; my $head = <$fd>; chomp $head; close $fd; @@ -255,7 +256,7 @@ if ($action eq "blob") { my (@entries) = map { chomp; $_ } <$fd>; close $fd; git_header(); - print "

\n"; + print "

\n"; print "
\n";
 	foreach my $line (@entries) {
 		#'100644	blob	0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa	panic.c'
@@ -270,28 +271,43 @@ if ($action eq "blob") {
 		}
 	}
 	print "
\n"; - print "
"; + print "
"; git_footer(); -} elsif ($action eq "log") { - open my $fd, "$projectroot/.git/HEAD"; +} elsif ($action eq "log" || $action eq "rss") { + open my $fd, "$projectroot/$project/.git/HEAD"; my $head = <$fd>; chomp $head; close $fd; open $fd, "-|", "$gitbin/rev-tree", $head; - my (@revtree) = map { chomp; $_ } <$fd>; + my (@revtree) = reverse sort map { chomp; $_ } <$fd>; close $fd; - git_header(); - print "
\n"; - print "view "; - print $cgi->a({-href => "$myself/$project/log"}, "last day") . " | "; - print $cgi->a({-href => "$myself/$project/log/7"}, "week") . " | "; - print $cgi->a({-href => "$myself/$project/log/31"}, "month") . " | "; - print $cgi->a({-href => "$myself/$project/log/365"}, "year") . " | "; - print $cgi->a({-href => "$myself/$project/log/0"}, "all") . "
\n"; - print "

\n"; - print "
\n"; - print "\n"; - foreach my $rev (reverse sort @revtree) { + + if ($action eq "log") { + git_header(); + print "
\n"; + print "view "; + print $cgi->a({-href => "$myself/$project/log"}, "last day") . " | "; + print $cgi->a({-href => "$myself/$project/log/7"}, "week") . " | "; + print $cgi->a({-href => "$myself/$project/log/31"}, "month") . " | "; + print $cgi->a({-href => "$myself/$project/log/365"}, "year") . " | "; + print $cgi->a({-href => "$myself/$project/log/0"}, "all") . "
\n"; + print "

\n"; + print "
\n"; + print "
\n"; + } elsif ($action eq "rss") { + print $cgi->header(-type => 'text/xml; charset: utf-8'); + print "\n". + "\n"; + print "\n"; + print "$project\n". + " " . $cgi->url() . "/$project/log\n". + "$project log\n". + "en\n"; + } + + for (my $i = 0; $i <= $#revtree; $i++) { + my $rev = $revtree[$i]; + #foreach my $rev (@revtree) { # '1114106118 755e3010ee10dadf42a8a80770e1b115fb038d9b:1 2af17b4854036a1c2ec6c101d93c8dd1ed80d24e:1' last if !($rev =~ m/^([0-9]+) ([0-9a-fA-F]+).* ([0-9a-fA-F]+)/); my $time = $1; @@ -322,6 +338,7 @@ if ($action eq "blob") { } } $shortlog = <$fd>; + chomp($shortlog); $shortlog = escapeHTML($shortlog); $comment = $shortlog . "
"; while (my $line = <$fd>) { @@ -333,9 +350,8 @@ if ($action eq "blob") { } } close $fd; - my $age = time-$committer_time; - last if ($view_back > 0 && $age > $view_back*60*60*24); + my $age = time-$committer_time; my $age_string; if ($age > 60*60*24*365*2) { $age_string = int $age/60/60/24/365; @@ -356,35 +372,55 @@ if ($action eq "blob") { $age_string = int $age/60; $age_string .= " minutes ago"; } - print "
\n"; - print "\n"; - print ""; - print "\n"; - print "\n"; - print "\n"; - print "\n"; + print "\n"; + print "\n"; + } + last; + } + print "\n"; + print "\n"; + print ""; + print "\n"; + print "\n"; + print "\n"; + print ""; + print "\n"; + print "\n"; + print "\n"; + print ""; + print "\n"; + } elsif ($action eq "rss") { + if ($i < 12) { + print "\n\t$age_string: $shortlog\n"; + print "\t " . $cgi->url() . "/$project/commit/$commit\n"; + print "\n"; + } } - print ""; - print "\n"; - print "\n"; - print "\n"; - print ""; - print "\n"; } - print "
" . $age_string . "" . $cgi->a({-href => "$myself/$project/commit/$commit"}, $shortlog) . "
"; - print $cgi->a({-href => "$myself/$project/treediff/$commit"}, "view diff") . "
\n"; - print $cgi->a({-href => "$myself/$project/commit/$commit"}, "view commit") . "
\n"; - print $cgi->a({-href => "$myself/$project/tree/$tree"}, "view tree") . "
\n"; - print "
\n"; - print "author    " . escapeHTML($author) . " [" . gmtime($author_time) . " " . $author_timezone . "]
\n"; - print "committer " . escapeHTML($committer) . " [" . gmtime($committer_time) . " " . $committer_timezone . "]
\n"; - print "commit    $commit
\n"; - print "tree      $tree
\n"; - foreach my $par (@parents) { - print "parent    $par
\n"; + if ($action eq "log") { + if ($view_back > 0 && $age > $view_back*60*60*24) { + if ($i == 0) { + print "
Last change $age_string.
" . $age_string . "" . $cgi->a({-href => "$myself/$project/commit/$commit"}, $shortlog) . "
"; + print $cgi->a({-href => "$myself/$project/commitdiff/$commit"}, "view diff") . "
\n"; + print $cgi->a({-href => "$myself/$project/commit/$commit"}, "view commit") . "
\n"; + print $cgi->a({-href => "$myself/$project/tree/$tree"}, "view tree") . "
\n"; + print "
\n"; + print "author    " . escapeHTML($author) . " [" . gmtime($author_time) . " " . $author_timezone . "]
\n"; + print "committer " . escapeHTML($committer) . " [" . gmtime($committer_time) . " " . $committer_timezone . "]
\n"; + print "commit    $commit
\n"; + print "tree      $tree
\n"; + foreach my $par (@parents) { + print "parent    $par
\n"; + } + print "
\n"; + print "$comment

\n"; + print "
\n"; - print "$comment

\n"; - print "
\n"; - git_footer(); + if ($action eq "log") { + print "\n"; + git_footer(); + } elsif ($action eq "rss") { + print ""; + } } elsif ($action eq "commit") { my $parent = ""; open my $fd, "-|", "$gitbin/cat-file", "commit", $hash; @@ -404,8 +440,8 @@ if ($action eq "blob") { close $fd; git_header(); - print "
\n"; - print "view " . $cgi->a({-href => "$myself/$project/treediff/$hash"}, "diff") . "


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


\n"; print "
$shortlog
\n"; print "
\n";
 	foreach my $line (@difftree) {
@@ -426,22 +462,22 @@ 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/diff/$old/$new"}, $file) . "\n";
+				print "changed\t" . $cgi->a({-href => "$myself/$project/blobdiff/$old/$new"}, $file) . "\n";
 			}
 		}
 	}
 	print "
\n"; - print "
"; + print "
"; git_footer(); -} elsif ($action eq "diff") { +} elsif ($action eq "blobdiff") { git_header(); - print "

\n"; + print "

\n"; print "
\n";
 	git_diff($hash, $hash_parent, $hash, $hash_parent);
 	print "
\n"; - print "
"; + print "
"; git_footer(); -} elsif ($action eq "treediff") { +} elsif ($action eq "commitdiff") { my $parent = ""; open my $fd, "-|", "$gitbin/cat-file", "commit", $hash; while (my $line = <$fd>) { @@ -460,8 +496,8 @@ if ($action eq "blob") { close $fd; git_header(); - print "
\n"; - print "view " . $cgi->a({-href => "$myself/$project/commit/$hash"}, "commit") . "


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


\n"; print "
$shortlog
\n"; print "
\n";
 	foreach my $line (@difftree) {
@@ -484,12 +520,6 @@ if ($action eq "blob") {
 		}
 	}
 	print "
\n"; - print "
"; - git_footer(); -} else { - git_header(); - print "

\n"; - print "unknown action\n"; - print "
"; + print "
"; git_footer(); }