Merge branch 'ab/gitweb-abbrev-links'
authorJunio C Hamano <gitster@pobox.com>
Wed, 26 Oct 2016 20:14:45 +0000 (13:14 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Oct 2016 20:14:46 +0000 (13:14 -0700)
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

1  2 
gitweb/gitweb.perl
diff --combined gitweb/gitweb.perl
index 44094f41d580bd4259bdb2bdb680b6dff4fd5340,3a52bc77054b4646ab0d954ff4aa85ea7f466bf1..7cf68f07b773f7e520c1e6ba680bff65e5bc7f3a
@@@ -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
+             (?<!-) # see strbuf_check_tag_ref(). Tags can't start with -
+             [A-Za-z0-9.-]+
+             (?!\.) # refs can't end with ".", see check_refname_format()
+             -g[0-9a-fA-F]{7,40}
+             |
+             # Just a normal looking Git SHA1
+             [0-9a-fA-F]{7,40}
+         )
+         \b
+     }{
                $cgi->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}
  # 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 = '';
                        $line = untabify($line);
                        printf qq!<div class="pre"><a id="l%i" href="%s#l%i" class="linenr">%4i</a> %s</div>\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