{"thread":{"id":"14730","subject":"[PATCH 1/2] gitweb: sort projects by path.","startedAt":"2008-07-29T02:34:26Z","lastAt":"2008-08-10T19:45:14Z","messageCount":8,"participants":["Gustavo Sverzut Barbieri","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"85386","messageId":"1217298868-16513-1-git-send-email-barbieri@profusion.mobi","threadId":"14730","inReplyTo":null,"subject":"[PATCH 0/2] gitweb use sections","fromName":"Gustavo Sverzut Barbieri","fromEmail":"barbieri@profusion.mobi","sentAt":"2008-07-29T02:34:26Z","receivedAt":"2008-07-29T02:34:26Z","isPatch":true,"sender":{"key":"barbieri@profusion.mobi","avatar":null},"body":"The following two patches will add sections to gitweb so usability is\nimproved for large project listing. It looks like:\n\n    http://staff.get-e.org/\n\nbut it's a new code that also supports owner sort.\n\nPatches orverview:\n\n * [PATCH 1/2] gitweb: sort projects by path.\n   This one is required to fix project sort. Since we use paths, we\n   should compare individual components to make it look like a\n   tree. Since we now can enable sections this error will be more\n   evident, so there is the fix.\n\n * [PATCH 2/2] gitweb: add section support to gitweb project listing.\n   The real section work. This will add use_sections variable and if\n   it evaluates to true sections will be enabled. Just project and\n   owner sections are implemented.\n\nI hope it looks good for inclusion. Last time I did perl was about 8\nyears ago, please point any problems and I'll fix them.\n\n\n--\nGustavo Sverzut Barbieri\nhttp://profusion.mobi embedded systems\n--------------------------------------\nMSN: barbieri@gmail.com\nSkype: gsbarbieri\nMobile: +55 (19) 9225-2202\n"},{"id":"85385","messageId":"1217298868-16513-2-git-send-email-barbieri@profusion.mobi","threadId":"14730","inReplyTo":"1217298868-16513-1-git-send-email-barbieri@profusion.mobi","subject":"[PATCH 1/2] gitweb: sort projects by path.","fromName":"Gustavo Sverzut Barbieri","fromEmail":"barbieri@profusion.mobi","sentAt":"2008-07-29T02:34:27Z","receivedAt":"2008-07-29T02:34:27Z","isPatch":true,"sender":{"key":"barbieri@profusion.mobi","avatar":null},"body":"Projects are paths, so they should be sorted in pieces, not as a\nwhole, so a/x will be come before a-b/x.\n\nSigned-off-by: Gustavo Sverzut Barbieri <barbieri@profusion.mobi>\n---\n gitweb/gitweb.perl |   37 ++++++++++++++++++++++++++++++++-----\n 1 files changed, 32 insertions(+), 5 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 90cd99b..c5675cf 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3574,17 +3574,40 @@ sub fill_project_list_info {\n \treturn @projects;\n }\n \n+sub cmp_paths {\n+\tmy ($a, $b) = @_;\n+\tmy @la = split('/', $a);\n+\tmy @lb = split('/', $b);\n+\tmy $last;\n+\n+\tif ($#la < $#lb) {\n+\t\t$last = $#la;\n+\t} else {\n+\t\t$last = $#lb;\n+\t}\n+\n+\tfor (my $i = 0; $i < $last; $i++) {\n+\t\tif ($la[$i] gt $lb[$i]) {\n+\t\t\treturn 1;\n+\t\t}\n+\t}\n+\n+\treturn $#la <=> $#lb;\n+}\n+\n # print 'sort by' <th> element, either sorting by $key if $name eq $order\n # (changing $list), or generating 'sort by $name' replay link otherwise\n sub print_sort_th {\n-\tmy ($str_sort, $name, $order, $key, $header, $list) = @_;\n+\tmy ($sort_mode, $name, $order, $key, $header, $list) = @_;\n \t$key    ||= $name;\n \t$header ||= ucfirst($name);\n \n \tif ($order eq $name) {\n-\t\tif ($str_sort) {\n+\t\tif ($sort_mode == 2) {\n+\t\t\t@$list = sort {cmp_paths($a->{$key}, $b->{$key})} @$list;\n+\t\t} elsif ($sort_mode == 1) {\n \t\t\t@$list = sort {$a->{$key} cmp $b->{$key}} @$list;\n-\t\t} else {\n+\t\t} elsif ($sort_mode == 0) {\n \t\t\t@$list = sort {$a->{$key} <=> $b->{$key}} @$list;\n \t\t}\n \t\tprint \"<th>$header</th>\\n\";\n@@ -3596,6 +3619,10 @@ sub print_sort_th {\n \t}\n }\n \n+sub print_sort_th_path {\n+\tprint_sort_th(2, @_);\n+}\n+\n sub print_sort_th_str {\n \tprint_sort_th(1, @_);\n }\n@@ -3620,8 +3647,8 @@ sub git_project_list_body {\n \t\tif ($check_forks) {\n \t\t\tprint \"<th></th>\\n\";\n \t\t}\n-\t\tprint_sort_th_str('project', $order, 'path',\n-\t\t                  'Project', \\@projects);\n+\t\tprint_sort_th_path('project', $order, 'path',\n+\t\t                   'Project', \\@projects);\n \t\tprint_sort_th_str('descr', $order, 'descr_long',\n \t\t                  'Description', \\@projects);\n \t\tprint_sort_th_str('owner', $order, 'owner',\n-- \n1.5.5.2\n"},{"id":"85387","messageId":"1217298868-16513-3-git-send-email-barbieri@profusion.mobi","threadId":"14730","inReplyTo":"1217298868-16513-2-git-send-email-barbieri@profusion.mobi","subject":"[PATCH 2/2] gitweb: add section support to gitweb project listing.","fromName":"Gustavo Sverzut Barbieri","fromEmail":"barbieri@profusion.mobi","sentAt":"2008-07-29T02:34:28Z","receivedAt":"2008-07-29T02:34:28Z","isPatch":true,"sender":{"key":"barbieri@profusion.mobi","avatar":null},"body":"Section headers will be optionally displayed when projects dirnames or\nowner names changes (depending on sort order), making it easier to\nfind projects in large setups.\n\nSigned-off-by: Gustavo Sverzut Barbieri <barbieri@profusion.mobi>\n---\n gitweb/gitweb.css  |    7 +++++\n gitweb/gitweb.perl |   73 +++++++++++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 79 insertions(+), 1 deletions(-)\n\ndiff --git a/gitweb/gitweb.css b/gitweb/gitweb.css\nindex aa0eeca..44abc4c 100644\n--- a/gitweb/gitweb.css\n+++ b/gitweb/gitweb.css\n@@ -235,6 +235,13 @@ tr.dark:hover {\n \tbackground-color: #edece6;\n }\n \n+tr.section td {\n+\tbackground-color: #d9d8d1;\n+\tborder-top: 1px solid #000000;\n+\tborder-left: 1px solid #000000;\n+\tfont-weight: bold;\n+}\n+\n td {\n \tpadding: 2px 5px;\n \tfont-size: 100%;\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex c5675cf..c99cea3 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -15,7 +15,7 @@ use CGI::Carp qw(fatalsToBrowser);\n use Encode;\n use Fcntl ':mode';\n use File::Find qw();\n-use File::Basename qw(basename);\n+use File::Basename qw(basename dirname);\n binmode STDOUT, ':utf8';\n \n BEGIN {\n@@ -82,6 +82,9 @@ our $projects_list_description_width = 25;\n # valid values are none, project, descr, owner, and age\n our $default_projects_order = \"project\";\n \n+# use sections to separate projects by dirname, helps usability\n+our $use_sections = 1;\n+\n # show repository only if this file exists\n # (only effective if this variable evaluates to true)\n our $export_ok = \"++GITWEB_EXPORT_OK++\";\n@@ -3631,6 +3634,66 @@ sub print_sort_th_num {\n \tprint_sort_th(0, @_);\n }\n \n+sub print_section_tr {\n+\tmy ($n_cols, $section) = @_;\n+\tprint \"<tr class=\\\"section\\\"><td colspan=\\\"$n_cols\\\">$section</td></tr>\\n\";\n+}\n+\n+sub print_section_internal {\n+\tmy ($order, $n_cols, $current, $getter) = @_;\n+\tmy $current_value = $getter->($current);\n+\n+\tif (!$current_value) {\n+\t\treturn 0;\n+\t}\n+\n+\tmy $last_value = '';\n+\tif ($current > 0) {\n+\t\t$last_value = $getter->($current - 1);\n+\t}\n+\n+\tif ($current_value ne $last_value) {\n+\t\tprint_section_tr($n_cols, $current_value);\n+\t\treturn 1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+sub print_section_project {\n+\tmy ($order, $n_cols, $current, $projects) = @_;\n+\n+\tsub get_section_project {\n+\t\tmy ($index) = @_;\n+\t\treturn dirname(@$projects[$index]->{'path'});\n+\t}\n+\n+\treturn print_section_internal($order, $n_cols, $current, \\&get_section_project);\n+}\n+\n+sub print_section_owner {\n+\tmy ($order, $n_cols, $current, $projects) = @_;\n+\n+\tsub get_section_owner {\n+\t\tmy ($index) = @_;\n+\t\treturn @$projects[$index]->{'owner'};\n+\t}\n+\n+\treturn print_section_internal($order, $n_cols, $current, \\&get_section_owner);\n+}\n+\n+sub print_section {\n+\tmy ($order, $n_cols, $current, $projects) = @_;\n+\n+\tif ($order eq 'project') {\n+\t\treturn print_section_project($order, $n_cols, $current, $projects);\n+\t} elsif ($order eq 'owner') {\n+\t\treturn print_section_owner($order, $n_cols, $current, $projects);\n+\t}\n+\n+\treturn 0;\n+}\n+\n sub git_project_list_body {\n \tmy ($projlist, $order, $from, $to, $extra, $no_header) = @_;\n \n@@ -3658,9 +3721,17 @@ sub git_project_list_body {\n \t\tprint \"<th></th>\\n\" . # for links\n \t\t      \"</tr>\\n\";\n \t}\n+\tmy $n_cols = $check_forks ? 6 : 5;\n \tmy $alternate = 1;\n \tfor (my $i = $from; $i <= $to; $i++) {\n \t\tmy $pr = $projects[$i];\n+\n+                if ($use_sections) {\n+\t\t\tif (print_section($order, $n_cols, $i, \\@projects)) {\n+\t\t\t\t$alternate = 1;\n+\t\t\t}\n+                }\n+\n \t\tif ($alternate) {\n \t\t\tprint \"<tr class=\\\"dark\\\">\\n\";\n \t\t} else {\n-- \n1.5.5.2\n"},{"id":"85393","messageId":"1217303942-18526-1-git-send-email-barbieri@profusion.mobi","threadId":"14730","inReplyTo":"1217298868-16513-2-git-send-email-barbieri@profusion.mobi","subject":"[PATCH 1/2 v2] gitweb: sort projects by path.","fromName":"Gustavo Sverzut Barbieri","fromEmail":"barbieri@profusion.mobi","sentAt":"2008-07-29T03:59:02Z","receivedAt":"2008-07-29T03:59:02Z","isPatch":true,"sender":{"key":"barbieri@profusion.mobi","avatar":null},"body":"Projects are paths, so they should be sorted in pieces, not as a\nwhole, so a/x will be come before a-b/x.\n\nSigned-off-by: Gustavo Sverzut Barbieri <barbieri@profusion.mobi>\n---\n\nNew version that fix cmp_paths. Unlike I though initially, $#list\nreports the last element index, not the list length. Nonetheless the\nlast component must be compared only if the list lengths are the same,\notherwise we'll get $root/a/a.git before $root/b.git and sections will\nlook ugly (group elements of the same level together).\n\n\n gitweb/gitweb.perl |   42 +++++++++++++++++++++++++++++++++++++-----\n 1 files changed, 37 insertions(+), 5 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 90cd99b..06c9901 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3574,17 +3574,45 @@ sub fill_project_list_info {\n \treturn @projects;\n }\n \n+sub cmp_paths {\n+\tmy ($a, $b) = @_;\n+\tmy @la = split('/', $a);\n+\tmy @lb = split('/', $b);\n+\tmy $last;\n+\n+\tif ($#la < $#lb) {\n+\t\t$last = $#la;\n+\t} else {\n+\t\t$last = $#lb;\n+\t}\n+\n+\tfor (my $i = 0; $i < $last; $i++) {\n+\t\tmy $r = $la[$i] cmp $lb[$i];\n+\t\tif ($r != 0) {\n+\t\t\treturn $r;\n+\t\t}\n+\t}\n+\n+\tif ($#la == $#lb) {\n+\t\treturn $la[$last] cmp $lb[$last];\n+\t} else {\n+\t\treturn $#la <=> $#lb;\n+\t}\n+}\n+\n # print 'sort by' <th> element, either sorting by $key if $name eq $order\n # (changing $list), or generating 'sort by $name' replay link otherwise\n sub print_sort_th {\n-\tmy ($str_sort, $name, $order, $key, $header, $list) = @_;\n+\tmy ($sort_mode, $name, $order, $key, $header, $list) = @_;\n \t$key    ||= $name;\n \t$header ||= ucfirst($name);\n \n \tif ($order eq $name) {\n-\t\tif ($str_sort) {\n+\t\tif ($sort_mode == 2) {\n+\t\t\t@$list = sort {cmp_paths($a->{$key}, $b->{$key})} @$list;\n+\t\t} elsif ($sort_mode == 1) {\n \t\t\t@$list = sort {$a->{$key} cmp $b->{$key}} @$list;\n-\t\t} else {\n+\t\t} elsif ($sort_mode == 0) {\n \t\t\t@$list = sort {$a->{$key} <=> $b->{$key}} @$list;\n \t\t}\n \t\tprint \"<th>$header</th>\\n\";\n@@ -3596,6 +3624,10 @@ sub print_sort_th {\n \t}\n }\n \n+sub print_sort_th_path {\n+\tprint_sort_th(2, @_);\n+}\n+\n sub print_sort_th_str {\n \tprint_sort_th(1, @_);\n }\n@@ -3620,8 +3652,8 @@ sub git_project_list_body {\n \t\tif ($check_forks) {\n \t\t\tprint \"<th></th>\\n\";\n \t\t}\n-\t\tprint_sort_th_str('project', $order, 'path',\n-\t\t                  'Project', \\@projects);\n+\t\tprint_sort_th_path('project', $order, 'path',\n+\t\t                   'Project', \\@projects);\n \t\tprint_sort_th_str('descr', $order, 'descr_long',\n \t\t                  'Description', \\@projects);\n \t\tprint_sort_th_str('owner', $order, 'owner',\n-- \n1.5.5.2\n"},{"id":"85807","messageId":"b1f2b8c40807311243i5689683avcc3c3c91e4e6a900@mail.gmail.com","threadId":"14730","inReplyTo":"1217298868-16513-1-git-send-email-barbieri@profusion.mobi","subject":"Re: [PATCH 0/2] gitweb use sections","fromName":"Gustavo Sverzut Barbieri","fromEmail":"barbieri@profusion.mobi","sentAt":"2008-07-31T19:43:35Z","receivedAt":"2008-07-31T19:43:35Z","isPatch":true,"sender":{"key":"barbieri@profusion.mobi","avatar":null},"body":"Since nobody replied and I missed some gitweb guys in CC, I'm adding\nPetr and Jakub, as some guys said on IRC.\n\nHave anyone tried this patch, any problems?\n\n\nOn Mon, Jul 28, 2008 at 11:34 PM, Gustavo Sverzut Barbieri\n<barbieri@profusion.mobi> wrote:\n> The following two patches will add sections to gitweb so usability is\n> improved for large project listing. It looks like:\n>\n>    http://staff.get-e.org/\n>\n> but it's a new code that also supports owner sort.\n>\n> Patches orverview:\n>\n>  * [PATCH 1/2] gitweb: sort projects by path.\n>   This one is required to fix project sort. Since we use paths, we\n>   should compare individual components to make it look like a\n>   tree. Since we now can enable sections this error will be more\n>   evident, so there is the fix.\n>\n>  * [PATCH 2/2] gitweb: add section support to gitweb project listing.\n>   The real section work. This will add use_sections variable and if\n>   it evaluates to true sections will be enabled. Just project and\n>   owner sections are implemented.\n>\n> I hope it looks good for inclusion. Last time I did perl was about 8\n> years ago, please point any problems and I'll fix them.\n>\n>\n> --\n> Gustavo Sverzut Barbieri\n> http://profusion.mobi embedded systems\n> --------------------------------------\n> MSN: barbieri@gmail.com\n> Skype: gsbarbieri\n> Mobile: +55 (19) 9225-2202\n>\n>\n\n\n\n-- \nGustavo Sverzut Barbieri\nhttp://profusion.mobi embedded systems\n--------------------------------------\nMSN: barbieri@gmail.com\nSkype: gsbarbieri\nMobile: +55 (19) 9225-2202\n"},{"id":"85815","messageId":"20080731203250.GO10151@machine.or.cz","threadId":"14730","inReplyTo":"b1f2b8c40807311243i5689683avcc3c3c91e4e6a900@mail.gmail.com","subject":"Re: [PATCH 0/2] gitweb use sections","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2008-07-31T20:32:50Z","receivedAt":"2008-07-31T20:32:50Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"  Hi,\n\nOn Thu, Jul 31, 2008 at 04:43:35PM -0300, Gustavo Sverzut Barbieri wrote:\n> Since nobody replied and I missed some gitweb guys in CC, I'm adding\n> Petr and Jakub, as some guys said on IRC.\n> \n> Have anyone tried this patch, any problems?\n\n  sorry, I have it in my review queue. At first pass it was looking\ngood, but I wanted to look at it better before commenting.\n\n  One thing I'm wondering about is how to make this stuff configurable,\nsince I'm not very comfortable with adding more \"unbound\" configuration\nvariables and would rather prefer stuff to be added to the $features\narray... I'm not at all sure about my own sentiment here, however.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nAs in certain cults it is possible to kill a process if you know\nits true name.  -- Ken Thompson and Dennis M. Ritchie\n"},{"id":"85821","messageId":"b1f2b8c40807311358k4132ba8bw931279d7a6a7bcb5@mail.gmail.com","threadId":"14730","inReplyTo":"20080731203250.GO10151@machine.or.cz","subject":"Re: [PATCH 0/2] gitweb use sections","fromName":"Gustavo Sverzut Barbieri","fromEmail":"barbieri@profusion.mobi","sentAt":"2008-07-31T20:58:45Z","receivedAt":"2008-07-31T20:58:45Z","isPatch":true,"sender":{"key":"barbieri@profusion.mobi","avatar":null},"body":"On Thu, Jul 31, 2008 at 5:32 PM, Petr Baudis <pasky@suse.cz> wrote:\n>  Hi,\n>\n> On Thu, Jul 31, 2008 at 04:43:35PM -0300, Gustavo Sverzut Barbieri wrote:\n>> Since nobody replied and I missed some gitweb guys in CC, I'm adding\n>> Petr and Jakub, as some guys said on IRC.\n>>\n>> Have anyone tried this patch, any problems?\n>\n>  sorry, I have it in my review queue. At first pass it was looking\n> good, but I wanted to look at it better before commenting.\n\nno problem, just to see it was noticed or not :-)\n\n\n>  One thing I'm wondering about is how to make this stuff configurable,\n> since I'm not very comfortable with adding more \"unbound\" configuration\n> variables and would rather prefer stuff to be added to the $features\n> array... I'm not at all sure about my own sentiment here, however.\n\nPath comparison (first patch), Sections (second), both?\n\nI know path comparison can be a performance hit on large listings on\nsites with heavy traffic. However, I don't see many people accessing\nthe projects page at the same time for long periods, it's not like\nslashdot... people mostly use it to know about repositories and then\nuse git to track it.\n    The slowness is due O(n^2) worst case of sort and each step is not\na bit heavier since it need to split path into components and walk\nthese. Maybe cache the split?\n\n-- \nGustavo Sverzut Barbieri\nhttp://profusion.mobi embedded systems\n--------------------------------------\nMSN: barbieri@gmail.com\nSkype: gsbarbieri\nMobile: +55 (19) 9225-2202\n"},{"id":"86712","messageId":"b1f2b8c40808101245j2942dc70sa429cca05c1bb5c7@mail.gmail.com","threadId":"14730","inReplyTo":"b1f2b8c40807311358k4132ba8bw931279d7a6a7bcb5@mail.gmail.com","subject":"Re: [PATCH 0/2] gitweb use sections","fromName":"Gustavo Sverzut Barbieri","fromEmail":"barbieri@profusion.mobi","sentAt":"2008-08-10T19:45:14Z","receivedAt":"2008-08-10T19:45:14Z","isPatch":true,"sender":{"key":"barbieri@profusion.mobi","avatar":null},"body":"Yet another \"ping\" on this topic, news?\n\nOn Thu, Jul 31, 2008 at 5:58 PM, Gustavo Sverzut Barbieri\n<barbieri@profusion.mobi> wrote:\n> On Thu, Jul 31, 2008 at 5:32 PM, Petr Baudis <pasky@suse.cz> wrote:\n>>  Hi,\n>>\n>> On Thu, Jul 31, 2008 at 04:43:35PM -0300, Gustavo Sverzut Barbieri wrote:\n>>> Since nobody replied and I missed some gitweb guys in CC, I'm adding\n>>> Petr and Jakub, as some guys said on IRC.\n>>>\n>>> Have anyone tried this patch, any problems?\n>>\n>>  sorry, I have it in my review queue. At first pass it was looking\n>> good, but I wanted to look at it better before commenting.\n>\n> no problem, just to see it was noticed or not :-)\n>\n>\n>>  One thing I'm wondering about is how to make this stuff configurable,\n>> since I'm not very comfortable with adding more \"unbound\" configuration\n>> variables and would rather prefer stuff to be added to the $features\n>> array... I'm not at all sure about my own sentiment here, however.\n>\n> Path comparison (first patch), Sections (second), both?\n>\n> I know path comparison can be a performance hit on large listings on\n> sites with heavy traffic. However, I don't see many people accessing\n> the projects page at the same time for long periods, it's not like\n> slashdot... people mostly use it to know about repositories and then\n> use git to track it.\n>    The slowness is due O(n^2) worst case of sort and each step is not\n> a bit heavier since it need to split path into components and walk\n> these. Maybe cache the split?\n>\n> --\n> Gustavo Sverzut Barbieri\n> http://profusion.mobi embedded systems\n> --------------------------------------\n> MSN: barbieri@gmail.com\n> Skype: gsbarbieri\n> Mobile: +55 (19) 9225-2202\n>\n\n\n\n-- \nGustavo Sverzut Barbieri\nhttp://profusion.mobi embedded systems\n--------------------------------------\nMSN: barbieri@gmail.com\nSkype: gsbarbieri\nMobile: +55 (19) 9225-2202\n"}]}