[PATCH 0/2] gitweb use sections

STALE3707d

8 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH 0/2] gitweb use sections

From: Gustavo Sverzut Barbieri <hidden>
Date: 2016-06-15 22:45:04

The following two patches will add sections to gitweb so usability is
improved for large project listing. It looks like:

    http://staff.get-e.org/

but it's a new code that also supports owner sort.

Patches orverview:

 * [PATCH 1/2] gitweb: sort projects by path.
   This one is required to fix project sort. Since we use paths, we
   should compare individual components to make it look like a
   tree. Since we now can enable sections this error will be more
   evident, so there is the fix.

 * [PATCH 2/2] gitweb: add section support to gitweb project listing.
   The real section work. This will add use_sections variable and if
   it evaluates to true sections will be enabled. Just project and
   owner sections are implemented.

I hope it looks good for inclusion. Last time I did perl was about 8
years ago, please point any problems and I'll fix them.


--
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbieri@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202

[PATCH 1/2] gitweb: sort projects by path.

From: Gustavo Sverzut Barbieri <hidden>
Date: 2016-06-15 22:45:04

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 <redacted>
---
 gitweb/gitweb.perl |   37 ++++++++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 90cd99b..c5675cf 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3574,17 +3574,40 @@ 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++) {
+		if ($la[$i] gt $lb[$i]) {
+			return 1;
+		}
+	}
+
+	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 +3619,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 +3647,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

[PATCH 2/2] gitweb: add section support to gitweb project listing.

From: Gustavo Sverzut Barbieri <hidden>
Date: 2016-06-15 22:45:04

Section headers will be optionally displayed when projects dirnames or
owner names changes (depending on sort order), making it easier to
find projects in large setups.

Signed-off-by: Gustavo Sverzut Barbieri <redacted>
---
 gitweb/gitweb.css  |    7 +++++
 gitweb/gitweb.perl |   73 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 79 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css
index aa0eeca..44abc4c 100644
--- a/gitweb/gitweb.css
+++ b/gitweb/gitweb.css
@@ -235,6 +235,13 @@ tr.dark:hover {
 	background-color: #edece6;
 }
 
+tr.section td {
+	background-color: #d9d8d1;
+	border-top: 1px solid #000000;
+	border-left: 1px solid #000000;
+	font-weight: bold;
+}
+
 td {
 	padding: 2px 5px;
 	font-size: 100%;
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index c5675cf..c99cea3 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -15,7 +15,7 @@ use CGI::Carp qw(fatalsToBrowser);
 use Encode;
 use Fcntl ':mode';
 use File::Find qw();
-use File::Basename qw(basename);
+use File::Basename qw(basename dirname);
 binmode STDOUT, ':utf8';
 
 BEGIN {
@@ -82,6 +82,9 @@ our $projects_list_description_width = 25;
 # valid values are none, project, descr, owner, and age
 our $default_projects_order = "project";
 
+# use sections to separate projects by dirname, helps usability
+our $use_sections = 1;
+
 # show repository only if this file exists
 # (only effective if this variable evaluates to true)
 our $export_ok = "++GITWEB_EXPORT_OK++";
@@ -3631,6 +3634,66 @@ sub print_sort_th_num {
 	print_sort_th(0, @_);
 }
 
+sub print_section_tr {
+	my ($n_cols, $section) = @_;
+	print "<tr class=\"section\"><td colspan=\"$n_cols\">$section</td></tr>\n";
+}
+
+sub print_section_internal {
+	my ($order, $n_cols, $current, $getter) = @_;
+	my $current_value = $getter->($current);
+
+	if (!$current_value) {
+		return 0;
+	}
+
+	my $last_value = '';
+	if ($current > 0) {
+		$last_value = $getter->($current - 1);
+	}
+
+	if ($current_value ne $last_value) {
+		print_section_tr($n_cols, $current_value);
+		return 1;
+	}
+
+	return 0;
+}
+
+sub print_section_project {
+	my ($order, $n_cols, $current, $projects) = @_;
+
+	sub get_section_project {
+		my ($index) = @_;
+		return dirname(@$projects[$index]->{'path'});
+	}
+
+	return print_section_internal($order, $n_cols, $current, \&get_section_project);
+}
+
+sub print_section_owner {
+	my ($order, $n_cols, $current, $projects) = @_;
+
+	sub get_section_owner {
+		my ($index) = @_;
+		return @$projects[$index]->{'owner'};
+	}
+
+	return print_section_internal($order, $n_cols, $current, \&get_section_owner);
+}
+
+sub print_section {
+	my ($order, $n_cols, $current, $projects) = @_;
+
+	if ($order eq 'project') {
+		return print_section_project($order, $n_cols, $current, $projects);
+	} elsif ($order eq 'owner') {
+		return print_section_owner($order, $n_cols, $current, $projects);
+	}
+
+	return 0;
+}
+
 sub git_project_list_body {
 	my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
 
@@ -3658,9 +3721,17 @@ sub git_project_list_body {
 		print "<th></th>\n" . # for links
 		      "</tr>\n";
 	}
+	my $n_cols = $check_forks ? 6 : 5;
 	my $alternate = 1;
 	for (my $i = $from; $i <= $to; $i++) {
 		my $pr = $projects[$i];
+
+                if ($use_sections) {
+			if (print_section($order, $n_cols, $i, \@projects)) {
+				$alternate = 1;
+			}
+                }
+
 		if ($alternate) {
 			print "<tr class=\"dark\">\n";
 		} else {
-- 
1.5.5.2

[PATCH 1/2 v2] gitweb: sort projects by path.

From: Gustavo Sverzut Barbieri <hidden>
Date: 2016-06-15 22:45:04

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 <redacted>
---

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

Re: [PATCH 0/2] gitweb use sections

From: Gustavo Sverzut Barbieri <hidden>
Date: 2016-06-15 22:45:05

Since nobody replied and I missed some gitweb guys in CC, I'm adding
Petr and Jakub, as some guys said on IRC.

Have anyone tried this patch, any problems?


On Mon, Jul 28, 2008 at 11:34 PM, Gustavo Sverzut Barbieri
[off-list ref] wrote:
The following two patches will add sections to gitweb so usability is
improved for large project listing. It looks like:

   http://staff.get-e.org/

but it's a new code that also supports owner sort.

Patches orverview:

 * [PATCH 1/2] gitweb: sort projects by path.
  This one is required to fix project sort. Since we use paths, we
  should compare individual components to make it look like a
  tree. Since we now can enable sections this error will be more
  evident, so there is the fix.

 * [PATCH 2/2] gitweb: add section support to gitweb project listing.
  The real section work. This will add use_sections variable and if
  it evaluates to true sections will be enabled. Just project and
  owner sections are implemented.

I hope it looks good for inclusion. Last time I did perl was about 8
years ago, please point any problems and I'll fix them.


--
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbieri@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202


-- 
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbieri@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202

Re: [PATCH 0/2] gitweb use sections

From: Petr Baudis <hidden>
Date: 2016-06-15 22:45:05

  Hi,

On Thu, Jul 31, 2008 at 04:43:35PM -0300, Gustavo Sverzut Barbieri wrote:
Since nobody replied and I missed some gitweb guys in CC, I'm adding
Petr and Jakub, as some guys said on IRC.

Have anyone tried this patch, any problems?
  sorry, I have it in my review queue. At first pass it was looking
good, but I wanted to look at it better before commenting.

  One thing I'm wondering about is how to make this stuff configurable,
since I'm not very comfortable with adding more "unbound" configuration
variables and would rather prefer stuff to be added to the $features
array... I'm not at all sure about my own sentiment here, however.

-- 
				Petr "Pasky" Baudis
As in certain cults it is possible to kill a process if you know
its true name.  -- Ken Thompson and Dennis M. Ritchie

Re: [PATCH 0/2] gitweb use sections

From: Gustavo Sverzut Barbieri <hidden>
Date: 2016-06-15 22:45:05

On Thu, Jul 31, 2008 at 5:32 PM, Petr Baudis [off-list ref] wrote:
 Hi,

On Thu, Jul 31, 2008 at 04:43:35PM -0300, Gustavo Sverzut Barbieri wrote:
quoted
Since nobody replied and I missed some gitweb guys in CC, I'm adding
Petr and Jakub, as some guys said on IRC.

Have anyone tried this patch, any problems?
 sorry, I have it in my review queue. At first pass it was looking
good, but I wanted to look at it better before commenting.
no problem, just to see it was noticed or not :-)

 One thing I'm wondering about is how to make this stuff configurable,
since I'm not very comfortable with adding more "unbound" configuration
variables and would rather prefer stuff to be added to the $features
array... I'm not at all sure about my own sentiment here, however.
Path comparison (first patch), Sections (second), both?

I know path comparison can be a performance hit on large listings on
sites with heavy traffic. However, I don't see many people accessing
the projects page at the same time for long periods, it's not like
slashdot... people mostly use it to know about repositories and then
use git to track it.
    The slowness is due O(n^2) worst case of sort and each step is not
a bit heavier since it need to split path into components and walk
these. Maybe cache the split?

-- 
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbieri@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202

Re: [PATCH 0/2] gitweb use sections

From: Gustavo Sverzut Barbieri <hidden>
Date: 2016-06-15 22:45:08

Yet another "ping" on this topic, news?

On Thu, Jul 31, 2008 at 5:58 PM, Gustavo Sverzut Barbieri
[off-list ref] wrote:
On Thu, Jul 31, 2008 at 5:32 PM, Petr Baudis [off-list ref] wrote:
quoted
 Hi,

On Thu, Jul 31, 2008 at 04:43:35PM -0300, Gustavo Sverzut Barbieri wrote:
quoted
Since nobody replied and I missed some gitweb guys in CC, I'm adding
Petr and Jakub, as some guys said on IRC.

Have anyone tried this patch, any problems?
 sorry, I have it in my review queue. At first pass it was looking
good, but I wanted to look at it better before commenting.
no problem, just to see it was noticed or not :-)

quoted
 One thing I'm wondering about is how to make this stuff configurable,
since I'm not very comfortable with adding more "unbound" configuration
variables and would rather prefer stuff to be added to the $features
array... I'm not at all sure about my own sentiment here, however.
Path comparison (first patch), Sections (second), both?

I know path comparison can be a performance hit on large listings on
sites with heavy traffic. However, I don't see many people accessing
the projects page at the same time for long periods, it's not like
slashdot... people mostly use it to know about repositories and then
use git to track it.
   The slowness is due O(n^2) worst case of sort and each step is not
a bit heavier since it need to split path into components and walk
these. Maybe cache the split?

--
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbieri@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202


-- 
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbieri@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help