From: Kay Sievers Date: Wed, 10 Aug 2005 01:53:09 +0000 (+0200) Subject: allow sorting of index page by project path, owner and age X-Git-Tag: v1.4.0~1^2~67 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f7ab660c15b5e3cb7fee035191e0cd5160bf8299;p=git.git allow sorting of index page by project path, owner and age --- diff --git a/gitweb.cgi b/gitweb.cgi index 973702f09..b0b515efb 100755 --- a/gitweb.cgi +++ b/gitweb.cgi @@ -15,7 +15,7 @@ use CGI::Carp qw(fatalsToBrowser); use Fcntl ':mode'; my $cgi = new CGI; -my $version = "237"; +my $version = "238"; my $my_url = $cgi->url(); my $my_uri = $cgi->url(-absolute => 1); 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'); if (defined $project) { 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"; } 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 "\n" . "\n" . @@ -753,9 +761,30 @@ sub git_read_projects { sub git_project_list { my @list = git_read_projects(); + my @projects; if (!@list) { 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(); if (-f $home_text) { print "
\n"; @@ -765,53 +794,52 @@ sub git_project_list { print "
\n"; } print "\n" . - "\n" . - "\n" . - "\n" . - "\n" . - "\n" . - "\n" . + "\n"; + if (defined($order) && ($order eq "project")) { + @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects; + print "\n"; + } else { + print "\n"; + } + print "\n"; + if (defined($order) && ($order eq "owner")) { + @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects; + print "\n"; + } else { + print "\n"; + } + if (defined($order) && ($order eq "age")) { + @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects; + print "\n"; + } else { + print "\n"; + } + print "\n" . "\n"; my $alternate = 0; - foreach my $pr (@list) { - 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'}") || ""; - } + foreach my $pr (@projects) { if ($alternate) { print "\n"; } else { print "\n"; } $alternate ^= 1; - print "\n" . - "\n" . - "\n"; + print "\n" . + "\n" . + "\n"; my $colored_age; - if ($co{'age'} < 60*60*2) { - $colored_age = "$co{'age_string'}"; - } elsif ($co{'age'} < 60*60*24*2) { - $colored_age = "$co{'age_string'}"; + if ($pr->{'commit'}{'age'} < 60*60*2) { + $colored_age = "$pr->{'commit'}{'age_string'}"; + } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) { + $colored_age = "$pr->{'commit'}{'age_string'}"; } else { - $colored_age = "$co{'age_string'}"; + $colored_age = "$pr->{'commit'}{'age_string'}"; } print "\n" . "\n" . "\n"; }
ProjectDescriptionOwnerlast change
Project" . $cgi->a({-class => "list", -href => "$my_uri?o=project"}, "Project") . "DescriptionOwner" . $cgi->a({-class => "list", -href => "$my_uri?o=owner"}, "Owner") . "last change" . $cgi->a({-class => "list", -href => "$my_uri?o=age"}, "last change") . "
" . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary", -class => "list"}, escapeHTML($proj{'path'})) . "$descr" . chop_str($proj{'owner'}, 15) . "" . $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=summary", -class => "list"}, escapeHTML($pr->{'path'})) . "$pr->{'descr'}" . chop_str($pr->{'owner'}, 15) . "$colored_age" . - $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, "summary") . - " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=shortlog"}, "shortlog") . - " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=log"}, "log") . + $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=summary"}, "summary") . + " | " . $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=shortlog"}, "shortlog") . + " | " . $cgi->a({-href => "$my_uri?p=$pr->{'path'};a=log"}, "log") . "