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

Re: [PATCH] Small optimizations to gitweb

From
Jakub Narebski <jnareb@gmail.com>
Date
Dec 19, 2006, 00:59 UTC
Message-ID
<200612190159.24173.jnareb@gmail.com>
In-Reply-To
<7vbqm0vkd6.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano wrote:
Show 34 quoted lines
> Jakub Narebski <jnareb@gmail.com> writes:
> 
>> Actually, that is needed to implement checking if we have more than
>> the number of commits to show to add '...' at the end only if there
>> are some commits which we don't show.
> 
> The counting code in git_*_body is seriously unusual to tempt
> anybody who reviews the code to reduce that 17 to 16.
> 
> The caller says:
> 
> 	git_shortlog_body(\@revlist, 0, 15, $refs,
> 	                  $cgi->a({-href => href(action=>"shortlog")}, "..."));
> 
> If it counts up, especially if it counts from zero, the loop
> would usually say:
> 
> 	for (i = bottom; i < end; i++)
> 
> and anybody who reads that caller would expect it to show 15
> lines of output.
> 
> But the actual code does this instead:
> 
>     sub git_shortlog_body {
>             # uses global variable $project
>             my ($revlist, $from, $to, $refs, $extra) = @_;
> 
>             $from = 0 unless defined $from;
>             $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
>             ...
>             for (my $i = $from; $i <= $to; $i++) {
>                     ... draw each item ...
>             }
Well, this should be then corrected perhaps to
            my ($revlist, $begin, $end, $refs, $extra) = @_;
            $begin = 0 unless defined $from;
            $end = scalar(@$revlist) if (!defined $end || @$revlist <= $end);
            ...
            for (my $i = $begin; $i < $end; $i++) {
                    ... draw each item ...
            }

I thought that $from..$to ($from <= i <= $to) is more natural and easier to understand than $begin..$end ($begin <= i < $end)... guess I guessed wrong.

Show 10 quoted lines
>             if (defined $extra) {
>                     print "<tr>\n" .
>                           "<td colspan=\"4\">$extra</td>\n" .
>                           "</tr>\n";
>             }
>     }
> 
> By the way, I wonder how that $extra is omitted when $revlist is
> longer than $to; it should be a trivial fix but it seems to me
> that it is always spitted out with the current code.

We should check if we want to omit $extra, either in caller or in callee, the *_body subroutine itself.

-- 
Jakub Narebski
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 11 in “Small optimizations to gitweb”
  1. Small optimizations to gitwebRobert Fitzsimons, Dec 18, 2006
  2. Jakub NarebskiDec 18, 2006
  3. Junio C HamanoDec 18, 2006
  4. Jakub NarebskiDec 19, 2006
  5. Junio C HamanoDec 19, 2006
  6. gitweb: Show '...' links in "summary" view only if there are more itemsJakub Narebski, Dec 19, 2006
  7. gitweb: Show '...' links in "summary" view only if there are more itemsRobert Fitzsimons, Dec 19, 2006
  8. Jakub NarebskiDec 19, 2006
  9. Robert FitzsimonsDec 19, 2006
  10. Jakub NarebskiDec 19, 2006
  11. Junio C HamanoDec 19, 2006

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.