]> Lady’s Gitweb - Gitweb/commit
gitweb: use highlight's shebang detection
authorIan Kelling <redacted>
Sat, 24 Sep 2016 22:32:58 +0000 (15:32 -0700)
committerLady <redacted>
Mon, 6 Apr 2026 04:51:32 +0000 (00:51 -0400)
commit85b5c0af1f4f6fd30abf32a95a8afc615fd359a3ae5ebf066deea4b36b8e761b
tree52e6d4b7b76f936ed039a95efdde65693faee12a3ebae14ae2f2b399b5dfb4ba
parent59d8a88303ab6dcb4e4c433727dabae0514c7e9e9663e87e40cf9a341ba5597e
gitweb: use highlight's shebang detection

The "highlight" binary can, in some cases, determine the language type
by the means of file contents, for example the shebang in the first line
for some scripting languages.  Make use of this autodetection for files
which syntax is not known by gitweb.  In that case, pass the blob
contents to "highlight --force"; the parameter is needed to make it
always generate HTML output (which includes HTML-escaping).

Although we now run highlight on files which do not end up highlighted,
performance is virtually unaffected because when we call highlight, it
is used for escaping HTML.  In the case that highlight is used, gitweb
calls sanitize() instead of esc_html(), and the latter is significantly
slower (it does more, being roughly a superset of sanitize()).  Simple
benchmark comparing performance of 'blob' view of files without syntax
highlighting in gitweb before and after this change indicates ±1%
difference in request time for all file types.  Benchmark was performed
on local instance on Debian, using Apache/2.4.23 web server and CGI.

Document the feature and improve syntax highlight documentation, add
test to ensure gitweb doesn't crash when language detection is used.

Signed-off-by: Ian Kelling <redacted>
Acked-by: Jakub Narębski <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl
This page took 0.177459 seconds and 4 git commands to generate.