From: Junio C Hamano Date: Wed, 26 Oct 2016 20:14:45 +0000 (-0700) Subject: Merge branch 'ab/gitweb-abbrev-links' X-Git-Tag: v2.11.0-rc0~42 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/5b941872d6003976ba4a1adc92bbc4de774661a8?ds=inline;hp=-c Merge branch 'ab/gitweb-abbrev-links' In addition to purely abbreviated commit object names, "gitweb" learned to turn "git describe" output (e.g. v2.9.3-599-g2376d31787) into clickable links in its output. * ab/gitweb-abbrev-links: gitweb: link to "git describe"'d commits in log messages gitweb: link to 7-char+ SHA-1s, not only 8-char+ gitweb: fix a typo in a comment --- 5b941872d6003976ba4a1adc92bbc4de774661a8 diff --combined gitweb/gitweb.perl index 44094f41d5,3a52bc7705..7cf68f07b7 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@@ -1616,7 -1616,7 +1616,7 @@@ sub esc_path return $str; } - # Sanitize for use in XHTML + application/xml+xhtm (valid XML 1.0) + # Sanitize for use in XHTML + application/xml+xhtml (valid XML 1.0) sub sanitize { my $str = shift; @@@ -2036,10 -2036,24 +2036,24 @@@ sub format_log_line_html my $line = shift; $line = esc_html($line, -nbsp=>1); - $line =~ s{\b([0-9a-fA-F]{8,40})\b}{ + $line =~ s{ + \b + ( + # The output of "git describe", e.g. v2.10.0-297-gf6727b0 + # or hadoop-20160921-113441-20-g094fb7d + (?a({-href => href(action=>"object", hash=>$1), -class => "text"}, $1); - }eg; + }egx; return $line; } @@@ -3913,7 -3927,7 +3927,7 @@@ sub blob_contenttype # guess file syntax for syntax highlighting; return undef if no highlighting # the name of syntax can (in the future) depend on syntax highlighter used sub guess_file_syntax { - my ($highlight, $mimetype, $file_name) = @_; + my ($highlight, $file_name) = @_; return undef unless ($highlight && defined $file_name); my $basename = basename($file_name, '.in'); return $highlight_basename{$basename} @@@ -3931,16 -3945,15 +3945,16 @@@ # or return original FD if no highlighting sub run_highlighter { my ($fd, $highlight, $syntax) = @_; - return $fd unless ($highlight && defined $syntax); + return $fd unless ($highlight); close $fd; + my $syntax_arg = (defined $syntax) ? "--syntax $syntax" : "--force"; open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ". quote_command($^X, '-CO', '-MEncode=decode,FB_DEFAULT', '-pse', '$_ = decode($fe, $_, FB_DEFAULT) if !utf8::decode($_);', '--', "-fe=$fallback_encoding")." | ". quote_command($highlight_bin). - " --replace-tabs=8 --fragment --syntax $syntax |" + " --replace-tabs=8 --fragment $syntax_arg |" or die_error(500, "Couldn't open file or run syntax highlighter"); return $fd; } @@@ -7063,8 -7076,9 +7077,8 @@@ sub git_blob $have_blame &&= ($mimetype =~ m!^text/!); my $highlight = gitweb_check_feature('highlight'); - my $syntax = guess_file_syntax($highlight, $mimetype, $file_name); - $fd = run_highlighter($fd, $highlight, $syntax) - if $syntax; + my $syntax = guess_file_syntax($highlight, $file_name); + $fd = run_highlighter($fd, $highlight, $syntax); git_header_html(undef, $expires); my $formats_nav = ''; @@@ -7117,7 -7131,7 +7131,7 @@@ $line = untabify($line); printf qq!
%4i %s
\n!, $nr, esc_attr(href(-replay => 1)), $nr, $nr, - $syntax ? sanitize($line) : esc_html($line, -nbsp=>1); + $highlight ? sanitize($line) : esc_html($line, -nbsp=>1); } } close $fd