]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.perl
gitweb/Makefile: add a $(GITWEB_ALL) variable
[Gitweb] / gitweb.perl
index d1264baed2992ddb9319d6069c55a45b208de60c92a8643ae919a529cb7af668..5d5401f5ace7bdaa6d0bf59c7c8e52dd41f4dc869179d0dea76183727fbec7e2 100755 (executable)
@@ -570,6 +570,15 @@ our %feature = (
                '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 {
@@ -742,7 +751,7 @@ sub evaluate_gitweb_config {
        $GITWEB_CONFIG_SYSTEM = "" if ($GITWEB_CONFIG_SYSTEM eq $GITWEB_CONFIG_COMMON);
 
        # Common system-wide settings for convenience.
-       # Those settings can be ovverriden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM.
+       # Those settings can be overridden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM.
        read_config_file($GITWEB_CONFIG_COMMON);
 
        # Use first config file that exists.  This means use the per-instance
@@ -1292,9 +1301,23 @@ our $is_last_request = sub { 1 };
 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
 our $CGI = 'CGI';
 our $cgi;
+our $FCGI_Stream_PRINT_raw = \&FCGI::Stream::PRINT;
 sub configure_as_fcgi {
        require CGI::Fast;
        our $CGI = 'CGI::Fast';
+       # FCGI is not Unicode aware hence the UTF-8 encoding must be done manually.
+       # However no encoding must be done within git_blob_plain() and git_snapshot()
+       # which must still output in raw binary mode.
+       no warnings 'redefine';
+       my $enc = Encode::find_encoding('UTF-8');
+       *FCGI::Stream::PRINT = sub {
+               my @OUTPUT = @_;
+               for (my $i = 1; $i < @_; $i++) {
+                       $OUTPUT[$i] = $enc->encode($_[$i], Encode::FB_CROAK|Encode::LEAVE_SRC);
+               }
+               @_ = @OUTPUT;
+               goto $FCGI_Stream_PRINT_raw;
+       };
 
        my $request_number = 0;
        # let each child service 100 requests
@@ -3436,6 +3459,13 @@ sub parse_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;
@@ -3452,7 +3482,7 @@ sub parse_tag {
                } 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/^([^<]+) <([^>]*)>/) {
@@ -3500,7 +3530,7 @@ sub parse_commit_text {
                } 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/^([^<]+) <([^>]*)>/) {
@@ -3510,7 +3540,7 @@ sub parse_commit_text {
                                $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/^([^<]+) <([^>]*)>/) {
@@ -3555,9 +3585,10 @@ sub parse_commit_text {
        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/^    //;
+               $line = hide_mailaddrs_if_private($line);
        }
        $co{'comment'} = \@commit_lines;
 
@@ -3766,7 +3797,8 @@ sub git_get_heads_list {
        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;
@@ -4182,19 +4214,20 @@ sub git_header_html {
        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"?>
-<!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>
-<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>
@@ -4628,7 +4661,7 @@ sub git_print_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;
@@ -5286,7 +5319,7 @@ sub format_ctx_rem_add_lines {
                #    + c
                #   +  d
                #
-               # Otherwise the highlightling would be confusing.
+               # Otherwise the highlighting would be confusing.
                if ($is_combined) {
                        for (my $i = 0; $i < @$add; $i++) {
                                my $prefix_rem = substr($rem->[$i], 0, $num_parents);
@@ -7080,6 +7113,7 @@ sub git_blob_plain {
                        ($sandbox ? 'attachment' : 'inline')
                        . '; filename="' . $save_as . '"');
        local $/ = undef;
+       local *FCGI::Stream::PRINT = $FCGI_Stream_PRINT_raw;
        binmode STDOUT, ':raw';
        print <$fd>;
        binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
@@ -7418,6 +7452,7 @@ sub git_snapshot {
 
        open my $fd, "-|", $cmd
                or die_error(500, "Execute git-archive failed");
+       local *FCGI::Stream::PRINT = $FCGI_Stream_PRINT_raw;
        binmode STDOUT, ':raw';
        print <$fd>;
        binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
@@ -7474,7 +7509,8 @@ sub git_log_generic {
                                 -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)},
@@ -7535,7 +7571,8 @@ sub git_commit {
                        } @$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");
@@ -7848,7 +7885,8 @@ sub git_commitdiff {
                $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");
This page took 0.307482 seconds and 4 git commands to generate.