]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.perl
gitweb: remove title shortening heuristics
[Gitweb] / gitweb.perl
index 7f9a7ddbbdf7904291e1b8e891ab4763c803331cf18fa28d69e682b67e743906..8c96a1dd0ab78384a91c40b8cde1a09478a2b6fd58f6127f3bd05e3657c4b807 100755 (executable)
@@ -570,6 +570,15 @@ our %feature = (
                'sub' => \&feature_extra_branch_refs,
                'override' => 0,
                'default' => []},
                'sub' => \&feature_extra_branch_refs,
                'override' => 0,
                'default' => []},
+
+       # Redact e-mail addresses.
+
+       # To enable system wide have in $GITWEB_CONFIG
+       # $feature{'email-privacy'}{'default'} = [1];
+       'email-privacy' => {
+               'sub' => sub { feature_bool('email-privacy', @_) },
+               'override' => 1,
+               'default' => [0]},
 );
 
 sub gitweb_get_feature {
 );
 
 sub gitweb_get_feature {
@@ -3450,6 +3459,13 @@ sub parse_date {
        return %date;
 }
 
        return %date;
 }
 
+sub hide_mailaddrs_if_private {
+       my $line = shift;
+       return $line unless gitweb_check_feature('email-privacy');
+       $line =~ s/<[^@>]+@[^>]+>/<redacted>/g;
+       return $line;
+}
+
 sub parse_tag {
        my $tag_id = shift;
        my %tag;
 sub parse_tag {
        my $tag_id = shift;
        my %tag;
@@ -3466,7 +3482,7 @@ sub parse_tag {
                } elsif ($line =~ m/^tag (.+)$/) {
                        $tag{'name'} = $1;
                } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
                } elsif ($line =~ m/^tag (.+)$/) {
                        $tag{'name'} = $1;
                } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
-                       $tag{'author'} = $1;
+                       $tag{'author'} = hide_mailaddrs_if_private($1);
                        $tag{'author_epoch'} = $2;
                        $tag{'author_tz'} = $3;
                        if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
                        $tag{'author_epoch'} = $2;
                        $tag{'author_tz'} = $3;
                        if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
@@ -3514,7 +3530,7 @@ sub parse_commit_text {
                } elsif ((!defined $withparents) && ($line =~ m/^parent ($oid_regex)$/)) {
                        push @parents, $1;
                } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
                } elsif ((!defined $withparents) && ($line =~ m/^parent ($oid_regex)$/)) {
                        push @parents, $1;
                } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
-                       $co{'author'} = to_utf8($1);
+                       $co{'author'} = hide_mailaddrs_if_private(to_utf8($1));
                        $co{'author_epoch'} = $2;
                        $co{'author_tz'} = $3;
                        if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
                        $co{'author_epoch'} = $2;
                        $co{'author_tz'} = $3;
                        if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
@@ -3524,7 +3540,7 @@ sub parse_commit_text {
                                $co{'author_name'} = $co{'author'};
                        }
                } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
                                $co{'author_name'} = $co{'author'};
                        }
                } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
-                       $co{'committer'} = to_utf8($1);
+                       $co{'committer'} = hide_mailaddrs_if_private(to_utf8($1));
                        $co{'committer_epoch'} = $2;
                        $co{'committer_tz'} = $3;
                        if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
                        $co{'committer_epoch'} = $2;
                        $co{'committer_tz'} = $3;
                        if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
@@ -3545,23 +3561,6 @@ sub parse_commit_text {
                $title =~ s/^    //;
                if ($title ne "") {
                        $co{'title'} = chop_str($title, 80, 5);
                $title =~ s/^    //;
                if ($title ne "") {
                        $co{'title'} = chop_str($title, 80, 5);
-                       # remove leading stuff of merges to make the interesting part visible
-                       if (length($title) > 50) {
-                               $title =~ s/^Automatic //;
-                               $title =~ s/^merge (of|with) /Merge ... /i;
-                               if (length($title) > 50) {
-                                       $title =~ s/(http|rsync):\/\///;
-                               }
-                               if (length($title) > 50) {
-                                       $title =~ s/(master|www|rsync)\.//;
-                               }
-                               if (length($title) > 50) {
-                                       $title =~ s/kernel.org:?//;
-                               }
-                               if (length($title) > 50) {
-                                       $title =~ s/\/pub\/scm//;
-                               }
-                       }
                        $co{'title_short'} = chop_str($title, 50, 5);
                        last;
                }
                        $co{'title_short'} = chop_str($title, 50, 5);
                        last;
                }
@@ -3569,9 +3568,10 @@ sub parse_commit_text {
        if (! defined $co{'title'} || $co{'title'} eq "") {
                $co{'title'} = $co{'title_short'} = '(no commit message)';
        }
        if (! defined $co{'title'} || $co{'title'} eq "") {
                $co{'title'} = $co{'title_short'} = '(no commit message)';
        }
-       # remove added spaces
+       # remove added spaces, redact e-mail addresses if applicable.
        foreach my $line (@commit_lines) {
                $line =~ s/^    //;
        foreach my $line (@commit_lines) {
                $line =~ s/^    //;
+               $line = hide_mailaddrs_if_private($line);
        }
        $co{'comment'} = \@commit_lines;
 
        }
        $co{'comment'} = \@commit_lines;
 
@@ -3780,7 +3780,8 @@ sub git_get_heads_list {
        my @headslist;
 
        open my $fd, '-|', git_cmd(), 'for-each-ref',
        my @headslist;
 
        open my $fd, '-|', git_cmd(), 'for-each-ref',
-               ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
+               ($limit ? '--count='.($limit+1) : ()),
+               '--sort=-HEAD', '--sort=-committerdate',
                '--format=%(objectname) %(refname) %(subject)%00%(committer)',
                @patterns
                or return;
                '--format=%(objectname) %(refname) %(subject)%00%(committer)',
                @patterns
                or return;
@@ -4196,19 +4197,20 @@ sub git_header_html {
        my %opts = @_;
 
        my $title = get_page_title();
        my %opts = @_;
 
        my $title = get_page_title();
-       my $content_type = get_content_type_html();
-       print $cgi->header(-type=>$content_type, -charset => 'utf-8',
+       print $cgi->header(-type=>get_content_type_html(), -charset => 'utf-8',
                           -status=> $status, -expires => $expires)
                unless ($opts{'-no_http_header'});
        my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
        print <<EOF;
 <?xml version="1.0" encoding="utf-8"?>
                           -status=> $status, -expires => $expires)
                unless ($opts{'-no_http_header'});
        my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
        print <<EOF;
 <?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!DOCTYPE html [
+       <!ENTITY nbsp "&#xA0;">
+       <!ENTITY sdot "&#x22C5;">
+]>
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
 <!-- git core binaries version $git_version -->
 <head>
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
 <!-- git core binaries version $git_version -->
 <head>
-<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
 <meta name="robots" content="index, nofollow"/>
 <title>$title</title>
 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
 <meta name="robots" content="index, nofollow"/>
 <title>$title</title>
@@ -4642,7 +4644,7 @@ sub git_print_log {
        # print log
        my $skip_blank_line = 0;
        foreach my $line (@$log) {
        # print log
        my $skip_blank_line = 0;
        foreach my $line (@$log) {
-               if ($line =~ m/^\s*([A-Z][-A-Za-z]*-[Bb]y|C[Cc]): /) {
+               if ($line =~ m/^\s*([A-Z][-A-Za-z]*-([Bb]y|[Tt]o)|C[Cc]|(Clos|Fix)es): /) {
                        if (! $opts{'-remove_signoff'}) {
                                print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
                                $skip_blank_line = 1;
                        if (! $opts{'-remove_signoff'}) {
                                print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
                                $skip_blank_line = 1;
@@ -7490,7 +7492,8 @@ sub git_log_generic {
                                 -accesskey => "n", -title => "Alt-n"}, "next");
        }
        my $patch_max = gitweb_get_feature('patches');
                                 -accesskey => "n", -title => "Alt-n"}, "next");
        }
        my $patch_max = gitweb_get_feature('patches');
-       if ($patch_max && !defined $file_name) {
+       if ($patch_max && !defined $file_name &&
+               !gitweb_check_feature('email-privacy')) {
                if ($patch_max < 0 || @commitlist <= $patch_max) {
                        $paging_nav .= " &sdot; " .
                                $cgi->a({-href => href(action=>"patches", -replay=>1)},
                if ($patch_max < 0 || @commitlist <= $patch_max) {
                        $paging_nav .= " &sdot; " .
                                $cgi->a({-href => href(action=>"patches", -replay=>1)},
@@ -7551,7 +7554,8 @@ sub git_commit {
                        } @$parents ) .
                        ')';
        }
                        } @$parents ) .
                        ')';
        }
-       if (gitweb_check_feature('patches') && @$parents <= 1) {
+       if (gitweb_check_feature('patches') && @$parents <= 1 &&
+               !gitweb_check_feature('email-privacy')) {
                $formats_nav .= " | " .
                        $cgi->a({-href => href(action=>"patch", -replay=>1)},
                                "patch");
                $formats_nav .= " | " .
                        $cgi->a({-href => href(action=>"patch", -replay=>1)},
                                "patch");
@@ -7864,7 +7868,8 @@ sub git_commitdiff {
                $formats_nav =
                        $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},
                                "raw");
                $formats_nav =
                        $cgi->a({-href => href(action=>"commitdiff_plain", -replay=>1)},
                                "raw");
-               if ($patch_max && @{$co{'parents'}} <= 1) {
+               if ($patch_max && @{$co{'parents'}} <= 1 &&
+                       !gitweb_check_feature('email-privacy')) {
                        $formats_nav .= " | " .
                                $cgi->a({-href => href(action=>"patch", -replay=>1)},
                                        "patch");
                        $formats_nav .= " | " .
                                $cgi->a({-href => href(action=>"patch", -replay=>1)},
                                        "patch");
This page took 0.293045 seconds and 4 git commands to generate.