allow sorting of index page by project path, owner and age
parent
e4669df9a6
commit
f7ab660c15
100
gitweb.cgi
100
gitweb.cgi
|
@ -15,7 +15,7 @@ use CGI::Carp qw(fatalsToBrowser);
|
||||||
use Fcntl ':mode';
|
use Fcntl ':mode';
|
||||||
|
|
||||||
my $cgi = new CGI;
|
my $cgi = new CGI;
|
||||||
my $version = "237";
|
my $version = "238";
|
||||||
my $my_url = $cgi->url();
|
my $my_url = $cgi->url();
|
||||||
my $my_uri = $cgi->url(-absolute => 1);
|
my $my_uri = $cgi->url(-absolute => 1);
|
||||||
my $rss_link = "";
|
my $rss_link = "";
|
||||||
|
@ -56,6 +56,14 @@ if (defined $action) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $order = $cgi->param('o');
|
||||||
|
if (defined $order) {
|
||||||
|
if ($order =~ m/[^a-zA-Z0-9_]/) {
|
||||||
|
undef $order;
|
||||||
|
die_error(undef, "Invalid order parameter.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $project = $cgi->param('p');
|
my $project = $cgi->param('p');
|
||||||
if (defined $project) {
|
if (defined $project) {
|
||||||
if ($project =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
|
if ($project =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
|
||||||
|
@ -314,7 +322,7 @@ sub git_footer_html {
|
||||||
}
|
}
|
||||||
print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
|
print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
|
||||||
} else {
|
} else {
|
||||||
print $cgi->a({-href => "$my_uri?a=opml", -class => "rss_logo"}, "RSS") . "\n";
|
print $cgi->a({-href => "$my_uri?a=opml", -class => "rss_logo"}, "OPML") . "\n";
|
||||||
}
|
}
|
||||||
print "</div>\n" .
|
print "</div>\n" .
|
||||||
"</body>\n" .
|
"</body>\n" .
|
||||||
|
@ -753,9 +761,30 @@ sub git_read_projects {
|
||||||
|
|
||||||
sub git_project_list {
|
sub git_project_list {
|
||||||
my @list = git_read_projects();
|
my @list = git_read_projects();
|
||||||
|
my @projects;
|
||||||
if (!@list) {
|
if (!@list) {
|
||||||
die_error(undef, "No project found.");
|
die_error(undef, "No project found.");
|
||||||
}
|
}
|
||||||
|
foreach my $pr (@list) {
|
||||||
|
my $head = git_read_hash("$pr->{'path'}/HEAD");
|
||||||
|
if (!defined $head) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
$ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
|
||||||
|
my %co = git_read_commit($head);
|
||||||
|
if (!%co) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
$pr->{'commit'} = \%co;
|
||||||
|
if (!defined $pr->{'descr'}) {
|
||||||
|
my $descr = git_read_description($pr->{'path'}) || "";
|
||||||
|
$pr->{'descr'} = chop_str($descr, 25, 5);
|
||||||
|
}
|
||||||
|
if (!defined $pr->{'owner'}) {
|
||||||
|
$pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
|
||||||
|
}
|
||||||
|
push @projects, $pr;
|
||||||
|
}
|
||||||
git_header_html();
|
git_header_html();
|
||||||
if (-f $home_text) {
|
if (-f $home_text) {
|
||||||
print "<div class=\"index_include\">\n";
|
print "<div class=\"index_include\">\n";
|
||||||
|
@ -765,53 +794,52 @@ sub git_project_list {
|
||||||
print "</div>\n";
|
print "</div>\n";
|
||||||
}
|
}
|
||||||
print "<table cellspacing=\"0\">\n" .
|
print "<table cellspacing=\"0\">\n" .
|
||||||
"<tr>\n" .
|
"<tr>\n";
|
||||||
"<th>Project</th>\n" .
|
if (defined($order) && ($order eq "project")) {
|
||||||
"<th>Description</th>\n" .
|
@projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
|
||||||
"<th>Owner</th>\n" .
|
print "<th>Project</th>\n";
|
||||||
"<th>last change</th>\n" .
|
} else {
|
||||||
"<th></th>\n" .
|
print "<th>" . $cgi->a({-class => "list", -href => "$my_uri?o=project"}, "Project") . "</th>\n";
|
||||||
|
}
|
||||||
|
print "<th>Description</th>\n";
|
||||||
|
if (defined($order) && ($order eq "owner")) {
|
||||||
|
@projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
|
||||||
|
print "<th>Owner</th>\n";
|
||||||
|
} else {
|
||||||
|
print "<th>" . $cgi->a({-class => "list", -href => "$my_uri?o=owner"}, "Owner") . "</th>\n";
|
||||||
|
}
|
||||||
|
if (defined($order) && ($order eq "age")) {
|
||||||
|
@projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
|
||||||
|
print "<th>last change</th>\n";
|
||||||
|
} else {
|
||||||
|
print "<th>" . $cgi->a({-class => "list", -href => "$my_uri?o=age"}, "last change") . "</th>\n";
|
||||||
|
}
|
||||||
|
print "<th></th>\n" .
|
||||||
"</tr>\n";
|
"</tr>\n";
|
||||||
my $alternate = 0;
|
my $alternate = 0;
|
||||||
foreach my $pr (@list) {
|
foreach my $pr (@projects) {
|
||||||
my %proj = %$pr;
|
|
||||||
my $head = git_read_hash("$proj{'path'}/HEAD");
|
|
||||||
if (!defined $head) {
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
$ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
|
|
||||||
my %co = git_read_commit($head);
|
|
||||||
if (!%co) {
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
my $descr = git_read_description($proj{'path'}) || "";
|
|
||||||
$descr = chop_str($descr, 25, 5);
|
|
||||||
# get directory owner if not already specified
|
|
||||||
if (!defined $proj{'owner'}) {
|
|
||||||
$proj{'owner'} = get_file_owner("$projectroot/$proj{'path'}") || "";
|
|
||||||
}
|
|
||||||
if ($alternate) {
|
if ($alternate) {
|
||||||
print "<tr class=\"dark\">\n";
|
print "<tr class=\"dark\">\n";
|
||||||
} else {
|
} else {
|
||||||
print "<tr class=\"light\">\n";
|
print "<tr class=\"light\">\n";
|
||||||
}
|
}
|
||||||
$alternate ^= 1;
|
$alternate ^= 1;
|
||||||
print "<td>" . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary", -class => "list"}, escapeHTML($proj{'path'})) . "</td>\n" .
|
print "<td>" . $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=summary", -class => "list"}, escapeHTML($pr->{'path'})) . "</td>\n" .
|
||||||
"<td>$descr</td>\n" .
|
"<td>$pr->{'descr'}</td>\n" .
|
||||||
"<td><i>" . chop_str($proj{'owner'}, 15) . "</i></td>\n";
|
"<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
|
||||||
my $colored_age;
|
my $colored_age;
|
||||||
if ($co{'age'} < 60*60*2) {
|
if ($pr->{'commit'}{'age'} < 60*60*2) {
|
||||||
$colored_age = "<span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span>";
|
$colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
|
||||||
} elsif ($co{'age'} < 60*60*24*2) {
|
} elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
|
||||||
$colored_age = "<span style =\"color: #009900;\"><i>$co{'age_string'}</i></span>";
|
$colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
|
||||||
} else {
|
} else {
|
||||||
$colored_age = "<i>$co{'age_string'}</i>";
|
$colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
|
||||||
}
|
}
|
||||||
print "<td>$colored_age</td>\n" .
|
print "<td>$colored_age</td>\n" .
|
||||||
"<td class=\"link\">" .
|
"<td class=\"link\">" .
|
||||||
$cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, "summary") .
|
$cgi->a({-href => "$my_uri?p=$pr->{'path'};a=summary"}, "summary") .
|
||||||
" | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=shortlog"}, "shortlog") .
|
" | " . $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=shortlog"}, "shortlog") .
|
||||||
" | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=log"}, "log") .
|
" | " . $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=log"}, "log") .
|
||||||
"</td>\n" .
|
"</td>\n" .
|
||||||
"</tr>\n";
|
"</tr>\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue