aboutsummaryrefslogtreecommitdiff
path: root/gitweb
diff options
context:
space:
mode:
authorMatthew Daley <mattjd@gmail.com>2012-12-11 23:56:07 +1300
committerJunio C Hamano <gitster@pobox.com>2012-12-11 10:08:00 -0800
commit28dae1812bc70f06079cb7d3fd4cdbfa9e59cbeb (patch)
tree081b890e1e8dbf4f4d58daa5d9f805777bb1e328 /gitweb
parent3e53891f85c58b4adb016a429a1f3b7fae78ca03 (diff)
downloadgit-28dae1812bc70f06079cb7d3fd4cdbfa9e59cbeb.tar.gz
git-28dae1812bc70f06079cb7d3fd4cdbfa9e59cbeb.tar.xz
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>
Diffstat (limited to 'gitweb')
-rwxr-xr-xgitweb/gitweb.perl35
1 files changed, 21 insertions, 14 deletions
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index e8812fa2b..be4b3772c 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5525,23 +5525,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