* [PATCH] gitweb: support perl 5.6
@ 2006-09-09 10:46 Sven Verdoolaege
2006-09-09 12:19 ` Jakub Narebski
0 siblings, 1 reply; 5+ messages in thread
From: Sven Verdoolaege @ 2006-09-09 10:46 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
Specifically, perl 5.6 doesn't have the Encode module and
doesn't support the open "-|" list form.
Signed-off-by: Sven Verdoolage <skimo@liacs.nl>
---
gitweb/gitweb.perl | 115 +++++++++++++++++++++++++++++++++-------------------
1 files changed, 74 insertions(+), 41 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index d89f709..c1ee15e 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -12,11 +12,12 @@ use warnings;
use CGI qw(:standard :escapeHTML -nosticky);
use CGI::Util qw(unescape);
use CGI::Carp qw(fatalsToBrowser);
-use Encode;
+eval { require Encode; import Encode; };
+our $have_encode = !$@;
use Fcntl ':mode';
use File::Find qw();
use File::Basename qw(basename);
-binmode STDOUT, ':utf8';
+binmode STDOUT, ':utf8' if $have_encode;
our $cgi = new CGI;
our $version = "++GIT_VERSION++";
@@ -347,10 +348,16 @@ sub esc_param {
return $str;
}
+sub utf8_decode {
+ my $str = shift;
+ $str = decode("utf8", $str, eval "Encode::FB_DEFAULT") if $have_encode;
+ return $str;
+}
+
# replace invalid utf8 character with SUBSTITUTION sequence
sub esc_html {
my $str = shift;
- $str = decode("utf8", $str, Encode::FB_DEFAULT);
+ $str = utf8_decode($str);
$str = escapeHTML($str);
$str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
return $str;
@@ -593,7 +600,8 @@ sub git_get_head_hash {
my $o_git_dir = $git_dir;
my $retval = undef;
$git_dir = "$projectroot/$project";
- if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
+ my $git_command = git_cmd_str();
+ if (open my $fd, "-|", "$git_command rev-parse --verify HEAD") {
my $head = <$fd>;
close $fd;
if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
@@ -610,7 +618,8 @@ # get type of given object
sub git_get_type {
my $hash = shift;
- open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command cat-file -t $hash" or return;
my $type = <$fd>;
close $fd or return;
chomp $type;
@@ -640,7 +649,8 @@ sub git_get_hash_by_path {
my $tree = $base;
- open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command ls-tree $base -- $path"
or die_error(undef, "Open git-ls-tree failed");
my $line = <$fd>;
close $fd or return undef;
@@ -719,7 +729,7 @@ sub git_get_projects_list {
if (-e "$projectroot/$path/HEAD") {
my $pr = {
path => $path,
- owner => decode("utf8", $owner, Encode::FB_DEFAULT),
+ owner => utf8_decode($owner),
};
push @list, $pr
}
@@ -748,7 +758,7 @@ sub git_get_project_owner {
$pr = unescape($pr);
$ow = unescape($ow);
if ($pr eq $project) {
- $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
+ $owner = utf8_decode($ow);
last;
}
}
@@ -771,7 +781,8 @@ sub git_get_references {
open $fd, "$projectroot/$project/info/refs"
or return;
} else {
- open $fd, "-|", git_cmd(), "ls-remote", "."
+ my $git_command = git_cmd_str();
+ open $fd, "-|", "$git_command ls-remote ."
or return;
}
@@ -792,7 +803,8 @@ sub git_get_references {
sub git_get_rev_name_tags {
my $hash = shift || return undef;
- open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command name-rev --tags $hash"
or return;
my $name_rev = <$fd>;
close $fd;
@@ -840,7 +852,8 @@ sub parse_tag {
my %tag;
my @comment;
- open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command cat-file tag $tag_id" or return;
$tag{'id'} = $tag_id;
while (my $line = <$fd>) {
chomp $line;
@@ -881,7 +894,8 @@ sub parse_commit {
@commit_lines = @$commit_text;
} else {
$/ = "\0";
- open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command rev-list --header --parents --max-count=1 $commit_id"
or return;
@commit_lines = split '\n', <$fd>;
close $fd or return;
@@ -1098,7 +1112,7 @@ sub get_file_owner {
}
my $owner = $gcos;
$owner =~ s/[,;].*$//;
- return decode("utf8", $owner, Encode::FB_DEFAULT);
+ return utf8_decode($owner);
}
## ......................................................................
@@ -2206,8 +2220,9 @@ sub git_summary {
}
print "</table>\n";
- open my $fd, "-|", git_cmd(), "rev-list", "--max-count=17",
- git_get_head_hash($project)
+ my $git_command = git_cmd_str();
+ my $head = git_get_head_hash($project);
+ open my $fd, "-|", "$git_command rev-list --max-count=17 $head",
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd;
@@ -2286,7 +2301,8 @@ sub git_blame2 {
if ($ftype !~ "blob") {
die_error("400 Bad Request", "Object is not a blob");
}
- open ($fd, "-|", git_cmd(), "blame", '-l', $file_name, $hash_base)
+ my $git_command = git_cmd_str();
+ open ($fd, "-|", "$git_command blame -l $file_name $hash_base")
or die_error(undef, "Open git-blame failed");
git_header_html();
my $formats_nav =
@@ -2352,7 +2368,8 @@ sub git_blame {
$hash = git_get_hash_by_path($hash_base, $file_name, "blob")
or die_error(undef, "Error lookup file");
}
- open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
+ my $git_command = git_cmd_str();
+ open ($fd, "-|", "$git_command annotate -l -t -r $file_name $hash_base")
or die_error(undef, "Open git-annotate failed");
git_header_html();
my $formats_nav =
@@ -2473,7 +2490,8 @@ sub git_blob_plain {
}
}
my $type = shift;
- open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command cat-file blob $hash"
or die_error(undef, "Couldn't cat $file_name, $hash");
$type ||= blob_mimetype($fd, $file_name);
@@ -2515,7 +2533,8 @@ sub git_blob {
}
}
my ($have_blame) = gitweb_check_feature('blame');
- open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command cat-file blob $hash"
or die_error(undef, "Couldn't cat $file_name, $hash");
my $mimetype = blob_mimetype($fd, $file_name);
if ($mimetype !~ m/^text\//) {
@@ -2580,7 +2599,8 @@ sub git_tree {
}
}
$/ = "\0";
- open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command ls-tree -z $hash"
or die_error(undef, "Open git-ls-tree failed");
my @entries = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading tree failed");
@@ -2666,7 +2686,8 @@ sub git_log {
my $refs = git_get_references();
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command rev-list $limit $hash"
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd;
@@ -2721,7 +2742,8 @@ sub git_commit {
if (!defined $parent) {
$parent = "--root";
}
- open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $parent, $hash
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command diff-tree -r @diff_opts $parent $hash"
or die_error(undef, "Open git-diff-tree failed");
my @difftree = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading git-diff-tree failed");
@@ -2828,8 +2850,8 @@ sub git_blobdiff {
if (defined $hash_base && defined $hash_parent_base) {
if (defined $file_name) {
# read raw output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
- "--", $file_name
+ my $git_command = git_cmd_str();
+ open $fd, "-|", "$git_command diff-tree -r @diff_opts $hash_parent_base $hash_base -- $file_name"
or die_error(undef, "Open git-diff-tree failed");
@difftree = map { chomp; $_ } <$fd>;
close $fd
@@ -2842,7 +2864,8 @@ sub git_blobdiff {
# try to find filename from $hash
# read filtered raw output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
+ my $git_command = git_cmd_str();
+ open $fd, "-|", "$git_command diff-tree -r @diff_opts $hash_parent_base $hash_base"
or die_error(undef, "Open git-diff-tree failed");
@difftree =
# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
@@ -2876,9 +2899,10 @@ sub git_blobdiff {
}
# open patch output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- '-p', $hash_parent_base, $hash_base,
- "--", $file_name
+ my $git_command = git_cmd_str();
+ open $fd, "-|", "$git_command diff-tree -r @diff_opts ".
+ "-p $hash_parent_base $hash_base ".
+ "-- $file_name"
or die_error(undef, "Open git-diff-tree failed");
}
@@ -2912,7 +2936,8 @@ sub git_blobdiff {
}
# open patch output
- open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts, $hash_parent, $hash
+ my $git_command = git_cmd_str();
+ open $fd, "-|", "$git_command diff -p @diff_opts $hash_parent $hash"
or die_error(undef, "Open git-diff failed");
} else {
die_error('404 Not Found', "Missing one of the blob diff parameters")
@@ -2997,8 +3022,9 @@ sub git_commitdiff {
my $fd;
my @difftree;
if ($format eq 'html') {
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- "--patch-with-raw", "--full-index", $hash_parent, $hash
+ my $git_command = git_cmd_str();
+ open $fd, "-|", "$git_command diff-tree -r @diff_opts ".
+ "--patch-with-raw --full-index $hash_parent $hash"
or die_error(undef, "Open git-diff-tree failed");
while (chomp(my $line = <$fd>)) {
@@ -3008,8 +3034,9 @@ sub git_commitdiff {
}
} elsif ($format eq 'plain') {
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- '-p', $hash_parent, $hash
+ my $git_command = git_cmd_str();
+ open $fd, "-|", "$git_command diff-tree -r @diff_opts ".
+ "-p $hash_parent $hash"
or die_error(undef, "Open git-diff-tree failed");
} else {
@@ -3108,8 +3135,9 @@ sub git_history {
}
git_print_page_path($file_name, $ftype, $hash_base);
+ my $git_command = git_cmd_str();
open my $fd, "-|",
- git_cmd(), "rev-list", "--full-history", $hash_base, "--", $file_name;
+ "$git_command rev-list --full-history $hash_base -- $file_name";
git_history_body($fd, $refs, $hash_base, $ftype);
@@ -3150,7 +3178,8 @@ sub git_search {
my $alternate = 0;
if ($commit_search) {
$/ = "\0";
- open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command rev-list --header --parents $hash" or next;
while (my $commit_text = <$fd>) {
if (!grep m/$searchtext/i, $commit_text) {
next;
@@ -3271,7 +3300,8 @@ sub git_shortlog {
my $refs = git_get_references();
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
+ my $git_command = git_cmd_str();
+ open my $fd, "-|", "$git_command rev-list $limit $hash"
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd;
@@ -3299,7 +3329,9 @@ ## feeds (RSS, OPML)
sub git_rss {
# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
- open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150", git_get_head_hash($project)
+ my $git_command = git_cmd_str();
+ my $head = git_get_head_hash($project);
+ open my $fd, "-|", "$git_command rev-list --max-count=150 $head"
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading git-rev-list failed");
@@ -3322,8 +3354,9 @@ XML
last;
}
my %cd = parse_date($co{'committer_epoch'});
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- $co{'parent'}, $co{'id'}
+ my $git_command = git_cmd_str();
+ open $fd, "-|", "$git_command diff-tree -r @diff_opts ".
+ "$co{'parent'} $co{'id'}"
or next;
my @difftree = map { chomp; $_ } <$fd>;
close $fd
@@ -3341,7 +3374,7 @@ XML
"<![CDATA[\n";
my $comment = $co{'comment'};
foreach my $line (@$comment) {
- $line = decode("utf8", $line, Encode::FB_DEFAULT);
+ $line = utf8_decode($line);
print "$line<br/>\n";
}
print "<br/>\n";
@@ -3350,7 +3383,7 @@ XML
next;
}
my $file = validate_input(unquote($7));
- $file = decode("utf8", $file, Encode::FB_DEFAULT);
+ $file = utf8_decode($file);
print "$file<br/>\n";
}
print "]]>\n" .
--
0.99.8c.g64e8-dirty
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH] gitweb: support perl 5.6
@ 2006-09-09 14:42 Sven Verdoolaege
0 siblings, 0 replies; 5+ messages in thread
From: Sven Verdoolaege @ 2006-09-09 14:42 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
Specifically, perl 5.6 doesn't have the Encode module and
doesn't support the open "-|" list form.
Signed-off-by: Sven Verdoolage <skimo@liacs.nl>
---
This is take two, hopefully addressing Jakub's remark.
gitweb/gitweb.perl | 94 +++++++++++++++++++++++++++++-----------------------
1 files changed, 53 insertions(+), 41 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index d89f709..9992046 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -12,11 +12,12 @@ use warnings;
use CGI qw(:standard :escapeHTML -nosticky);
use CGI::Util qw(unescape);
use CGI::Carp qw(fatalsToBrowser);
-use Encode;
+eval { require Encode; import Encode; };
+our $have_encode = !$@;
use Fcntl ':mode';
use File::Find qw();
use File::Basename qw(basename);
-binmode STDOUT, ':utf8';
+binmode STDOUT, ':utf8' if $have_encode;
our $cgi = new CGI;
our $version = "++GIT_VERSION++";
@@ -347,10 +348,16 @@ sub esc_param {
return $str;
}
+sub utf8_decode {
+ my $str = shift;
+ $str = decode("utf8", $str, eval "Encode::FB_DEFAULT") if $have_encode;
+ return $str;
+}
+
# replace invalid utf8 character with SUBSTITUTION sequence
sub esc_html {
my $str = shift;
- $str = decode("utf8", $str, Encode::FB_DEFAULT);
+ $str = utf8_decode($str);
$str = escapeHTML($str);
$str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
return $str;
@@ -582,6 +589,12 @@ sub git_cmd {
return $GIT, '--git-dir='.$git_dir;
}
+# returns pipe reading from git command with given arguments
+sub git_pipe {
+ open my $fd, "-|", join(' ', git_cmd(), @_) or return undef;
+ return $fd;
+}
+
# returns path to the core git executable and the --git-dir parameter as string
sub git_cmd_str {
return join(' ', git_cmd());
@@ -593,7 +606,7 @@ sub git_get_head_hash {
my $o_git_dir = $git_dir;
my $retval = undef;
$git_dir = "$projectroot/$project";
- if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
+ if (my $fd = git_pipe("rev-parse", "--verify", "HEAD")) {
my $head = <$fd>;
close $fd;
if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
@@ -610,7 +623,7 @@ # get type of given object
sub git_get_type {
my $hash = shift;
- open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
+ my $fd = git_pipe("cat-file", '-t', $hash) or return;
my $type = <$fd>;
close $fd or return;
chomp $type;
@@ -640,7 +653,7 @@ sub git_get_hash_by_path {
my $tree = $base;
- open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
+ my $fd = git_pipe("ls-tree", $base, "--", $path)
or die_error(undef, "Open git-ls-tree failed");
my $line = <$fd>;
close $fd or return undef;
@@ -719,7 +732,7 @@ sub git_get_projects_list {
if (-e "$projectroot/$path/HEAD") {
my $pr = {
path => $path,
- owner => decode("utf8", $owner, Encode::FB_DEFAULT),
+ owner => utf8_decode($owner),
};
push @list, $pr
}
@@ -748,7 +761,7 @@ sub git_get_project_owner {
$pr = unescape($pr);
$ow = unescape($ow);
if ($pr eq $project) {
- $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
+ $owner = utf8_decode($ow);
last;
}
}
@@ -771,7 +784,7 @@ sub git_get_references {
open $fd, "$projectroot/$project/info/refs"
or return;
} else {
- open $fd, "-|", git_cmd(), "ls-remote", "."
+ $fd = git_pipe("ls-remote", ".")
or return;
}
@@ -792,7 +805,7 @@ sub git_get_references {
sub git_get_rev_name_tags {
my $hash = shift || return undef;
- open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
+ my $fd = git_pipe("name-rev", "--tags", $hash)
or return;
my $name_rev = <$fd>;
close $fd;
@@ -840,7 +853,7 @@ sub parse_tag {
my %tag;
my @comment;
- open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
+ my $fd = git_pipe("cat-file", "tag", $tag_id) or return;
$tag{'id'} = $tag_id;
while (my $line = <$fd>) {
chomp $line;
@@ -881,7 +894,7 @@ sub parse_commit {
@commit_lines = @$commit_text;
} else {
$/ = "\0";
- open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
+ my $fd = git_pipe("rev-list", "--header", "--parents", "--max-count=1", $commit_id)
or return;
@commit_lines = split '\n', <$fd>;
close $fd or return;
@@ -1098,7 +1111,7 @@ sub get_file_owner {
}
my $owner = $gcos;
$owner =~ s/[,;].*$//;
- return decode("utf8", $owner, Encode::FB_DEFAULT);
+ return utf8_decode($owner);
}
## ......................................................................
@@ -2206,8 +2219,8 @@ sub git_summary {
}
print "</table>\n";
- open my $fd, "-|", git_cmd(), "rev-list", "--max-count=17",
- git_get_head_hash($project)
+ my $fd = git_pipe("rev-list", "--max-count=17",
+ git_get_head_hash($project))
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd;
@@ -2286,7 +2299,7 @@ sub git_blame2 {
if ($ftype !~ "blob") {
die_error("400 Bad Request", "Object is not a blob");
}
- open ($fd, "-|", git_cmd(), "blame", '-l', $file_name, $hash_base)
+ $fd = git_pipe("blame", '-l', $file_name, $hash_base)
or die_error(undef, "Open git-blame failed");
git_header_html();
my $formats_nav =
@@ -2352,7 +2365,7 @@ sub git_blame {
$hash = git_get_hash_by_path($hash_base, $file_name, "blob")
or die_error(undef, "Error lookup file");
}
- open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
+ $fd = git_pipe("annotate", '-l', '-t', '-r', $file_name, $hash_base)
or die_error(undef, "Open git-annotate failed");
git_header_html();
my $formats_nav =
@@ -2473,7 +2486,7 @@ sub git_blob_plain {
}
}
my $type = shift;
- open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
+ my $fd = git_pipe("cat-file", "blob", $hash)
or die_error(undef, "Couldn't cat $file_name, $hash");
$type ||= blob_mimetype($fd, $file_name);
@@ -2515,7 +2528,7 @@ sub git_blob {
}
}
my ($have_blame) = gitweb_check_feature('blame');
- open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
+ my $fd =git_pipe("cat-file", "blob", $hash)
or die_error(undef, "Couldn't cat $file_name, $hash");
my $mimetype = blob_mimetype($fd, $file_name);
if ($mimetype !~ m/^text\//) {
@@ -2580,7 +2593,7 @@ sub git_tree {
}
}
$/ = "\0";
- open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
+ my $fd = git_pipe("ls-tree", '-z', $hash)
or die_error(undef, "Open git-ls-tree failed");
my @entries = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading tree failed");
@@ -2666,7 +2679,7 @@ sub git_log {
my $refs = git_get_references();
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
+ my $fd = git_pipe("rev-list", $limit, $hash)
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd;
@@ -2721,7 +2734,7 @@ sub git_commit {
if (!defined $parent) {
$parent = "--root";
}
- open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $parent, $hash
+ my $fd = git_pipe("diff-tree", '-r', @diff_opts, $parent, $hash)
or die_error(undef, "Open git-diff-tree failed");
my @difftree = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading git-diff-tree failed");
@@ -2828,8 +2841,8 @@ sub git_blobdiff {
if (defined $hash_base && defined $hash_parent_base) {
if (defined $file_name) {
# read raw output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
- "--", $file_name
+ $fd = git_pipe("diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
+ "--", $file_name)
or die_error(undef, "Open git-diff-tree failed");
@difftree = map { chomp; $_ } <$fd>;
close $fd
@@ -2842,7 +2855,7 @@ sub git_blobdiff {
# try to find filename from $hash
# read filtered raw output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
+ $fd = git_pipe("diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base)
or die_error(undef, "Open git-diff-tree failed");
@difftree =
# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
@@ -2876,9 +2889,9 @@ sub git_blobdiff {
}
# open patch output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
+ $fd = git_pipe("diff-tree", '-r', @diff_opts,
'-p', $hash_parent_base, $hash_base,
- "--", $file_name
+ "--", $file_name)
or die_error(undef, "Open git-diff-tree failed");
}
@@ -2912,7 +2925,7 @@ sub git_blobdiff {
}
# open patch output
- open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts, $hash_parent, $hash
+ $fd = git_pipe("diff", '-p', @diff_opts, $hash_parent, $hash)
or die_error(undef, "Open git-diff failed");
} else {
die_error('404 Not Found', "Missing one of the blob diff parameters")
@@ -2997,8 +3010,8 @@ sub git_commitdiff {
my $fd;
my @difftree;
if ($format eq 'html') {
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- "--patch-with-raw", "--full-index", $hash_parent, $hash
+ $fd = git_pipe("diff-tree", '-r', @diff_opts,
+ "--patch-with-raw", "--full-index", $hash_parent, $hash)
or die_error(undef, "Open git-diff-tree failed");
while (chomp(my $line = <$fd>)) {
@@ -3008,8 +3021,8 @@ sub git_commitdiff {
}
} elsif ($format eq 'plain') {
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- '-p', $hash_parent, $hash
+ $fd = git_pipe("diff-tree", '-r', @diff_opts,
+ '-p', $hash_parent, $hash)
or die_error(undef, "Open git-diff-tree failed");
} else {
@@ -3108,8 +3121,7 @@ sub git_history {
}
git_print_page_path($file_name, $ftype, $hash_base);
- open my $fd, "-|",
- git_cmd(), "rev-list", "--full-history", $hash_base, "--", $file_name;
+ my $fd = git_pipe("rev-list", "--full-history", $hash_base, "--", $file_name);
git_history_body($fd, $refs, $hash_base, $ftype);
@@ -3150,7 +3162,7 @@ sub git_search {
my $alternate = 0;
if ($commit_search) {
$/ = "\0";
- open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
+ my $fd = git_pipe("rev-list", "--header", "--parents", $hash or next);
while (my $commit_text = <$fd>) {
if (!grep m/$searchtext/i, $commit_text) {
next;
@@ -3271,7 +3283,7 @@ sub git_shortlog {
my $refs = git_get_references();
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
+ my $fd = git_pipe("rev-list", $limit, $hash)
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd;
@@ -3299,7 +3311,7 @@ ## feeds (RSS, OPML)
sub git_rss {
# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
- open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150", git_get_head_hash($project)
+ my $fd = git_pipe("rev-list", "--max-count=150", git_get_head_hash($project))
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading git-rev-list failed");
@@ -3322,8 +3334,8 @@ XML
last;
}
my %cd = parse_date($co{'committer_epoch'});
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- $co{'parent'}, $co{'id'}
+ $fd = git_pipe("diff-tree", '-r', @diff_opts,
+ $co{'parent'}, $co{'id'})
or next;
my @difftree = map { chomp; $_ } <$fd>;
close $fd
@@ -3341,7 +3353,7 @@ XML
"<![CDATA[\n";
my $comment = $co{'comment'};
foreach my $line (@$comment) {
- $line = decode("utf8", $line, Encode::FB_DEFAULT);
+ $line = utf8_decode($line);
print "$line<br/>\n";
}
print "<br/>\n";
@@ -3350,7 +3362,7 @@ XML
next;
}
my $file = validate_input(unquote($7));
- $file = decode("utf8", $file, Encode::FB_DEFAULT);
+ $file = utf8_decode($file);
print "$file<br/>\n";
}
print "]]>\n" .
--
0.99.8c.g64e8-dirty
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH] gitweb: support perl 5.6
@ 2006-09-09 14:59 Sven Verdoolaege
2006-09-09 22:20 ` Jakub Narebski
0 siblings, 1 reply; 5+ messages in thread
From: Sven Verdoolaege @ 2006-09-09 14:59 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
Specifically, perl 5.6 doesn't have the Encode module and
doesn't support the open "-|" list form.
Signed-off-by: Sven Verdoolage <skimo@liacs.nl>
---
This is take three.
I had missed the other binmodes in the code.
gitweb/gitweb.perl | 102 +++++++++++++++++++++++++++++-----------------------
1 files changed, 57 insertions(+), 45 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index d89f709..7afdf33 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -12,11 +12,12 @@ use warnings;
use CGI qw(:standard :escapeHTML -nosticky);
use CGI::Util qw(unescape);
use CGI::Carp qw(fatalsToBrowser);
-use Encode;
+eval { require Encode; import Encode; };
+our $have_encode = !$@;
use Fcntl ':mode';
use File::Find qw();
use File::Basename qw(basename);
-binmode STDOUT, ':utf8';
+binmode STDOUT, ':utf8' if $have_encode;
our $cgi = new CGI;
our $version = "++GIT_VERSION++";
@@ -347,10 +348,16 @@ sub esc_param {
return $str;
}
+sub utf8_decode {
+ my $str = shift;
+ $str = decode("utf8", $str, eval "Encode::FB_DEFAULT") if $have_encode;
+ return $str;
+}
+
# replace invalid utf8 character with SUBSTITUTION sequence
sub esc_html {
my $str = shift;
- $str = decode("utf8", $str, Encode::FB_DEFAULT);
+ $str = utf8_decode($str);
$str = escapeHTML($str);
$str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
return $str;
@@ -582,6 +589,12 @@ sub git_cmd {
return $GIT, '--git-dir='.$git_dir;
}
+# returns pipe reading from git command with given arguments
+sub git_pipe {
+ open my $fd, "-|", join(' ', git_cmd(), @_) or return undef;
+ return $fd;
+}
+
# returns path to the core git executable and the --git-dir parameter as string
sub git_cmd_str {
return join(' ', git_cmd());
@@ -593,7 +606,7 @@ sub git_get_head_hash {
my $o_git_dir = $git_dir;
my $retval = undef;
$git_dir = "$projectroot/$project";
- if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
+ if (my $fd = git_pipe("rev-parse", "--verify", "HEAD")) {
my $head = <$fd>;
close $fd;
if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
@@ -610,7 +623,7 @@ # get type of given object
sub git_get_type {
my $hash = shift;
- open my $fd, "-|", git_cmd(), "cat-file", '-t', $hash or return;
+ my $fd = git_pipe("cat-file", '-t', $hash) or return;
my $type = <$fd>;
close $fd or return;
chomp $type;
@@ -640,7 +653,7 @@ sub git_get_hash_by_path {
my $tree = $base;
- open my $fd, "-|", git_cmd(), "ls-tree", $base, "--", $path
+ my $fd = git_pipe("ls-tree", $base, "--", $path)
or die_error(undef, "Open git-ls-tree failed");
my $line = <$fd>;
close $fd or return undef;
@@ -719,7 +732,7 @@ sub git_get_projects_list {
if (-e "$projectroot/$path/HEAD") {
my $pr = {
path => $path,
- owner => decode("utf8", $owner, Encode::FB_DEFAULT),
+ owner => utf8_decode($owner),
};
push @list, $pr
}
@@ -748,7 +761,7 @@ sub git_get_project_owner {
$pr = unescape($pr);
$ow = unescape($ow);
if ($pr eq $project) {
- $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
+ $owner = utf8_decode($ow);
last;
}
}
@@ -771,7 +784,7 @@ sub git_get_references {
open $fd, "$projectroot/$project/info/refs"
or return;
} else {
- open $fd, "-|", git_cmd(), "ls-remote", "."
+ $fd = git_pipe("ls-remote", ".")
or return;
}
@@ -792,7 +805,7 @@ sub git_get_references {
sub git_get_rev_name_tags {
my $hash = shift || return undef;
- open my $fd, "-|", git_cmd(), "name-rev", "--tags", $hash
+ my $fd = git_pipe("name-rev", "--tags", $hash)
or return;
my $name_rev = <$fd>;
close $fd;
@@ -840,7 +853,7 @@ sub parse_tag {
my %tag;
my @comment;
- open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
+ my $fd = git_pipe("cat-file", "tag", $tag_id) or return;
$tag{'id'} = $tag_id;
while (my $line = <$fd>) {
chomp $line;
@@ -881,7 +894,7 @@ sub parse_commit {
@commit_lines = @$commit_text;
} else {
$/ = "\0";
- open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
+ my $fd = git_pipe("rev-list", "--header", "--parents", "--max-count=1", $commit_id)
or return;
@commit_lines = split '\n', <$fd>;
close $fd or return;
@@ -1098,7 +1111,7 @@ sub get_file_owner {
}
my $owner = $gcos;
$owner =~ s/[,;].*$//;
- return decode("utf8", $owner, Encode::FB_DEFAULT);
+ return utf8_decode($owner);
}
## ......................................................................
@@ -2206,8 +2219,8 @@ sub git_summary {
}
print "</table>\n";
- open my $fd, "-|", git_cmd(), "rev-list", "--max-count=17",
- git_get_head_hash($project)
+ my $fd = git_pipe("rev-list", "--max-count=17",
+ git_get_head_hash($project))
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd;
@@ -2286,7 +2299,7 @@ sub git_blame2 {
if ($ftype !~ "blob") {
die_error("400 Bad Request", "Object is not a blob");
}
- open ($fd, "-|", git_cmd(), "blame", '-l', $file_name, $hash_base)
+ $fd = git_pipe("blame", '-l', $file_name, $hash_base)
or die_error(undef, "Open git-blame failed");
git_header_html();
my $formats_nav =
@@ -2352,7 +2365,7 @@ sub git_blame {
$hash = git_get_hash_by_path($hash_base, $file_name, "blob")
or die_error(undef, "Error lookup file");
}
- open ($fd, "-|", git_cmd(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
+ $fd = git_pipe("annotate", '-l', '-t', '-r', $file_name, $hash_base)
or die_error(undef, "Open git-annotate failed");
git_header_html();
my $formats_nav =
@@ -2473,7 +2486,7 @@ sub git_blob_plain {
}
}
my $type = shift;
- open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
+ my $fd = git_pipe("cat-file", "blob", $hash)
or die_error(undef, "Couldn't cat $file_name, $hash");
$type ||= blob_mimetype($fd, $file_name);
@@ -2491,9 +2504,9 @@ sub git_blob_plain {
-expires=>$expires,
-content_disposition => "inline; filename=\"$save_as\"");
undef $/;
- binmode STDOUT, ':raw';
+ binmode STDOUT, ':raw' if $have_encode;
print <$fd>;
- binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
+ binmode STDOUT, ':utf8' if $have_encode; # as set at the beginning of gitweb.cgi
$/ = "\n";
close $fd;
}
@@ -2515,7 +2528,7 @@ sub git_blob {
}
}
my ($have_blame) = gitweb_check_feature('blame');
- open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
+ my $fd =git_pipe("cat-file", "blob", $hash)
or die_error(undef, "Couldn't cat $file_name, $hash");
my $mimetype = blob_mimetype($fd, $file_name);
if ($mimetype !~ m/^text\//) {
@@ -2580,7 +2593,7 @@ sub git_tree {
}
}
$/ = "\0";
- open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
+ my $fd = git_pipe("ls-tree", '-z', $hash)
or die_error(undef, "Open git-ls-tree failed");
my @entries = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading tree failed");
@@ -2648,9 +2661,9 @@ sub git_snapshot {
my $git_command = git_cmd_str();
open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
die_error(undef, "Execute git-tar-tree failed.");
- binmode STDOUT, ':raw';
+ binmode STDOUT, ':raw' if $have_encode;
print <$fd>;
- binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
+ binmode STDOUT, ':utf8' if $have_encode; # as set at the beginning of gitweb.cgi
close $fd;
}
@@ -2666,7 +2679,7 @@ sub git_log {
my $refs = git_get_references();
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
+ my $fd = git_pipe("rev-list", $limit, $hash)
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd;
@@ -2721,7 +2734,7 @@ sub git_commit {
if (!defined $parent) {
$parent = "--root";
}
- open my $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $parent, $hash
+ my $fd = git_pipe("diff-tree", '-r', @diff_opts, $parent, $hash)
or die_error(undef, "Open git-diff-tree failed");
my @difftree = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading git-diff-tree failed");
@@ -2828,8 +2841,8 @@ sub git_blobdiff {
if (defined $hash_base && defined $hash_parent_base) {
if (defined $file_name) {
# read raw output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
- "--", $file_name
+ $fd = git_pipe("diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
+ "--", $file_name)
or die_error(undef, "Open git-diff-tree failed");
@difftree = map { chomp; $_ } <$fd>;
close $fd
@@ -2842,7 +2855,7 @@ sub git_blobdiff {
# try to find filename from $hash
# read filtered raw output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
+ $fd = git_pipe("diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base)
or die_error(undef, "Open git-diff-tree failed");
@difftree =
# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
@@ -2876,9 +2889,9 @@ sub git_blobdiff {
}
# open patch output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
+ $fd = git_pipe("diff-tree", '-r', @diff_opts,
'-p', $hash_parent_base, $hash_base,
- "--", $file_name
+ "--", $file_name)
or die_error(undef, "Open git-diff-tree failed");
}
@@ -2912,7 +2925,7 @@ sub git_blobdiff {
}
# open patch output
- open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts, $hash_parent, $hash
+ $fd = git_pipe("diff", '-p', @diff_opts, $hash_parent, $hash)
or die_error(undef, "Open git-diff failed");
} else {
die_error('404 Not Found', "Missing one of the blob diff parameters")
@@ -2997,8 +3010,8 @@ sub git_commitdiff {
my $fd;
my @difftree;
if ($format eq 'html') {
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- "--patch-with-raw", "--full-index", $hash_parent, $hash
+ $fd = git_pipe("diff-tree", '-r', @diff_opts,
+ "--patch-with-raw", "--full-index", $hash_parent, $hash)
or die_error(undef, "Open git-diff-tree failed");
while (chomp(my $line = <$fd>)) {
@@ -3008,8 +3021,8 @@ sub git_commitdiff {
}
} elsif ($format eq 'plain') {
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- '-p', $hash_parent, $hash
+ $fd = git_pipe("diff-tree", '-r', @diff_opts,
+ '-p', $hash_parent, $hash)
or die_error(undef, "Open git-diff-tree failed");
} else {
@@ -3108,8 +3121,7 @@ sub git_history {
}
git_print_page_path($file_name, $ftype, $hash_base);
- open my $fd, "-|",
- git_cmd(), "rev-list", "--full-history", $hash_base, "--", $file_name;
+ my $fd = git_pipe("rev-list", "--full-history", $hash_base, "--", $file_name);
git_history_body($fd, $refs, $hash_base, $ftype);
@@ -3150,7 +3162,7 @@ sub git_search {
my $alternate = 0;
if ($commit_search) {
$/ = "\0";
- open my $fd, "-|", git_cmd(), "rev-list", "--header", "--parents", $hash or next;
+ my $fd = git_pipe("rev-list", "--header", "--parents", $hash or next);
while (my $commit_text = <$fd>) {
if (!grep m/$searchtext/i, $commit_text) {
next;
@@ -3271,7 +3283,7 @@ sub git_shortlog {
my $refs = git_get_references();
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", git_cmd(), "rev-list", $limit, $hash
+ my $fd = git_pipe("rev-list", $limit, $hash)
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd;
@@ -3299,7 +3311,7 @@ ## feeds (RSS, OPML)
sub git_rss {
# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
- open my $fd, "-|", git_cmd(), "rev-list", "--max-count=150", git_get_head_hash($project)
+ my $fd = git_pipe("rev-list", "--max-count=150", git_get_head_hash($project))
or die_error(undef, "Open git-rev-list failed");
my @revlist = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading git-rev-list failed");
@@ -3322,8 +3334,8 @@ XML
last;
}
my %cd = parse_date($co{'committer_epoch'});
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- $co{'parent'}, $co{'id'}
+ $fd = git_pipe("diff-tree", '-r', @diff_opts,
+ $co{'parent'}, $co{'id'})
or next;
my @difftree = map { chomp; $_ } <$fd>;
close $fd
@@ -3341,7 +3353,7 @@ XML
"<![CDATA[\n";
my $comment = $co{'comment'};
foreach my $line (@$comment) {
- $line = decode("utf8", $line, Encode::FB_DEFAULT);
+ $line = utf8_decode($line);
print "$line<br/>\n";
}
print "<br/>\n";
@@ -3350,7 +3362,7 @@ XML
next;
}
my $file = validate_input(unquote($7));
- $file = decode("utf8", $file, Encode::FB_DEFAULT);
+ $file = utf8_decode($file);
print "$file<br/>\n";
}
print "]]>\n" .
--
0.99.8c.g64e8-dirty
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] gitweb: support perl 5.6
2006-09-09 14:59 Sven Verdoolaege
@ 2006-09-09 22:20 ` Jakub Narebski
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Narebski @ 2006-09-09 22:20 UTC (permalink / raw)
To: git
Sven Verdoolaege wrote:
> +# returns pipe reading from git command with given arguments
> +sub git_pipe {
> + open my $fd, "-|", join(' ', git_cmd(), @_) or return undef;
> + return $fd;
> +}
> +
I'm sorry, but this is not enough. For example the $file_name argument
should be quoted in shell, i.e. in three argument magic open "-|". So
either you return to your old patch, which changes each list form of open
"-|" into old three argument form (which adds penalty of additional shell
invocation, and is prone to shell interpretation of arguments), and
sometimes add quotes (e.g. "... \'$file_name\' ..."), or (what would be
better) to reimplement list form of open "-|" using two argument forking
open "-|", and doing exec in child, a la "Safe Pipe Opens" in perlipc(3pm).
--
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-09-09 22:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-09 10:46 [PATCH] gitweb: support perl 5.6 Sven Verdoolaege
2006-09-09 12:19 ` Jakub Narebski
-- strict thread matches above, loose matches on Subject: below --
2006-09-09 14:42 Sven Verdoolaege
2006-09-09 14:59 Sven Verdoolaege
2006-09-09 22:20 ` Jakub Narebski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).