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

Re: gitweb

From
Jakub Narębski <jnareb@gmail.com>
Date
Oct 29, 2012, 07:12 UTC
Message-ID
<CANQwDwd6EP94PEFkEcx8gBX1B5+-95qtjGMD6iU3ao8G+rCbLw@mail.gmail.com>
In-Reply-To
<20121029052815.GA30186@sigill.intra.peff.net>
On Mon, Oct 29, 2012 at 6:28 AM, Jeff King <peff@peff.net> wrote:
Show 15 quoted lines
> On Sun, Oct 28, 2012 at 04:56:47PM -0700, rh wrote:
>
>> I'm not using gitweb I was thinking about using it and was looking at the
>> cgi and saw this in this file:
>> https://github.com/git/git/blob/master/gitweb/gitweb.perl
>>
>> I think I understand the intention but the outcome is wrong.
>>
>> our %highlight_ext = (
>>       # main extensions, defining name of syntax;
>>       # see files in /usr/share/highlight/langDefs/ directory
>>       map { $_ => $_ }
>>       qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql make),
>>       # alternate extensions, see /etc/highlight/filetypes.conf
>>       'h' => 'c',
[...]
Show 19 quoted lines
> Yeah, this is wrong. The first map will eat the rest of the list, and
> you will get "h => h", "cxx => cxx", and so forth. I do not know this
> chunk of code, but that does not seem like it is the likely intent.
>
> You could fix it with extra parentheses:
>
>   our %he = (
>     (map { $_ => $_ } qw(py c cpp ...)),
>     'h' => 'c',
>     (map { $_ => 'sh' } qw(bash zsh ksh)),
>     ... etc ...
>   );
>
>> I think the intent is better met with this, (the print is for show)
>>
>> our %he = ();
>> $he{'h'} = 'c';
>> $he{$_} = $_     for (qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl sql make));
>> $he{$_} = 'cpp'  for (qw(cxx c++ cc));
[...]
Show 10 quoted lines
> That is more readable to me (though it does lose the obviousness that it
> is a variable initialization).
>
> Looks like this was broken since 592ea41 (gitweb: Refactor syntax
> highlighting support, 2010-04-27). I do not use gitweb (nor highlight)
> at all, but I'd guess the user-visible impact is that "*.h" files are
> not correctly highlighted
>
> Jakub, can you confirm the intent and a fix like the one above makes
> things better?
Yes, either of those makes things better.
>                                   (unless highlight does this extension mapping
> itself, but then why are we doing it here?).

Highlight does extension mapping itself... but for that it needs file name, and not to be feed file contents from pipe.

-- 
Jakub Narebski
Previous: Jeff KingNext: Jeff King
Message 3 of 4 in “gitweb”
  1. rhOct 28, 2012
  2. Jeff KingOct 29, 2012
  3. Jakub NarębskiOct 29, 2012
  4. Jeff KingOct 29, 2012

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.