git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gitweb: Sort projects with undefined ages last

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 11, 2012, 18:08 UTC
Message-ID
<7vhans8ns2.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1355223367-5894-1-git-send-email-mattjd@gmail.com>
Matthew Daley <mattjd@gmail.com> writes:
Show 16 quoted lines
> I thought about both of those variants as well. What about this:
>
> -- >8 --
> Subject: [PATCH] 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>
> ---
Looks sensible to me.  Thanks; will queue.
Show 52 quoted lines
>  gitweb/gitweb.perl |   35 +++++++++++++++++++++--------------
>  1 file changed, 21 insertions(+), 14 deletions(-)
>
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 0f207f2..656b324 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
Previous: Matthew Daley
Message 4 of 4 in “gitweb: Sort projects with undefined ages last”
  1. gitweb: Sort projects with undefined ages lastMatthew Daley, Dec 10, 2012
  2. Junio C HamanoDec 10, 2012
  3. Matthew DaleyDec 11, 2012
  4. Junio C HamanoDec 11, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.