From: Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
Subject: [PATCH 1/2 v2] gitweb: sort projects by path.
Date: Tue, 29 Jul 2008 00:59:02 -0300 [thread overview]
Message-ID: <1217303942-18526-1-git-send-email-barbieri@profusion.mobi> (raw)
In-Reply-To: <1217298868-16513-2-git-send-email-barbieri@profusion.mobi>
Projects are paths, so they should be sorted in pieces, not as a
whole, so a/x will be come before a-b/x.
Signed-off-by: Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
---
New version that fix cmp_paths. Unlike I though initially, $#list
reports the last element index, not the list length. Nonetheless the
last component must be compared only if the list lengths are the same,
otherwise we'll get $root/a/a.git before $root/b.git and sections will
look ugly (group elements of the same level together).
gitweb/gitweb.perl | 42 +++++++++++++++++++++++++++++++++++++-----
1 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 90cd99b..06c9901 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3574,17 +3574,45 @@ sub fill_project_list_info {
return @projects;
}
+sub cmp_paths {
+ my ($a, $b) = @_;
+ my @la = split('/', $a);
+ my @lb = split('/', $b);
+ my $last;
+
+ if ($#la < $#lb) {
+ $last = $#la;
+ } else {
+ $last = $#lb;
+ }
+
+ for (my $i = 0; $i < $last; $i++) {
+ my $r = $la[$i] cmp $lb[$i];
+ if ($r != 0) {
+ return $r;
+ }
+ }
+
+ if ($#la == $#lb) {
+ return $la[$last] cmp $lb[$last];
+ } else {
+ return $#la <=> $#lb;
+ }
+}
+
# print 'sort by' <th> element, either sorting by $key if $name eq $order
# (changing $list), or generating 'sort by $name' replay link otherwise
sub print_sort_th {
- my ($str_sort, $name, $order, $key, $header, $list) = @_;
+ my ($sort_mode, $name, $order, $key, $header, $list) = @_;
$key ||= $name;
$header ||= ucfirst($name);
if ($order eq $name) {
- if ($str_sort) {
+ if ($sort_mode == 2) {
+ @$list = sort {cmp_paths($a->{$key}, $b->{$key})} @$list;
+ } elsif ($sort_mode == 1) {
@$list = sort {$a->{$key} cmp $b->{$key}} @$list;
- } else {
+ } elsif ($sort_mode == 0) {
@$list = sort {$a->{$key} <=> $b->{$key}} @$list;
}
print "<th>$header</th>\n";
@@ -3596,6 +3624,10 @@ sub print_sort_th {
}
}
+sub print_sort_th_path {
+ print_sort_th(2, @_);
+}
+
sub print_sort_th_str {
print_sort_th(1, @_);
}
@@ -3620,8 +3652,8 @@ sub git_project_list_body {
if ($check_forks) {
print "<th></th>\n";
}
- print_sort_th_str('project', $order, 'path',
- 'Project', \@projects);
+ print_sort_th_path('project', $order, 'path',
+ 'Project', \@projects);
print_sort_th_str('descr', $order, 'descr_long',
'Description', \@projects);
print_sort_th_str('owner', $order, 'owner',
--
1.5.5.2
next prev parent reply other threads:[~2008-07-29 4:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-29 2:34 [PATCH 0/2] gitweb use sections Gustavo Sverzut Barbieri
2008-07-29 2:34 ` [PATCH 1/2] gitweb: sort projects by path Gustavo Sverzut Barbieri
2008-07-29 2:34 ` [PATCH 2/2] gitweb: add section support to gitweb project listing Gustavo Sverzut Barbieri
2008-07-29 3:59 ` Gustavo Sverzut Barbieri [this message]
2008-07-31 19:43 ` [PATCH 0/2] gitweb use sections Gustavo Sverzut Barbieri
2008-07-31 20:32 ` Petr Baudis
2008-07-31 20:58 ` Gustavo Sverzut Barbieri
2008-08-10 19:45 ` Gustavo Sverzut Barbieri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1217303942-18526-1-git-send-email-barbieri@profusion.mobi \
--to=barbieri@profusion.mobi \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).