X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/3a6fd6520897b9bb4fb9ab9b52e1b97d3127cc124dae8d31307ce4abc8383c42..43c53ef1b0c0237c2e7c075ba8f0c153456f1eb63387dacf6226dde5ca41af6c:/gitweb.cgi diff --git a/gitweb.cgi b/gitweb.cgi index e80be7d..fc1ac0f 100755 --- a/gitweb.cgi +++ b/gitweb.cgi @@ -14,18 +14,21 @@ use CGI::Carp qw(fatalsToBrowser); my $cgi = new CGI; -my $version = "056"; -my $projectroot = "/home/kay/public_html/pub/scm"; +my $version = "063"; +my $projectroot = "/pub/scm"; my $defaultprojects = "linux/kernel/git"; -my $gitbin = "/home/kay/bin/git"; -my $gittmp = "/tmp"; +my $gitbin = "/usr/bin"; +my $gittmp = "/tmp/gitweb"; +my $giturl = "/pub/software/scm/cogito"; my $my_url = $cgi->url(); my $my_uri = $cgi->url(-absolute => 1); +mkdir($gittmp, 0700); my $project = $cgi->param('p'); my $action = $cgi->param('a'); my $hash = $cgi->param('h'); my $hash_parent = $cgi->param('hp'); +my $file_name = $cgi->param('f'); my $time_back = $cgi->param('t'); $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects"; @@ -33,6 +36,9 @@ $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects"; if (defined($project) && $project =~ /(^|\/)(|\.|\.\.)($|\/)/) { die_error("", "Invalid project parameter."); } +if (defined($file_name) && $file_name =~ /(^|\/)(|\.|\.\.)($|\/)/) { + die_error("", "Invalid file parameter."); +} if (defined($action) && !$action =~ m/^[0-9a-zA-Z\.\-]+$/) { die_error("", "Invalid action parameter."); } @@ -44,8 +50,6 @@ if (defined($hash_parent) && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) { } if (defined($time_back) && !($time_back =~ m/^[0-9]+$/)) { die_error("", "Invalid time parameter."); -} else { - $time_back = 1; } sub git_header_html { @@ -77,6 +81,10 @@ sub git_header_html { } div.page_footer_text { float:left; color:#888888; font-size:10px;} div.page_body { margin:0px 25px; padding:8px; clear:both; border: solid #d9d8d1; border-width:0px 1px; } + div.title { + display:block; margin:0px 25px; padding:8px; clear:both; + font-weight:bold; background-color: #d9d8d1; color:#000000; + } a.log_title { display:block; margin:0px 25px; padding:8px; clear:both; font-weight:bold; background-color: #d9d8d1; text-decoration:none; color:#000000; @@ -107,7 +115,7 @@ sub git_header_html { EOF print "
\n" . - "" . + "" . "\"git\""; if ($defaultprojects ne "") { print $cgi->a({-href => "$my_uri"}, "projects") . " / "; @@ -186,6 +194,28 @@ sub git_commit { $co{'comment'} = \@comment; $co{'title'} = $comment[0]; close $fd; + + my $age = time - $co{'committer_epoch'}; + $co{'age'} = $age; + if ($age > 60*60*24*365*2) { + $co{'age_string'} = (int $age/60/60/24/365); + $co{'age_string'} .= " years ago"; + } elsif ($age > 60*60*24*365/12*2) { + $co{'age_string'} = int $age/60/60/24/365/12; + $co{'age_string'} .= " months ago"; + } elsif ($age > 60*60*24*7*2) { + $co{'age_string'} = int $age/60/60/24/7; + $co{'age_string'} .= " weeks ago"; + } elsif ($age > 60*60*24*2) { + $co{'age_string'} = int $age/60/60/24; + $co{'age_string'} .= " days ago"; + } elsif ($age > 60*60*2) { + $co{'age_string'} = int $age/60/60; + $co{'age_string'} .= " hours ago"; + } elsif ($age > 60*2) { + $co{'age_string'} = int $age/60; + $co{'age_string'} .= " minutes ago"; + } return %co; } @@ -339,12 +369,19 @@ if ($project eq "") { exit; } -if ($action eq "") { +if (!defined($action)) { $action = "log"; } +if (!defined($time_back)) { + $time_back = 1; +} + if ($action eq "blob") { git_header_html(); + print "
\n"; + print "

\n"; + print "
$hash
\n"; print "


\n"; open(my $fd, "-|", "$gitbin/cat-file blob $hash"); my $nr; @@ -364,6 +401,9 @@ if ($action eq "blob") { my (@entries) = map { chomp; $_ } <$fd>; close $fd; git_header_html(); + print "
\n"; + print "

\n"; + print "
$hash
\n"; print "
\n"; print "
\n";
 	foreach my $line (@entries) {
@@ -374,9 +414,9 @@ if ($action eq "blob") {
 		my $t_hash = $3;
 		my $t_name = $4;
 		if ($t_type eq "blob") {
-			print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash"}, $t_name) . "\n";
+			print mode_str($t_mode). " $t_name (" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash"}, "view") . ")\n";
 		} elsif ($t_type eq "tree") {
-			print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash"}, $t_name) . "\n";
+			print mode_str($t_mode). " $t_name (" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash"}, "view") . ")\n";
 		}
 	}
 	print "
\n"; @@ -384,7 +424,7 @@ if ($action eq "blob") { git_footer_html(); } elsif ($action eq "log" || $action eq "rss") { open my $fd, "-|", "$gitbin/rev-list " . git_head($project); - my (@revtree) = map { chomp; $_ } <$fd>; + my (@revlist) = map { chomp; $_ } <$fd>; close $fd; if ($action eq "log") { @@ -409,40 +449,19 @@ if ($action eq "blob") { "en\n"; } - for (my $i = 0; $i <= $#revtree; $i++) { - my $commit = $revtree[$i]; + for (my $i = 0; $i <= $#revlist; $i++) { + my $commit = $revlist[$i]; my %co = git_commit($commit); my %ad = date_str($co{'author_epoch'}); - my $age = time - $co{'committer_epoch'}; - my $age_string; - if ($age > 60*60*24*365*2) { - $age_string = int $age/60/60/24/365; - $age_string .= " years ago"; - } elsif ($age > 60*60*24*365/12*2) { - $age_string = int $age/60/60/24/365/12; - $age_string .= " months ago"; - } elsif ($age > 60*60*24*7*2) { - $age_string = int $age/60/60/24/7; - $age_string .= " weeks ago"; - } elsif ($age > 60*60*24*2) { - $age_string = int $age/60/60/24; - $age_string .= " days ago"; - } elsif ($age > 60*60*2) { - $age_string = int $age/60/60; - $age_string .= " hours ago"; - } elsif ($age > 60*2) { - $age_string = int $age/60; - $age_string .= " minutes ago"; - } if ($action eq "log") { - if ($time_back > 0 && $age > $time_back*60*60*24) { + if ($time_back > 0 && $co{'age'} > $time_back*60*60*24) { if ($i == 0) { - print "
Last change $age_string.

\n"; + print "
Last change " . $co{'age_string'} . ".

\n"; } last; } print "
\n" . - "" . $age_string . "\n" . escapeHTML($co{'title'}) . "\n" . + "" . $co{'age_string'} . "\n" . escapeHTML($co{'title'}) . "\n" . "
\n"; print "
\n" . "
\n" . @@ -466,7 +485,7 @@ if ($action eq "blob") { last if ($i >= 20); print "\n" . "\t" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'min'}) . " - " . escapeHTML($co{'title'}) . "\n" . - "\t " . $my_url . "?p=$project;a==commit;h=$commit\n" . + "\t " . $my_url . "?p=$project;a=commit;h=$commit\n" . "\t"; my $comment = $co{'comment'}; foreach my $line (@$comment) { @@ -492,7 +511,7 @@ if ($action eq "blob") { git_header_html(); print "
view\n" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" . - $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff") . "\n" . + $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . "\n" . "

\n"; print "$co{'title'}\n"; print "
\n"; @@ -537,14 +556,19 @@ if ($action eq "blob") { my $modestr = mode_str($1); if ($type eq "blob") { if ($op eq "+") { - print "$modestr " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$id"}, $file) . " (new)\n"; + print "$modestr $file" . "[new] " . + "(" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "view") . ")\n"; } elsif ($op eq "-") { - print "$modestr " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;hp=$id"}, $file) . " (removed)\n"; + print "$modestr $file" . "[removed] " . + "(" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "view") . ")\n"; } elsif ($op eq "*") { $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/; my $from = $1; my $to = $2; - print "$modestr " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to;hp=$from"}, $file) . "\n"; + print "$modestr $file " . + "(" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to"}, "view") . ")" . + "(" . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to;hp=$from"}, "diff") . ")" . + "(" . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . ")\n"; } } } @@ -553,6 +577,9 @@ if ($action eq "blob") { git_footer_html(); } elsif ($action eq "blobdiff") { git_header_html(); + print "
\n"; + print "

\n"; + print "
$hash vs $hash_parent
\n"; print "


\n" . "
\n";
 	git_diff_html($hash_parent, $hash, $hash_parent, $hash);
@@ -568,7 +595,7 @@ if ($action eq "blob") {
 	git_header_html();
 	print "
view\n" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" . - $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff") . "\n" . + $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . "\n" . "

\n"; print $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, $co{'title'}) ."\n"; print "
\n" . @@ -595,6 +622,46 @@ if ($action eq "blob") { print "
\n"; print "
"; git_footer_html(); +} elsif ($action eq "history") { + if (!(defined($hash))) { + $hash = git_head($project); + } + open my $fd, "-|", "$gitbin/rev-list $hash"; + my (@revlist) = map { chomp; $_ } <$fd>; + close $fd; + + git_header_html(); + print "
\n"; + print "

\n"; + print "
$file_name
\n"; + print "
\n" . + "
\n";
+	foreach my $rev (@revlist) {
+		my %co = git_commit($rev);
+		my $parents  = $co{'parents'};
+		my $found = 0;
+		foreach my $parent (@$parents) {
+			open $fd, "-|", "$gitbin/diff-tree -r $parent $rev $file_name";
+			my (@difftree) = map { chomp; $_ } <$fd>;
+			close $fd;
+
+			foreach my $line (@difftree) {
+				$line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
+				my $file = $5;
+				if ($file eq $file_name) {
+					$found = 1;
+					last;
+				}
+			}
+		}
+		if ($found) {
+			print $co{'age_string'} . "\t " . $co{'author_name'} . "  - " . $co{'title'} .
+			      " (" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$rev"}, "view") .")\n";
+		}
+	}
+	print "
\n"; + print "
"; + git_footer_html(); } else { die_error("", "unknown action"); }