gitweb: Sort projects with undefined ages last
Sorting gitweb's project list by age ('Last Change') currently shows projects with undefined ages at the head of the list. This gives a less useful result when there are a number of projects that are missing or otherwise faulty and one is trying to see what projects have been updated recently. Fix by sorting these projects with undefined ages at the bottom of the list when sorting by age. Signed-off-by: Matthew Daley <mattjd@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthew Daley committed
Dec 11, 2012 at 23:56 UTC
28dae1812bc70f06079cb7d3fd4cdbfa9e59cbeb
1 file changed
+21
-14
gitweb/gitweb.perl
+21
-14
@@ -5525,23 +5525,30 @@ sub fill_project_list_info {
5525
5526
sub sort_projects_list {
5527
my ($projlist, $order) = @_;
5528
- my @projects;
5528
5530
- my %order_info = (
5531
- project => { key => 'path', type => 'str' },
5532
- descr => { key => 'descr_long', type => 'str' },
5533
- owner => { key => 'owner', type => 'str' },
5534
- age => { key => 'age', type => 'num' }
5535
- );
5536
- my $oi = $order_info{$order};
5537
- return @$projlist unless defined $oi;
5538
- if ($oi->{'type'} eq 'str') {
5539
- @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @$projlist;
5540
- } else {
5541
- @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @$projlist;
5529
+ sub order_str {
5530
+ my $key = shift;
5531
+ return sub { $a->{$key} cmp $b->{$key} };
5532
}
5533
5544
- return @projects;
5534
+ sub order_num_then_undef {
5535
+ my $key = shift;
5536
+ return sub {
5537
+ defined $a->{$key} ?
5538
+ (defined $b->{$key} ? $a->{$key} <=> $b->{$key} : -1) :
5539
+ (defined $b->{$key} ? 1 : 0)
5540
+ };
5541
+ }
5542
+
5543
+ my %orderings = (
5544
+ project => order_str('path'),
5545
+ descr => order_str('descr_long'),
5546
+ owner => order_str('owner'),
5547
+ age => order_num_then_undef('age'),
5548
+ );
5549
+
5550
+ my $ordering = $orderings{$order};
5551
+ return defined $ordering ? sort $ordering @$projlist : @$projlist;
5552
}
5553
5554
# returns a hash of categories, containing the list of project