Skip to content

Commit 28dae18

Browse files
Matthew Daleygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3e53891 commit 28dae18

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

gitweb/gitweb.perl

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5525,23 +5525,30 @@ sub fill_project_list_info {
55255525

55265526
sub sort_projects_list {
55275527
my ($projlist, $order) = @_;
5528-
my @projects;
55295528

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} };
55425532
}
55435533

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;
55455552
}
55465553

55475554
# returns a hash of categories, containing the list of project

0 commit comments

Comments
 (0)