git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 3/3] gitweb: Optional grouping of projects by category

From
Jakub Narebski <jnareb@gmail.com>
Date
Dec 12, 2008, 00:13 UTC
Message-ID
<200812120113.47051.jnareb@gmail.com>
In-Reply-To
<878wqmz3pl.wl%seb@cine7.net>
On Fri, 12 Dec 2008, Sébastien Cevey wrote:
Show 14 quoted lines
> At Fri, 5 Dec 2008 11:45:08 +0100, Jakub Narebski wrote:
> 
>>>> Nice... but perhaps it would be better to simply pass $from / $to to
>>>> build_projlist_by_category function, and have in %categories only
>>>> projects which are shown...
>>> 
>>> Ah you're right, we could do that, I hadn't thought of it.  Sounds
>>> cleaner than the $from/$to dance I did in this patch.
>>
>> [...] we can simply pass $from and $to to
>> build_projlist_by_category(), and use loop $from..$to there.
> 
> I just tried, it works but we first need to sort @projects by
> category.
I don't understand. You have the following code:

+# returns a hash of categories, containing the list of project +# belonging to each category +sub build_projlist_by_category { +       my $projlist = shift; +       my %categories; + +       for my $pr (@$projlist) { +               push @{$categories{ $pr->{'category'} }}, $pr; +       } + +       return %categories; +}

I propose to change it to:
+# returns a hash of categories, containing the list of project
+# belonging to each category
+sub build_projlist_by_category {
+       my ($projlist, $from, $to) = shift;                       # <<<<<<<<<<<<<<<<<<<<<<<
+	$from = 0 unless defined $from;                           # +++++++++++++++++++++++
+	$to = $#$projlist if (!defined $to || $#$projlist < $to); # +++++++++++++++++++++++
+       my %categories;
+
+       for (my $i = $from; $i <= $to; $i++) {                    # <<<<<<<<<<<<<<<<<<<<<<<
+		$pr = $projlist->[$i];                            # +++++++++++++++++++++++
+               push @{$categories{ $pr->{'category'} }}, $pr;
+       }
+
+       return %categories;
+}
And of course update callers to pass $from and $to parameters.

This code doesn't change _anything_ beside the fact that it can operate only on part of @$projlist.

But as you have noticed some kinds of limiting shown project list size make sense only if done _after_ dividing into categories. Some but not all. For example page length limiting after sorting by name, description, owner or age (sorting which takes place before dividing into categories) makes sense if it is done _before_ categorization: we want to show e.g. 100 freshest projects, and not up to 100 projects from first categories, with last category showing maybe only freshest projects in this category.

Besides making selection of projects to show operate on list of projects instead of being done just before display is IMHO better, more flexible, and more robust solution.

> I'm gonna re-send the three patches as a new version.
Thanks in advance.
-- 
Jakub Narebski
Poland
Previous: Sébastien CeveyNext: Sébastien Cevey
Message 16 of 24 in “gitweb: Optional grouping of projects by category”
  1. gitweb: Optional grouping of projects by categorySebastien Cevey, Dec 2, 2008
  2. Jakub NarebskiDec 2, 2008
  3. gitweb: Optional grouping of projects by categorySébastien Cevey, Dec 3, 2008
  4. Junio C HamanoDec 3, 2008
  5. Jakub NarebskiDec 3, 2008
  6. 0/3 gitweb: Optional grouping of projects by categorySébastien Cevey, Dec 4, 2008
  7. Junio C HamanoDec 4, 2008
  8. 1/3 gitweb: Modularized git_get_project_description to be more genericSébastien Cevey, Dec 4, 2008
  9. 2/3 gitweb: Split git_project_list_body in two functionsSébastien Cevey, Dec 4, 2008
  10. 3/3 gitweb: Optional grouping of projects by categorySébastien Cevey, Dec 4, 2008
  11. Junio C HamanoDec 4, 2008
  12. Jakub NarebskiDec 5, 2008
  13. Sébastien CeveyDec 5, 2008
  14. Jakub NarebskiDec 5, 2008
  15. Sébastien CeveyDec 11, 2008
  16. Jakub NarebskiDec 12, 2008
  17. Sébastien CeveyDec 12, 2008
  18. Jakub NarebskiDec 12, 2008
  19. Sébastien CeveyDec 12, 2008
  20. Jakub NarebskiDec 12, 2008
  21. Jakub NarebskiDec 5, 2008
  22. Jakub NarebskiDec 5, 2008
  23. Sébastien CeveyDec 3, 2008
  24. Junio C HamanoDec 3, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.