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

Re: [PATCH] gitweb: reset input record separator in parse_commit even on error

From
Jakub Narebski <jnareb@gmail.com>
Date
Sep 9, 2006, 22:00 UTC
Message-ID
<edvdgb$mtt$1@sea.gmane.org>
In-Reply-To
<20060909205159.GC16906@coredump.intra.peff.net>
Jeff King wrote:
Show 26 quoted lines
> On Sat, Sep 09, 2006 at 05:12:36PM +0200, Sven Verdoolaege wrote:
> 
>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
>> index 7afdf33..60dd598 100755
>> --- a/gitweb/gitweb.perl
>> +++ b/gitweb/gitweb.perl
>> @@ -897,8 +897,8 @@ sub parse_commit {
>>              my $fd = git_pipe("rev-list", "--header", "--parents", "--max-count=1", $commit_id)
>>                      or return;
>>              @commit_lines = split '\n', <$fd>;
>> -            close $fd or return;
>>              $/ = "\n";
>> +            close $fd or return;
>>              pop @commit_lines;
>>      }
>>      my $header = shift @commit_lines;
> 
> You missed the other early return from git_pipe. However, I think the
> approach is wrong; this is a great opportunity to use the dynamic
> scoping offered by 'local':
> 
>   else {
>     local $/ = "\0";
>     # do stuff with $/ as "\0"
>   }
>   # $/ has automatically been reset at the end of the block
And this should be done consistently, for all plain formats 
(blob_plain, blobdiff_plain, commitdiff_plain), and some other
 places.
Sometimes it is
  local $/ = "\0";
more often
  local $/ = undef;
(or equivalently but slightly less human friendly, just 'local $/');
Show 8 quoted lines
> Looking further at this bit of code, it seems even more confusing,
> though. We split the output of rev-list on NUL, grab presumably the
> entire thing (since there shouldn't be any NULs in the output, right?)
> and then split it on newline into a list. Why aren't we doing this:
>   else {
>     open my $fd, ...;
>     @commit_lines = map { chomp; $_ } <$fd>;
>     ...

That is because by default git-rev-list separates output for different commits (when --header option is used) bu NULL... only because of "--max-count=1" there is only _one_ record... nevertheless it ends with "\0" (NULL) character.

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Previous: Jeff King
Message 3 of 3 in “gitweb: reset input record separator in parse_commit even on error”
  1. gitweb: reset input record separator in parse_commit even on errorSven Verdoolaege, Sep 9, 2006
  2. Jeff KingSep 9, 2006
  3. Jakub NarebskiSep 9, 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.