From: Andrew Lorimer Date: Tue, 21 Jul 2020 08:50:49 +0000 (+1000) Subject: general improvements X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/43abf1397ac0fd8b39a75a3159635af5f8dabf45?ds=sidebyside general improvements --- diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 49ed13b9de..6ddde75dee 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -14,10 +14,12 @@ use warnings; # handle ACL in file access tests use filetest 'access'; +use HTML::Entities; +use Pandoc; use CGI qw(:standard :escapeHTML -nosticky); use CGI::Util qw(unescape); -#use CGI::Carp qw(fatalsToBrowser set_message); -use CGI::Carp qw(set_message); +#use CGI::Carp qw(fatalsToBrowser set_message); # debugging only +use CGI::Carp qw(set_message); # production use Encode; use Fcntl ':mode'; use File::Find qw(); @@ -85,6 +87,9 @@ sub evaluate_uri { # this can just be "git" if your webserver has a sensible PATH our $GIT = "++GIT_BINDIR++/git"; +# executable path to Pandoc executable for rendering readme files etc +our $PANDOC = "pandoc"; + # absolute fs-path which will be prepended to the project path #our $projectroot = "/pub/scm"; our $projectroot = "++GITWEB_PROJECTROOT++"; @@ -608,6 +613,37 @@ sub evaluate_uri { 'sub' => \&feature_extra_branch_refs, 'override' => 0, 'default' => []}, + + # Enable or disable RSS feed + # Added by Andrew Lorimer, October 2019 + + 'rss' => { + 'sub' => \&feature_bool, + 'override' => 0, + 'default' => [1]}, + + # Enable or disable Atom feed + # Added by Andrew Lorimer, October 2019 + + 'atom' => { + 'sub' => \&feature_bool, + 'override' => 0, + 'default' => [1]}, + + + # Enable or disable the shortlog view + # Added by Andrew Lorimer, November 2019 + 'shortlog' => { + 'sub' => \&feature_bool, + 'override' => 0, + 'default' => [1]}, + + # Show author name for every commit in main commit list + # Added by Andrew Lorimer, January 2020 + 'summary_omit_author' => { + 'sub' => \&feature_bool, + 'override' => 0, + 'default' => [1]}, ); sub gitweb_get_feature { @@ -1488,7 +1524,7 @@ sub href { } $href .= esc_path_info($params{'hash_base'}); - if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) { + if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) { $href .= ":/".esc_path_info($params{'file_name'}); delete $params{'file_name'}; } @@ -2110,7 +2146,7 @@ sub format_log_line_html { # Potentially abbreviated OID. my $regex = oid_nlen_regex("7,64"); - $line = esc_html($line, -nbsp=>1); + $line = esc_html($line); $line =~ s{ \b ( @@ -2309,6 +2345,7 @@ sub format_search_author { # the author name is chopped and escaped according to the other # optional parameters (see chop_str). sub format_author_html { + if (not gitweb_check_feature('summary_omit_author')) { my $tag = shift; my $co = shift; my $author = chop_and_escape_str($co->{'author_name'}, @_); @@ -2317,6 +2354,9 @@ sub format_author_html { git_get_avatar($co->{'author_email'}, -pad_after => 1) . $author) . ""; + } else { + return ""; + } } # format git diff header line, i.e. "diff --(git|combined|cc) ..." @@ -3586,7 +3626,6 @@ sub parse_commit_text { foreach my $title (@commit_lines) { $title =~ s/^ //; if ($title ne "") { - #$co{'title'} = chop_str($title, 80, 5); $co{'title'} = $title; # remove leading stuff of merges to make the interesting part visible if (length($title) > 50) { @@ -3605,8 +3644,7 @@ sub parse_commit_text { $title =~ s/\/pub\/scm//; } } - #$co{'title_short'} = chop_str($title, 50, 5); - $co{'title_short'} = $title; + $co{'title_short'} = chop_str($title, 50, 5); last; } } @@ -3615,7 +3653,8 @@ sub parse_commit_text { } # remove added spaces foreach my $line (@commit_lines) { - $line =~ s/^ //; + $line =~ s/\s\s+//; + $line =~ s/\n+$//; } $co{'comment'} = \@commit_lines; @@ -3937,6 +3976,13 @@ sub insert_file { close $fd; } +# Check if a file should be displayed +sub check_tree_filter { + my $filename = shift; + my @treefilter_pattern = gitweb_get_feature('tree_filter'); + return $filename =~ /$treefilter_pattern[0]/; +} + ## ...................................................................... ## mimetype related functions @@ -4097,33 +4143,10 @@ sub print_feed_meta { $href_params{'-title'} = 'log'; } - foreach my $format (qw(RSS Atom)) { - my $type = lc($format); - my %link_attr = ( - '-rel' => 'alternate', - '-title' => esc_attr("$project - $href_params{'-title'} - $format feed"), - '-type' => "application/$type+xml" - ); - - $href_params{'extra_options'} = undef; - $href_params{'action'} = $type; - $link_attr{'-href'} = href(%href_params); - print "\n"; - - $href_params{'extra_options'} = '--no-merges'; - $link_attr{'-href'} = href(%href_params); - $link_attr{'-title'} .= ' (no merges)'; - print "\n"; + foreach my $format (qw("RSS Atom")) { + if (gitweb_check_feature($format)) { + print_feed_links($format, %href_params); + } } } else { @@ -4136,6 +4159,39 @@ sub print_feed_meta { } } +sub print_feed_links { + + my ($format, %href_params) = @_; + + my $type = lc($format); + my %link_attr = ( + '-rel' => 'alternate', + '-title' => esc_attr("$project - $href_params{'-title'} - $format feed"), + '-type' => "application/$type+xml" + ); + + $href_params{'extra_options'} = undef; + $href_params{'action'} = $type; + $link_attr{'-href'} = href(%href_params); + print "\n"; + + $href_params{'extra_options'} = '--no-merges'; + $link_attr{'-href'} = href(%href_params); + $link_attr{'-title'} .= ' (no merges)'; + print "\n"; + +} + sub print_header_links { my $status = shift; @@ -4193,8 +4249,11 @@ sub print_nav_breadcrumbs { my $projectbasename = pop @dirname; print_nav_breadcrumbs_path(@dirname); print $cgi->a({-href => href(action=>"summary")}, esc_html($projectbasename)); - if (defined $action) { + if (defined $action && $action ne "summary") { $action =~ s/_/ /; + if ($action eq "blob") { + $action = $file_name; + } my $action_print = $action ; if (defined $opts{-action_extra}) { $action_print = $cgi->a({-href => href(action=>$action)}, @@ -4335,11 +4394,17 @@ sub git_footer_html { } $href_params{'-title'} ||= 'log'; - foreach my $format (qw(RSS Atom)) { - $href_params{'action'} = lc($format); + if (gitweb_check_feature("rss")) { + $href_params{'action'} = "rss"; + print $cgi->a({-href => href(%href_params), + -title => "$href_params{'-title'} RSS feed", + -class => $feed_class}, "RSS")."\n"; + } + if (gitweb_check_feature("atom")) { + $href_params{'action'} = "atom"; print $cgi->a({-href => href(%href_params), - -title => "$href_params{'-title'} $format feed", - -class => $feed_class}, $format)."\n"; + -title => "$href_params{'-title'} Atom feed", + -class => $feed_class}, "Atom")."\n"; } } else { @@ -4453,7 +4518,12 @@ sub git_print_page_nav { my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_; $extra = '' if !defined $extra; # pager or formats - my @navs = qw(summary shortlog log commit diff tree); + # Check if shortlog should be added to breadcrumb + # Added by Andrew Lorimer, November 2019 + my @navs = qw(summary log commit diff tree); + if (gitweb_check_feature("shortlog")) { + @navs = qw(summary shortlog log commit diff tree); + } if ($suppress) { @navs = grep { $_ ne $suppress } @navs; } @@ -4636,11 +4706,13 @@ sub git_print_authorship { my $author = $co->{'author_name'}; my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); - print "<$tag class=\"author_date\">" . - format_search_author($author, "author", esc_html($author)) . - " [".format_timestamp_html(\%ad)."]". - git_get_avatar($co->{'author_email'}, -pad_before => 1) . - "\n"; + print("<$tag class=\"author\">"); + print(git_get_avatar($co->{'author_email'}, -pad_before => 1)); + print(format_search_author($author, "author", esc_html($author))); + print("\n"); + print("<$tag class=\"age\">"); + print(format_timestamp_html(\%ad)); + print("\n"); } # Outputs table rows containing the full author or committer information, @@ -4761,6 +4833,8 @@ sub git_path_header { return $output; } + +# Print the log output for a single commit sub git_print_log { my $log = shift; my %opts = @_; @@ -6057,7 +6131,9 @@ sub git_log_body { # uses global variable $project my ($commitlist, $from, $to, $refs, $extra) = @_; - $from = 0 unless defined $from; + if (not defined $from) { + my $from = 0; + } $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to); for (my $i = 0; $i <= $to; $i++) { @@ -6065,23 +6141,28 @@ sub git_log_body { next if !%co; my $commit = $co{'id'}; my $ref = format_ref_marker($refs, $commit); - git_print_header_div('commit', - "$co{'age_string'}" . - esc_html($co{'title'}), $ref, - $commit); - print "
\n" . - "
\n" . + + print("
\n"); + print "
\n" . $cgi->a({-href => href(action=>"diff", hash=>$commit)}, "diff") . " | " . $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") . "
\n" . "
\n"; - git_print_authorship(\%co, -tag => 'span'); - print "
\n
\n"; - - print "
\n"; - git_print_log($co{'comment'}, -final_empty_line=> 1); - print "
\n"; + print(""); + print format_subject_html($co{'title'}, $co{'title_short'}, + href(action=>"commit", hash=>$commit), $ref); + print(""); + git_print_authorship(\%co, -tag => 'span'); + print("

"); + git_print_log($co{'comment'}, -final_empty_line=>1); + print("

"); + # print "
\n
\n"; + + #print "
\n"; + #git_print_log($co{'comment'}, -final_empty_line=> 1); + #print "
\n"; + print("
"); } if ($extra) { print "