X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/e32bb2294da7e4d79967cd6e680fdef8e5b572a26dc1e481fe02a1d64e98ca24..48abd01729dbca9e676c3bad94dbfa11a6a1c4c08d17392a3e1dcc3a50a57b2c:/gitweb.cgi diff --git a/gitweb.cgi b/gitweb.cgi index 2731937..37997fc 100755 --- a/gitweb.cgi +++ b/gitweb.cgi @@ -10,11 +10,12 @@ use strict; use warnings; use CGI qw(:standard :escapeHTML); +use CGI::Util qw(unescape); use CGI::Carp qw(fatalsToBrowser); use Fcntl ':mode'; my $cgi = new CGI; -my $version = "145"; +my $version = "154"; my $my_url = $cgi->url(); my $my_uri = $cgi->url(-absolute => 1); my $rss_link = ""; @@ -36,7 +37,7 @@ my $home_text = "indextext.html"; # source of projects list #my $projects_list = $projectroot; -my $projects_list = "index/index.txt"; +my $projects_list = "index/index.aux"; # input validation and dispatch my $action = $cgi->param('a'); @@ -120,6 +121,9 @@ if (defined $time_back) { if ($action eq "summary") { git_summary(); exit; +} elsif ($action eq "branches") { + git_branches(); + exit; } elsif ($action eq "tags") { git_tags(); exit; @@ -192,7 +196,7 @@ div.title, a.title { a.title:hover { background-color: #d9d8d1; } div.title_text { padding:6px 8px; border: solid #d9d8d1; border-width:0px 0px 1px; } div.log_body { padding:8px 8px 8px 150px; } -span.log_age { position:relative; float:left; width:142px; font-style:italic; } +span.age { position:relative; float:left; width:142px; font-style:italic; } div.log_link { font-size:10px; font-family:sans-serif; font-style:normal; position:relative; float:left; width:142px; @@ -355,7 +359,7 @@ sub git_read_commit { $co{'parent'} = $parents[0]; my (@comment) = map { chomp; $_ } <$fd>; $co{'comment'} = \@comment; - $comment[0] =~ m/^(.{0,60}[^ ]*)/; + $comment[0] =~ m/^(.{0,60}[^ \/]*)/; $co{'title'} = $1; if ($comment[0] ne $co{'title'}) { $co{'title'} .= " ..."; @@ -381,10 +385,10 @@ sub git_read_commit { $co{'age_string'} .= " hours ago"; } elsif ($age > 60*2) { $co{'age_string'} = int $age/60; - $co{'age_string'} .= " minutes ago"; + $co{'age_string'} .= " min ago"; } elsif ($age > 2) { $co{'age_string'} = int $age; - $co{'age_string'} .= " seconds ago"; + $co{'age_string'} .= " sec ago"; } else { $co{'age_string'} .= " right now"; } @@ -563,7 +567,9 @@ sub git_project_list { open my $fd , $projects_list || return undef; while (my $line = <$fd>) { chomp $line; - my ($path, $owner) = split ':', $line; + my ($path, $owner) = split ' ', $line; + $path = unescape($path); + $owner = unescape($owner); if (!defined $path) { next; } @@ -643,39 +649,41 @@ sub git_project_list { git_footer_html(); } -sub git_read_tags { - my @taglist; +sub git_read_refs { + my $ref_dir = shift; + my @reflist; - opendir my $dh, "$projectroot/$project/refs/tags"; - my @tags = grep !m/^\./, readdir $dh; + opendir my $dh, "$projectroot/$project/$ref_dir"; + my @refs = grep !m/^\./, readdir $dh; closedir($dh); - foreach my $tag_file (@tags) { - my $tag_id = git_read_hash("$project/refs/tags/$tag_file"); - my $type = git_get_type($tag_id) || next; - my %tag_item; + foreach my $ref_file (@refs) { + my $ref_id = git_read_hash("$project/$ref_dir/$ref_file"); + my $type = git_get_type($ref_id) || next; + my %ref_item; my %co; if ($type eq "tag") { - my %tag = git_read_tag($tag_id); + my %tag = git_read_tag($ref_id); if ($tag{'type'} eq "commit") { %co = git_read_commit($tag{'object'}); } - $tag_item{'type'} = $tag{'type'}; - $tag_item{'name'} = $tag{'name'}; - $tag_item{'id'} = $tag{'object'}; + $ref_item{'type'} = $tag{'type'}; + $ref_item{'name'} = $tag{'name'}; + $ref_item{'id'} = $tag{'object'}; } elsif ($type eq "commit"){ - %co = git_read_commit($tag_id); - $tag_item{'type'} = "commit"; - $tag_item{'name'} = $tag_file; - $tag_item{'id'} = $tag_id; + %co = git_read_commit($ref_id); + $ref_item{'type'} = "commit"; + $ref_item{'name'} = $ref_file; + $ref_item{'title'} = $co{'title'}; + $ref_item{'id'} = $ref_id; } - $tag_item{'epoch'} = $co{'author_epoch'} || 0; - $tag_item{'age'} = $co{'age_string'} || "unknown"; + $ref_item{'epoch'} = $co{'committer_epoch'} || 0; + $ref_item{'age'} = $co{'age_string'} || "unknown"; - push @taglist, \%tag_item; + push @reflist, \%ref_item; } # sort tags by age - @taglist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @taglist; - return \@taglist; + @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist; + return \@reflist; } sub git_summary { @@ -691,7 +699,9 @@ sub git_summary { open (my $fd , $projects_list); while (my $line = <$fd>) { chomp $line; - my ($pr, $ow) = split ':', $line; + my ($pr, $ow) = split ' ', $line; + $pr = unescape($pr); + $ow = unescape($ow); if ($pr eq $project) { $owner = $ow; last; @@ -721,41 +731,81 @@ sub git_summary { my (@revlist) = map { chomp; $_ } <$fd>; close $fd; print "
\n" . - $cgi->a({-href => "$my_uri?p=$project;a=log", -class => "title"}, "recent commits") . + $cgi->a({-href => "$my_uri?p=$project;a=log", -class => "title"}, "commits") . "
\n"; my $i = 10; + print "
\n" . + "\n"; foreach my $commit (@revlist) { my %co = git_read_commit($commit); my %ad = date_str($co{'author_epoch'}); - print "
\n" . - $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, - "$co{'age_string'}" . escapeHTML($co{'title'})) . "\n" . - "
\n"; - if (--$i == 0) { - print "
" . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "...") . "
\n"; + print "\n"; + if (--$i > 0) { + print "\n" . + "\n" . + "\n" . + "\n" . + ""; + } else { + print "\n" . + ""; last; } } - print "

\n"; + print "" . + "\n"; - my $taglist = git_read_tags(); + my $taglist = git_read_refs("refs/tags"); if (defined @$taglist) { print "
\n" . - $cgi->a({-href => "$my_uri?p=$project;a=tags", -class => "title"}, "recent tags") . + $cgi->a({-href => "$my_uri?p=$project;a=tags", -class => "title"}, "tags") . "
\n"; my $i = 10; + print "
\n" . + "
$co{'age_string'}$co{'author_name'}" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, escapeHTML($co{'title'})) . "" . + $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") . + " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") . + "
" . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "...") . "
\n"; foreach my $entry (@$taglist) { my %tag = %$entry; - print "
\n" . - $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, - "$tag{'age'}" . escapeHTML($tag{'name'})) . "\n" . - "
\n"; - if (--$i == 0) { - print "
" . $cgi->a({-href => "$my_uri?p=$project;a=tags"}, "...") . "
\n"; + print "\n"; + if (--$i > 0) { + print "\n" . + "\n" . + ""; + } else { + print "\n" . + ""; + last; + } + } + print "" . + "\n"; + } + + my $branchlist = git_read_refs("refs/heads"); + if (defined @$branchlist) { + print "
\n" . + $cgi->a({-href => "$my_uri?p=$project;a=branches", -class => "title"}, "branches") . + "
\n"; + my $i = 10; + print "
\n" . + "
$tag{'age'}" . $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, escapeHTML($tag{'name'})) . "
" . $cgi->a({-href => "$my_uri?p=$project;a=tags"}, "...") . "
\n"; + foreach my $entry (@$branchlist) { + my %tag = %$entry; + print "\n"; + if (--$i > 0) { + print "\n" . + "\n" . + ""; + } else { + print "\n" . + ""; last; } } - print "

\n"; + print "" . + "\n"; } git_footer_html(); } @@ -769,7 +819,7 @@ sub git_tags { " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree"}, "tree") . "

\n" . "\n"; - my $taglist = git_read_tags(); + my $taglist = git_read_refs("refs/tags"); print "
\n" . $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "tags") . "
\n"; @@ -778,7 +828,33 @@ sub git_tags { my %tag = %$entry; print "
\n" . $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, - "$tag{'age'}" . escapeHTML($tag{'name'})) . "\n" . + "$tag{'age'}" . escapeHTML($tag{'name'})) . "\n" . + "
\n"; + } + } + print "

\n"; + git_footer_html(); +} + +sub git_branches { + my $head = git_read_hash("$project/HEAD"); + git_header_html(); + print "
\n" . + $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") . + " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") . + " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree"}, "tree") . + "

\n" . + "
\n"; + my $taglist = git_read_refs("refs/heads"); + print "
\n" . + $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "branches") . + "
\n"; + if (defined @$taglist) { + foreach my $entry (@$taglist) { + my %tag = %$entry; + print "
\n" . + $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, + "$tag{'age'}" . escapeHTML($tag{'name'})) . "\n" . "
\n"; } } @@ -963,7 +1039,9 @@ sub git_rss { } sub git_log { - my $head = git_read_hash("$project/HEAD"); + if (!defined $hash) { + $hash = git_read_hash("$project/HEAD"); + } my $limit_option = ""; if (!defined $time_back) { $limit_option = "--max-count=10"; @@ -971,7 +1049,7 @@ sub git_log { my $date = time - $time_back*24*60*60; $limit_option = "--max-age=$date"; } - open my $fd, "-|", "$gitbin/git-rev-list $limit_option $head" || die_error(undef, "Open failed."); + open my $fd, "-|", "$gitbin/git-rev-list $limit_option $hash" || die_error(undef, "Open failed."); my (@revlist) = map { chomp; $_ } <$fd>; close $fd || die_error(undef, "Reading rev-list failed."); @@ -987,7 +1065,7 @@ sub git_log { "\n"; if (!@revlist) { - my %co = git_read_commit($head); + my %co = git_read_commit($hash); print "
Last change $co{'age_string'}.

\n"; } @@ -997,7 +1075,7 @@ sub git_log { my %ad = date_str($co{'author_epoch'}); print "
\n" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"}, - "$co{'age_string'}" . escapeHTML($co{'title'})) . "\n" . + "$co{'age_string'}" . escapeHTML($co{'title'})) . "\n" . "
\n"; print "
\n" . "
\n" . @@ -1256,6 +1334,30 @@ sub git_commitdiff { $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" . "
\n"; print "
\n"; + my $comment = $co{'comment'}; + my $empty = 0; + my $signed = 0; + my @log = @$comment; + # remove first and empty lines after that + shift @log; + while (defined $log[0] && $log[0] eq "") { + shift @log; + } + foreach my $line (@log) { + if ($line =~ m/^(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) { + next; + } + if ($line eq "") { + if ($empty) { + next; + } + $empty = 1; + } else { + $empty = 0; + } + print escapeHTML($line) . "
\n"; + } + print "
\n"; foreach my $line (@difftree) { # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile' $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/; @@ -1338,7 +1440,7 @@ sub git_history { } print "
\n" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, - "$co{'age_string'}" . escapeHTML($co{'title'})) . "\n" . + "$co{'age_string'}" . escapeHTML($co{'title'})) . "\n" . "
\n"; print "
\n" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
$tag{'age'}" . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, escapeHTML($tag{'name'})) . "
" . $cgi->a({-href => "$my_uri?p=$project;a=branches"}, "...") . "