Merge branch 'md/gitweb-sort-by-age'
authorJunio C Hamano <gitster@pobox.com>
Wed, 2 Jan 2013 18:40:03 +0000 (10:40 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 Jan 2013 18:40:03 +0000 (10:40 -0800)
"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

1  2 
gitweb/gitweb.perl
diff --combined gitweb/gitweb.perl
index 0f207f2e20b0c3c30e62c1fd6f0526d38868776f,be4b3772ccf9ce71f21dbbed1e126b1f8625b6c6..656b324fb7f82c7f65c71075f57e909843c50cce
@@@ -540,7 -540,7 +540,7 @@@ our %feature = 
        # $feature{'remote_heads'}{'default'} = [1];
        # To have project specific config enable override in $GITWEB_CONFIG
        # $feature{'remote_heads'}{'override'} = 1;
 -      # and in project config gitweb.remote_heads = 0|1;
 +      # and in project config gitweb.remoteheads = 0|1;
        'remote_heads' => {
                'sub' => sub { feature_bool('remote_heads', @_) },
                'override' => 0,
@@@ -2696,15 -2696,12 +2696,15 @@@ sub git_get_project_config 
        # only subsection, if exists, is case sensitive,
        # and not lowercased by 'git config -z -l'
        if (my ($hi, $mi, $lo) = ($key =~ /^([^.]*)\.(.*)\.([^.]*)$/)) {
 +              $lo =~ s/_//g;
                $key = join(".", lc($hi), $mi, lc($lo));
 +              return if ($lo =~ /\W/ || $hi =~ /\W/);
        } else {
                $key = lc($key);
 +              $key =~ s/_//g;
 +              return if ($key =~ /\W/);
        }
        $key =~ s/^gitweb\.//;
 -      return if ($key =~ m/\W/);
  
        # type sanity check
        if (defined $type) {
@@@ -5528,23 -5525,30 +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