{"thread":{"id":"13886","subject":"[PATCH 2/2] gitweb: Separate generating 'sort by' table header","startedAt":"2008-06-10T17:19:23Z","lastAt":"2008-06-10T17:21:44Z","messageCount":3,"participants":["Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"79368","messageId":"200806101919.24242.jnareb@gmail.com","threadId":"13886","inReplyTo":null,"subject":"[PATCH 0/2] gitweb: Refactor projects_list generation","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-06-10T17:19:23Z","receivedAt":"2008-06-10T17:19:23Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"These two patches make code generating 'projects_list\" view better.\nThis is resend of those patches, this time without following patches\nwhich add new features like allowing 'description' field in\n$projects_list file, searching for projects, and paginating projects\nlist page.\n\nThose two patches should also make it easier for Lea to plug-in\ncaching in gitweb.  That's why I'm sending them even in the rc/freeze\nperiod...\n\nShortlog:\n=========\nJakub Narebski (2):\n  gitweb: Separate filling list of projects info\n  gitweb: Separate generating 'sort by' table header\n\nDiffstat:\n=========\n gitweb/gitweb.perl |  111 +++++++++++++++++++++++++++++-----------------------\n 1 files changed, 62 insertions(+), 49 deletions(-)\n\n-- \nJakub Narebski\nShadeHawk on #git\n"},{"id":"79370","messageId":"200806101921.02156.jnareb@gmail.com","threadId":"13886","inReplyTo":"200806101919.24242.jnareb@gmail.com","subject":"[PATCH 1/2] gitweb: Separate filling list of projects info","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-06-10T17:21:01Z","receivedAt":"2008-06-10T17:21:01Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Extract filling project list info, i.e. adding age, description, owner\nand forks information, into fill_project_list_info() subroutine.  This\nis preparation for smart pagination and smart searching (to make it\npossible to calculate/generate info only for those projects which will\nbe shown).\n\nSmall changes compared to original version to improve readability\n(comments, names of variables, named loops).\n\nAdditionally, store both full ('descr_long') and shortened ('descr')\nproject description in Perl's internal form (using to_utf8).\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nIt is meant to be minimally intrusive patch, although it corrects\nsome code (variable naming, ensuring storing data in Perl internal\nform, comments, etc.).\n\n gitweb/gitweb.perl |   35 +++++++++++++++++++++++------------\n 1 files changed, 23 insertions(+), 12 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 198772c..d7a9809 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3559,21 +3559,24 @@ sub git_patchset_body {\n \n # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\n \n-sub git_project_list_body {\n-\tmy ($projlist, $order, $from, $to, $extra, $no_header) = @_;\n-\n-\tmy ($check_forks) = gitweb_check_feature('forks');\n-\n+# fills project list info (age, description, owner, forks) for each\n+# project in the list, removing invalid projects from returned list\n+# NOTE: modifies $projlist, but does not remove entries from it\n+sub fill_project_list_info {\n+\tmy ($projlist, $check_forks) = @_;\n \tmy @projects;\n+\n+ PROJECT:\n \tforeach my $pr (@$projlist) {\n-\t\tmy (@aa) = git_get_last_activity($pr->{'path'});\n-\t\tunless (@aa) {\n-\t\t\tnext;\n+\t\tmy (@activity) = git_get_last_activity($pr->{'path'});\n+\t\tunless (@activity) {\n+\t\t\tnext PROJECT;\n \t\t}\n-\t\t($pr->{'age'}, $pr->{'age_string'}) = @aa;\n+\t\t($pr->{'age'}, $pr->{'age_string'}) = @activity;\n \t\tif (!defined $pr->{'descr'}) {\n \t\t\tmy $descr = git_get_project_description($pr->{'path'}) || \"\";\n-\t\t\t$pr->{'descr_long'} = to_utf8($descr);\n+\t\t\t$descr = to_utf8($descr);\n+\t\t\t$pr->{'descr_long'} = $descr;\n \t\t\t$pr->{'descr'} = chop_str($descr, $projects_list_description_width, 5);\n \t\t}\n \t\tif (!defined $pr->{'owner'}) {\n@@ -3585,14 +3588,22 @@ sub git_project_list_body {\n \t\t\t    ($pname !~ /\\/$/) &&\n \t\t\t    (-d \"$projectroot/$pname\")) {\n \t\t\t\t$pr->{'forks'} = \"-d $projectroot/$pname\";\n-\t\t\t}\n-\t\t\telse {\n+\t\t\t}\telse {\n \t\t\t\t$pr->{'forks'} = 0;\n \t\t\t}\n \t\t}\n \t\tpush @projects, $pr;\n \t}\n \n+\treturn @projects;\n+}\n+\n+sub git_project_list_body {\n+\tmy ($projlist, $order, $from, $to, $extra, $no_header) = @_;\n+\n+\tmy ($check_forks) = gitweb_check_feature('forks');\n+\tmy @projects = fill_project_list_info($projlist, $check_forks);\n+\n \t$order ||= $default_projects_order;\n \t$from = 0 unless defined $from;\n \t$to = $#projects if (!defined $to || $#projects < $to);\n-- \n1.5.5.3\n"},{"id":"79367","messageId":"200806101921.45017.jnareb@gmail.com","threadId":"13886","inReplyTo":"200806101919.24242.jnareb@gmail.com","subject":"[PATCH 2/2] gitweb: Separate generating 'sort by' table header","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-06-10T17:21:44Z","receivedAt":"2008-06-10T17:21:44Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Extract generating table header cell, for tables which can be sorted\nby its columns, into print_sort_th_str() and print_sort_th_num()\nsubroutines, and print_sort_th() driver subroutine.\n\nThis avoids repetition, and should make further improvements (like\nJavaScript sorting) easier.  The subroutine uses now \"replay\" link,\nso it is generic enough to be able to use it for other tables which\ncan be sorted by column, like for example 'heads' and 'tags' view\n(sort by name, or sort by age).\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nFor further code reusing, and current code clarity.\n\n gitweb/gitweb.perl |   76 ++++++++++++++++++++++++++-------------------------\n 1 files changed, 39 insertions(+), 37 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex d7a9809..c7882f2 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -3598,6 +3598,36 @@ sub fill_project_list_info {\n \treturn @projects;\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+\t$key    ||= $name;\n+\t$header ||= ucfirst($name);\n+\n+\tif ($order eq $name) {\n+\t\tif ($str_sort) {\n+\t\t\t@$list = sort {$a->{$key} cmp $b->{$key}} @$list;\n+\t\t} else {\n+\t\t\t@$list = sort {$a->{$key} <=> $b->{$key}} @$list;\n+\t\t}\n+\t\tprint \"<th>$header</th>\\n\";\n+\t} else {\n+\t\tprint \"<th>\" .\n+\t\t      $cgi->a({-href => href(-replay=>1, order=>$name),\n+\t\t               -class => \"header\"}, $header) .\n+\t\t      \"</th>\\n\";\n+\t}\n+}\n+\n+sub print_sort_th_str {\n+\tprint_sort_th(1, @_);\n+}\n+\n+sub print_sort_th_num {\n+\tprint_sort_th(0, @_);\n+}\n+\n sub git_project_list_body {\n \tmy ($projlist, $order, $from, $to, $extra, $no_header) = @_;\n \n@@ -3614,43 +3644,15 @@ sub git_project_list_body {\n \t\tif ($check_forks) {\n \t\t\tprint \"<th></th>\\n\";\n \t\t}\n-\t\tif ($order eq \"project\") {\n-\t\t\t@projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;\n-\t\t\tprint \"<th>Project</th>\\n\";\n-\t\t} else {\n-\t\t\tprint \"<th>\" .\n-\t\t\t      $cgi->a({-href => href(project=>undef, order=>'project'),\n-\t\t\t               -class => \"header\"}, \"Project\") .\n-\t\t\t      \"</th>\\n\";\n-\t\t}\n-\t\tif ($order eq \"descr\") {\n-\t\t\t@projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;\n-\t\t\tprint \"<th>Description</th>\\n\";\n-\t\t} else {\n-\t\t\tprint \"<th>\" .\n-\t\t\t      $cgi->a({-href => href(project=>undef, order=>'descr'),\n-\t\t\t               -class => \"header\"}, \"Description\") .\n-\t\t\t      \"</th>\\n\";\n-\t\t}\n-\t\tif ($order eq \"owner\") {\n-\t\t\t@projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;\n-\t\t\tprint \"<th>Owner</th>\\n\";\n-\t\t} else {\n-\t\t\tprint \"<th>\" .\n-\t\t\t      $cgi->a({-href => href(project=>undef, order=>'owner'),\n-\t\t\t               -class => \"header\"}, \"Owner\") .\n-\t\t\t      \"</th>\\n\";\n-\t\t}\n-\t\tif ($order eq \"age\") {\n-\t\t\t@projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;\n-\t\t\tprint \"<th>Last Change</th>\\n\";\n-\t\t} else {\n-\t\t\tprint \"<th>\" .\n-\t\t\t      $cgi->a({-href => href(project=>undef, order=>'age'),\n-\t\t\t               -class => \"header\"}, \"Last Change\") .\n-\t\t\t      \"</th>\\n\";\n-\t\t}\n-\t\tprint \"<th></th>\\n\" .\n+\t\tprint_sort_th_str('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+\t\t                  'Owner', \\@projects);\n+\t\tprint_sort_th_num('age', $order, 'age',\n+\t\t                  'Last Change', \\@projects);\n+\t\tprint \"<th></th>\\n\" . # for links\n \t\t      \"</tr>\\n\";\n \t}\n \tmy $alternate = 1;\n-- \n1.5.5.3\n"}]}