From: Junio C Hamano Date: Thu, 4 Dec 2008 06:03:09 +0000 (-0800) Subject: Merge branch 'jn/gitweb-utf8' X-Git-Tag: v1.6.1-rc2~11 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ad685681c22c921e3b1c8ec9504289b5cd8e699b?ds=inline;hp=-c Merge branch 'jn/gitweb-utf8' * jn/gitweb-utf8: gitweb: Fix handling of non-ASCII characters in inserted HTML files --- ad685681c22c921e3b1c8ec9504289b5cd8e699b diff --combined gitweb/gitweb.perl index 2738643950,b92134b1c0..95988fba4a --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@@ -190,9 -190,7 +190,9 @@@ our %feature = # if there is no 'sub' key (no feature-sub), then feature cannot be # overriden # - # use gitweb_check_feature() to check if is enabled + # use gitweb_get_feature() to retrieve the value + # (an array) or gitweb_check_feature() to check if + # is enabled # Enable the 'blame' blob view, showing the last commit that modified # each line in the file. This can be very CPU-intensive. @@@ -331,7 -329,7 +331,7 @@@ 'default' => [0]}, ); -sub gitweb_check_feature { +sub gitweb_get_feature { my ($name) = @_; return unless exists $feature{$name}; my ($sub, $override, @defaults) = ( @@@ -346,22 -344,6 +346,22 @@@ return $sub->(@defaults); } +# A wrapper to check if a given feature is enabled. +# With this, you can say +# +# my $bool_feat = gitweb_check_feature('bool_feat'); +# gitweb_check_feature('bool_feat') or somecode; +# +# instead of +# +# my ($bool_feat) = gitweb_get_feature('bool_feat'); +# (gitweb_get_feature('bool_feat'))[0] or somecode; +# +sub gitweb_check_feature { + return (gitweb_get_feature(@_))[0]; +} + + sub feature_blame { my ($val) = git_get_project_config('blame', '--bool'); @@@ -785,7 -767,7 +785,7 @@@ our $git_dir $git_dir = "$projectroot/$project" if $project; # list of supported snapshot formats -our @snapshot_fmts = gitweb_check_feature('snapshot'); +our @snapshot_fmts = gitweb_get_feature('snapshot'); @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); # dispatch @@@ -828,7 -810,7 +828,7 @@@ sub href (%) } } - my ($use_pathinfo) = gitweb_check_feature('pathinfo'); + my $use_pathinfo = gitweb_check_feature('pathinfo'); if ($use_pathinfo) { # try to put as many parameters as possible in PATH_INFO: # - project name @@@ -2119,7 -2101,7 +2119,7 @@@ sub git_get_projects_list $filter ||= ''; $filter =~ s/\.git$//; - my ($check_forks) = gitweb_check_feature('forks'); + my $check_forks = gitweb_check_feature('forks'); if (-d $projects_list) { # search in directory @@@ -2758,6 -2740,15 +2758,15 @@@ sub get_file_owner return to_utf8($owner); } + # assume that file exists + sub insert_file { + my $filename = shift; + + open my $fd, '<', $filename; + print map(to_utf8, <$fd>); + close $fd; + } + ## ...................................................................... ## mimetype related functions @@@ -2946,9 -2937,7 +2955,7 @@@ EO "\n"; if (-f $site_header) { - open (my $fd, $site_header); - print <$fd>; - close $fd; + insert_file($site_header); } print "
\n" . @@@ -2965,7 -2954,7 +2972,7 @@@ } print "
\n"; - my ($have_search) = gitweb_check_feature('search'); + my $have_search = gitweb_check_feature('search'); if (defined $project && $have_search) { if (!defined $searchtext) { $searchtext = ""; @@@ -2979,7 -2968,7 +2986,7 @@@ $search_hash = "HEAD"; } my $action = $my_uri; - my ($use_pathinfo) = gitweb_check_feature('pathinfo'); + my $use_pathinfo = gitweb_check_feature('pathinfo'); if ($use_pathinfo) { $action .= "/".esc_url($project); } @@@ -3035,9 -3024,7 +3042,7 @@@ sub git_footer_html print "\n"; # class="page_footer" if (-f $site_footer) { - open (my $fd, $site_footer); - print <$fd>; - close $fd; + insert_file($site_footer); } print "\n" . @@@ -3102,7 -3089,7 +3107,7 @@@ sub git_print_page_nav $arg{'tree'}{'hash'} = $treehead if defined $treehead; $arg{'tree'}{'hash_base'} = $treebase if defined $treebase; - my @actions = gitweb_check_feature('actions'); + my @actions = gitweb_get_feature('actions'); my %repl = ( '%' => '%', 'n' => $project, # project name @@@ -3472,7 -3459,7 +3477,7 @@@ sub is_patch_split sub git_difftree_body { my ($difftree, $hash, @parents) = @_; my ($parent) = $parents[0]; - my ($have_blame) = gitweb_check_feature('blame'); + my $have_blame = gitweb_check_feature('blame'); print "
\n"; if ($#{$difftree} > 10) { print(($#{$difftree} + 1) . " files changed:\n"); @@@ -3986,7 -3973,7 +3991,7 @@@ sub git_project_list_body # actually uses global variable $project my ($projlist, $order, $from, $to, $extra, $no_header) = @_; - my ($check_forks) = gitweb_check_feature('forks'); + my $check_forks = gitweb_check_feature('forks'); my @projects = fill_project_list_info($projlist, $check_forks); $order ||= $default_projects_order; @@@ -4376,9 -4363,7 +4381,7 @@@ sub git_project_list git_header_html(); if (-f $home_text) { print "
\n"; - open (my $fd, $home_text); - print <$fd>; - close $fd; + insert_file($home_text); print "
\n"; } print $cgi->startform(-method => "get") . @@@ -4446,7 -4431,7 +4449,7 @@@ sub git_summary my @taglist = git_get_tags_list(16); my @headlist = git_get_heads_list(16); my @forklist; - my ($check_forks) = gitweb_check_feature('forks'); + my $check_forks = gitweb_check_feature('forks'); if ($check_forks) { @forklist = git_get_projects_list($project); @@@ -4475,7 -4460,7 +4478,7 @@@ } # Tag cloud - my $show_ctags = (gitweb_check_feature('ctags'))[0]; + my $show_ctags = gitweb_check_feature('ctags'); if ($show_ctags) { my $ctags = git_get_project_ctags($project); my $cloud = git_populate_project_tagcloud($ctags); @@@ -4490,13 -4475,10 +4493,10 @@@ print "\n"; if (-s "$projectroot/$project/README.html") { - if (open my $fd, "$projectroot/$project/README.html") { - print "
readme
\n" . - "
\n"; - print $_ while (<$fd>); - print "\n
\n"; # class="readme" - close $fd; - } + print "
readme
\n" . + "
\n"; + insert_file("$projectroot/$project/README.html"); + print "\n
\n"; # class="readme" } # we need to request one more than 16 (0..15) to check if @@@ -4765,7 -4747,7 +4765,7 @@@ sub git_blob $expires = "+1d"; } - my ($have_blame) = gitweb_check_feature('blame'); + my $have_blame = gitweb_check_feature('blame'); open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash or die_error(500, "Couldn't cat $file_name, $hash"); my $mimetype = blob_mimetype($fd, $file_name); @@@ -4858,7 -4840,7 +4858,7 @@@ sub git_tree my $ref = format_ref_marker($refs, $hash_base); git_header_html(); my $basedir = ''; - my ($have_blame) = gitweb_check_feature('blame'); + my $have_blame = gitweb_check_feature('blame'); if (defined $hash_base && (my %co = parse_commit($hash_base))) { my @views_nav = (); if (defined $file_name) { @@@ -5856,7 -5838,7 +5856,7 @@@ insensitive).

commit
The commit messages and authorship information will be scanned for the given pattern.
EOT - my ($have_grep) = gitweb_check_feature('grep'); + my $have_grep = gitweb_check_feature('grep'); if ($have_grep) { print <grep @@@ -5873,7 -5855,7 +5873,7 @@@ EO
committer
Name and e-mail of the committer and date of commit will be scanned for the given pattern.
EOT - my ($have_pickaxe) = gitweb_check_feature('pickaxe'); + my $have_pickaxe = gitweb_check_feature('pickaxe'); if ($have_pickaxe) { print <pickaxe @@@ -5925,7 -5907,7 +5925,7 @@@ sub git_shortlog sub git_feed { my $format = shift || 'atom'; - my ($have_blame) = gitweb_check_feature('blame'); + my $have_blame = gitweb_check_feature('blame'); # Atom: http://www.atomenabled.org/developers/syndication/ # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ