From a7e09a96a8b92913bebd89a45e43367c28a49072 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sun, 7 Aug 2005 20:00:05 +0200 Subject: [PATCH] v020 --- gitweb.pl | 70 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/gitweb.pl b/gitweb.pl index b1a9b661fb..85a5f530cc 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 020 # # (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,32 +30,32 @@ 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#/(.+)/treediff/([0-9a-fA-F]+)$#) { $project = $1; $action = "treediff"; $hash = $2; -} elsif ($url_parm =~ m#/([^/]+)/diff/([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) { +} elsif ($url_parm =~ m#/(.+)/diff/([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) { $project = $1; $action = "diff"; $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; @@ -74,19 +75,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'); @@ -129,9 +127,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,14 +209,14 @@ 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"; 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 "
"; @@ -224,11 +224,6 @@ if ($project eq "") { exit; } -if ($action eq "") { - print $cgi->redirect("$myself/$project/log/$view_back"); - exit; -} - if ($action eq "blob") { git_header(); print "

\n"; @@ -245,7 +240,7 @@ if ($action eq "blob") { 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; @@ -273,12 +268,12 @@ if ($action eq "blob") { print "
"; git_footer(); } elsif ($action eq "log") { - open my $fd, "$projectroot/.git/HEAD"; + 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"; @@ -291,7 +286,9 @@ if ($action eq "blob") { print "

\n"; print "
\n"; print "\n"; - foreach my $rev (reverse sort @revtree) { + 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; @@ -333,9 +330,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,6 +352,14 @@ if ($action eq "blob") { $age_string = int $age/60; $age_string .= " minutes ago"; } + if ($view_back > 0 && $age > $view_back*60*60*24) { + if ($i == 0) { + print "\n"; + print "\n"; + print "\n"; + } + last; + } print "\n"; print "\n"; print "";
Last change $age_string.
" . $age_string . "" . $cgi->a({-href => "$myself/$project/commit/$commit"}, $shortlog) . "