aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-01-02 10:40:03 -0800
committerJunio C Hamano <gitster@pobox.com>2013-01-02 10:40:03 -0800
commitb05d8c62d306071729eb3d905042385bb93b9fcd (patch)
tree52b478457909765147d55fa883a8f93bf672c358
parentf97335b132c80a2282d7648885a4686b85595088 (diff)
parent28dae1812bc70f06079cb7d3fd4cdbfa9e59cbeb (diff)
downloadgit-b05d8c62d306071729eb3d905042385bb93b9fcd.tar.gz
git-b05d8c62d306071729eb3d905042385bb93b9fcd.tar.xz
Merge branch 'md/gitweb-sort-by-age'
"gitweb", when sorting by age to show repositories with new activities first, used to sort repositories with absolutely nothing in it early, which was not very useful. * md/gitweb-sort-by-age: gitweb: Sort projects with undefined ages last
-rwxr-xr-xgitweb/gitweb.perl35
1 files changed, 21 insertions, 14 deletions
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 0f207f2e2..656b324fb 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5528,23 +5528,30 @@ sub fill_project_list_info {
sub sort_projects_list {
my ($projlist, $order) = @_;
- my @projects;
- my %order_info = (
- project => { key => 'path', type => 'str' },
- descr => { key => 'descr_long', type => 'str' },
- owner => { key => 'owner', type => 'str' },
- age => { key => 'age', type => 'num' }
- );
- my $oi = $order_info{$order};
- return @$projlist unless defined $oi;
- if ($oi->{'type'} eq 'str') {
- @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @$projlist;
- } else {
- @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @$projlist;
+ sub order_str {
+ my $key = shift;
+ return sub { $a->{$key} cmp $b->{$key} };
}
- return @projects;
+ sub order_num_then_undef {
+ my $key = shift;
+ return sub {
+ defined $a->{$key} ?
+ (defined $b->{$key} ? $a->{$key} <=> $b->{$key} : -1) :
+ (defined $b->{$key} ? 1 : 0)
+ };
+ }
+
+ my %orderings = (
+ project => order_str('path'),
+ descr => order_str('descr_long'),
+ owner => order_str('owner'),
+ age => order_num_then_undef('age'),
+ );
+
+ my $ordering = $orderings{$order};
+ return defined $ordering ? sort $ordering @$projlist : @$projlist;
}
# returns a hash of categories, containing the list of project