Gitweb; ordering of fork list on summary page (was Vanilla gitweb vs repo.or.cz)

3 messages, 2 authors, 2016-08-13 · open the first message on its own page

Gitweb; ordering of fork list on summary page (was Vanilla gitweb vs repo.or.cz)

From: Mike Ralphson <hidden>
Date: 2016-06-15 22:45:00

2008/7/13 Petr Baudis [off-list ref]:
 Then, there is the http://repo.or.cz/w/git/gitweb.git repository,
which was my old attempt at maintaining gitweb actively. Unfortunately,
this didn't quite work out because of my general lack of time and
dedication.
Notwithstanding the above, I've pushed a little 'fix' to the mob branch:

http://repo.or.cz/w/git/gitweb.git?a=commitdiff;h=3e8f6e9125071a7e17c88efb69c1780d775025bc

The list of forks on the summary page was unsorted, this just makes
them sorted by age, which seems a fair way to decide which forks are
shown before the list size cut-off (15) kicks in.

s/noheader/no_header was just to make it obvious what the parameter
affects, so all the code can be found with one grep, and s/undef/'age'
just shows the intent, although that parameter isn't what actually
controls the sort order. Or, I guess, the sorting could be refactored
out of the header generation code.

Mike

[PATCH] gitweb: Clean-up sorting of project list

From: Petr Baudis <hidden>
Date: 2016-08-13 23:16:07

This decouples the sorting of project list and printing the column
headers, so that the project list can be easily sorted even when
the headers are not shown.

Signed-off-by: Petr Baudis <redacted>

---
 gitweb/gitweb.perl |   45 ++++++++++++++++++++-------------------------
 1 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index da474d0..bd81e14 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3605,19 +3605,13 @@ sub fill_project_list_info {
 	return @projects;
 }
 
-# print 'sort by' <th> element, either sorting by $key if $name eq $order
-# (changing $list), or generating 'sort by $name' replay link otherwise
+# print 'sort by' <th> element, generating 'sort by $name' replay link
+# if that order is not selected
 sub print_sort_th {
-	my ($str_sort, $name, $order, $key, $header, $list) = @_;
-	$key    ||= $name;
+	my ($name, $order, $header) = @_;
 	$header ||= ucfirst($name);
 
 	if ($order eq $name) {
-		if ($str_sort) {
-			@$list = sort {$a->{$key} cmp $b->{$key}} @$list;
-		} else {
-			@$list = sort {$a->{$key} <=> $b->{$key}} @$list;
-		}
 		print "<th>$header</th>\n";
 	} else {
 		print "<th>" .
@@ -3627,14 +3621,6 @@ sub print_sort_th {
 	}
 }
 
-sub print_sort_th_str {
-	print_sort_th(1, @_);
-}
-
-sub print_sort_th_num {
-	print_sort_th(0, @_);
-}
-
 sub git_project_list_body {
 	my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
 
@@ -3645,20 +3631,29 @@ sub git_project_list_body {
 	$from = 0 unless defined $from;
 	$to = $#projects if (!defined $to || $#projects < $to);
 
+	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};
+	if ($oi->{'type'} eq 'str') {
+		@projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
+	} else {
+		@projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
+	}
+
 	print "<table class=\"project_list\">\n";
 	unless ($no_header) {
 		print "<tr>\n";
 		if ($check_forks) {
 			print "<th></th>\n";
 		}
-		print_sort_th_str('project', $order, 'path',
-		                  'Project', \@projects);
-		print_sort_th_str('descr', $order, 'descr_long',
-		                  'Description', \@projects);
-		print_sort_th_str('owner', $order, 'owner',
-		                  'Owner', \@projects);
-		print_sort_th_num('age', $order, 'age',
-		                  'Last Change', \@projects);
+		print_sort_th('project', $order, 'Project');
+		print_sort_th('descr', $order, 'Description');
+		print_sort_th('owner', $order, 'Owner');
+		print_sort_th('age', $order, 'Last Change');
 		print "<th></th>\n" . # for links
 		      "</tr>\n";
 	}
-- 
tg: (c427559..) t/forks/sort-refactor (depends on: vanilla/master)

[PATCH] gitweb: Sort the list of forks on the summary page by age

From: Petr Baudis <hidden>
Date: 2016-08-13 23:16:08

From: Petr Baudis <redacted>

From: Mike Ralphson <redacted>

The list of forks on the summary page was unsorted, this just makes
them sorted by age, which seems a fair way to decide which forks are
shown before the list size cut-off (15) kicks in.

s/noheader/no_header was just to make it obvious what the parameter
affects, so all the code can be found with one grep.

pb: As suggested by Mike, I have augmented this by an additional patch
that refactors the sorting logic so that it is not tied to printing
the headers.

Signed-off-by: Mike Ralphson <redacted>
Signed-off-by: Petr Baudis <redacted>

---
 gitweb/gitweb.perl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index bd81e14..0f8a564 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4119,10 +4119,10 @@ sub git_summary {
 
 	if (@forklist) {
 		git_print_header_div('forks');
-		git_project_list_body(\@forklist, undef, 0, 15,
+		git_project_list_body(\@forklist, 'age', 0, 15,
 		                      $#forklist <= 15 ? undef :
 		                      $cgi->a({-href => href(action=>"forks")}, "..."),
-		                      'noheader');
+		                      'no_header');
 	}
 
 	git_footer_html();
-- 
tg: (513dad1..) t/forks/sort-by-age (depends on: t/forks/sort-refactor)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help