# location for temporary files needed for diffs
our $git_temp = "/tmp/gitweb";
if (! -d $git_temp) {
- mkdir($git_temp, 0700) || die_error("Couldn't mkdir $git_temp");
+ mkdir($git_temp, 0700) || die_error("Couldn't mkdir $git_temp");
}
# target of the home link on top of all pages
die_error(undef, "No such project.");
}
$rss_link = "<link rel=\"alternate\" title=\"" . esc_param($project) . " log\" href=\"" .
- "$my_uri?" . esc_param("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
+ "$my_uri?" . esc_param("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
$ENV{'GIT_DIR'} = "$projectroot/$project";
} else {
git_project_list();
} else {
$content_type = 'text/html';
}
- print $cgi->header(-type=>$content_type, -charset => 'utf-8', -status=> $status, -expires => $expires);
+ print $cgi->header(-type=>$content_type, -charset => 'utf-8', -status=> $status, -expires => $expires);
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">
sub git_get_type {
my $hash = shift;
- open my $fd, "-|", "$GIT cat-file -t $hash" or return;
+ open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
my $type = <$fd>;
close $fd or return;
chomp $type;
my %tag;
my @comment;
- open my $fd, "-|", "$GIT cat-file tag $tag_id" or return;
+ open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
$tag{'id'} = $tag_id;
while (my $line = <$fd>) {
chomp $line;
@commit_lines = @$commit_text;
} else {
$/ = "\0";
- open my $fd, "-|", "$GIT rev-list --header --parents --max-count=1 $commit_id" or return;
+ open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
@commit_lines = split '\n', <$fd>;
close $fd or return;
$/ = "\n";
if (defined $from) {
$from_tmp = "$git_temp/gitweb_" . $$ . "_from";
open my $fd2, "> $from_tmp";
- open my $fd, "-|", "$GIT cat-file blob $from";
+ open my $fd, "-|", $GIT, "cat-file", "blob", $from;
my @file = <$fd>;
print $fd2 @file;
close $fd2;
if (defined $to) {
$to_tmp = "$git_temp/gitweb_" . $$ . "_to";
open my $fd2, "> $to_tmp";
- open my $fd, "-|", "$GIT cat-file blob $to";
+ open my $fd, "-|", $GIT, "cat-file", "blob", $to;
my @file = <$fd>;
print $fd2 @file;
close $fd2;
$/ = "\n";
} else {
while (my $line = <$fd>) {
- chomp($line);
+ chomp $line;
my $char = substr($line, 0, 1);
my $diff_class = "";
if ($char eq '+') {
if (-d $projects_list) {
# search in directory
my $dir = $projects_list;
- opendir my $dh, $dir or return undef;
+ opendir my ($dh), $dir or return undef;
while (my $dir = readdir($dh)) {
if (-e "$projectroot/$dir/HEAD") {
my $pr = {
# 'git%2Fgit.git Linus+Torvalds'
# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
- open my $fd , $projects_list or return undef;
+ open my ($fd), $projects_list or return undef;
while (my $line = <$fd>) {
chomp $line;
my ($path, $owner) = split ' ', $line;
# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
open my $fd, "$projectroot/$project/info/refs" or return;
while (my $line = <$fd>) {
- chomp($line);
+ chomp $line;
if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\^]+)/) {
if (defined $refs{$1}) {
$refs{$1} .= " / $2";
"<tr><td>owner</td><td>$owner</td></tr>\n" .
"<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
"</table>\n";
- open my $fd, "-|", "$GIT rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head($project)
+ or die_error(undef, "Open git-rev-list failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd;
print "<div>\n" .
"</td>\n" .
"<td>";
if (defined($comment)) {
- print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
+ print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, esc_html($comment));
}
print "</td>\n" .
"<td class=\"link\">";
if ($tag{'type'} eq "tag") {
- print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
+ print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
}
print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
if ($tag{'reftype'} eq "commit") {
- print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
+ print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
}
print "</td>\n" .
"</tr>";
git_footer_html();
}
-sub git_read_blame_line {
- my %bl;
- $_ = shift;
-
- ($bl{'hash'}, $bl{'lineno'}, $bl{'data'}) = /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
-
- return %bl;
-}
-
sub git_blame2 {
my $fd;
my $ftype;
die_error("400 Bad Request", "object is not a blob");
}
open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
- or die_error(undef, "Open failed");
+ or die_error(undef, "Open git-blame failed.");
git_header_html();
print "<div class=\"page_nav\">\n" .
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
print "<div class=\"page_body\">\n";
print "<table class=\"blame\">\n";
print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
- while (my $line = <$fd>) {
- my %blame_line = git_read_blame_line($line);
- my $full_rev = $blame_line{'hash'};
+ while (<$fd>) {
+ /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
+ my $full_rev = $1;
my $rev = substr($full_rev, 0, 8);
- my $lineno = $blame_line{'lineno'};
- my $data = $blame_line{'data'};
+ my $lineno = $2;
+ my $data = $3;
if (!defined $last_rev) {
$last_rev = $full_rev;
or die_error(undef, "Error lookup file.");
}
open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
- or die_error(undef, "Open failed.");
+ or die_error(undef, "Open git-annotate failed.");
git_header_html();
print "<div class=\"page_nav\">\n" .
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
"</td>\n" .
"<td>";
if (defined($comment)) {
- print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
+ print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
}
print "</td>\n" .
"<td class=\"link\">";
if ($tag{'type'} eq "tag") {
- print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
+ print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
}
print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
if ($tag{'reftype'} eq "commit") {
- print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
- " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
+ print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
+ " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
}
print "</td>\n" .
"</tr>";
my $path = shift || return undef;
my $tree = $base;
- my @parts = split '/', $path;
- while (my $part = shift @parts) {
- open my $fd, "-|", "$GIT ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
- my (@entries) = map { chomp; $_ } <$fd>;
- close $fd or return undef;
- foreach my $line (@entries) {
- #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
- $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
- my $t_mode = $1;
- my $t_type = $2;
- my $t_hash = $3;
- my $t_name = validate_input(unquote($4));
- if ($t_name eq $part) {
- if (!(@parts)) {
- return $t_hash;
- }
- if ($t_type eq "tree") {
- $tree = $t_hash;
- }
- last;
- }
- }
- }
+
+ open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
+ or die_error(undef, "Open git-ls-tree failed.");
+ my $line = <$fd>;
+ close $fd or return undef;
+
+ #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
+ $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
+ return $3;
}
sub mimetype_guess_file {
sub git_blob_plain {
if (!defined $hash) {
- if (defined $file_name) {
- my $base = $hash_base || git_read_head($project);
- $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
- } else {
- die_error(undef, "No file name defined.");
- }
- }
+ if (defined $file_name) {
+ my $base = $hash_base || git_read_head($project);
+ $hash = git_get_hash_by_path($base, $file_name, "blob")
+ or die_error(undef, "Error lookup file.");
+ } else {
+ die_error(undef, "No file name defined.");
+ }
+ }
my $type = shift;
- open my $fd, "-|", "$GIT cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash");
+ open my $fd, "-|", $GIT, "cat-file", "blob", $hash
+ or die_error("Couldn't cat $file_name, $hash");
$type ||= git_blob_plain_mimetype($fd, $file_name);
sub git_blob {
if (!defined $hash) {
- if (defined $file_name) {
- my $base = $hash_base || git_read_head($project);
- $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
- } else {
- die_error(undef, "No file name defined.");
- }
- }
+ if (defined $file_name) {
+ my $base = $hash_base || git_read_head($project);
+ $hash = git_get_hash_by_path($base, $file_name, "blob")
+ or die_error(undef, "Error lookup file.");
+ } else {
+ die_error(undef, "No file name defined.");
+ }
+ }
my $have_blame = git_get_project_config_bool ('blame');
- open my $fd, "-|", "$GIT cat-file blob $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "cat-file", "blob", $hash
+ or die_error(undef, "Couldn't cat $file_name, $hash.");
my $mimetype = git_blob_plain_mimetype($fd, $file_name);
if ($mimetype !~ m/^text\//) {
close $fd;
print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
}
print "</div>\n".
- "<div>" .
+ "<div>" .
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
"</div>\n";
} else {
}
}
$/ = "\0";
- open my $fd, "-|", "$GIT ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed.");
+ open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
+ or die_error(undef, "Open git-ls-tree failed.");
chomp (my (@entries) = <$fd>);
close $fd or die_error(undef, "Reading tree failed.");
$/ = "\n";
sub git_rss {
# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
- open my $fd, "-|", "$GIT rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head($project)
+ or die_error(undef, "Open git-rev-list failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading rev-list failed.");
print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
last;
}
my %cd = date_str($co{'committer_epoch'});
- open $fd, "-|", "$GIT diff-tree -r $co{'parent'} $co{'id'}" or next;
+ open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
my @difftree = map { chomp; $_ } <$fd>;
close $fd or next;
print "<item>\n" .
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", "$GIT rev-list $limit $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "rev-list", $limit, $hash
+ or die_error(undef, "Open git-rev-list failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd;
my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
my @difftree;
- my $root = "";
my $parent = $co{'parent'};
if (!defined $parent) {
- $root = " --root";
- $parent = "";
+ $parent = "--root";
}
- open my $fd, "-|", "$GIT diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
+ or die_error(undef, "Open git-diff-tree failed.");
@difftree = map { chomp; $_ } <$fd>;
- close $fd or die_error(undef, "Reading diff-tree failed.");
+ close $fd or die_error(undef, "Reading git-diff-tree failed.");
# non-textual hash id's can be cached
my $expires;
if (!defined $hash_parent) {
$hash_parent = $co{'parent'};
}
- open my $fd, "-|", "$GIT diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
+ or die_error(undef, "Open git-diff-tree failed.");
my (@difftree) = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading diff-tree failed.");
my $status = $5;
my $file = validate_input(unquote($6));
if ($status eq "A") {
- print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
+ print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
"</div>\n";
git_diff_print(undef, "/dev/null", $to_id, "b/$file");
sub git_commitdiff_plain {
mkdir($git_temp, 0700);
- open my $fd, "-|", "$GIT diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
+ or die_error(undef, "Open git-diff-tree failed.");
my (@difftree) = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading diff-tree failed.");
# try to figure out the next tag after this commit
my $tagname;
my $refs = read_info_ref("tags");
- open $fd, "-|", "$GIT rev-list HEAD";
+ open $fd, "-|", $GIT, "rev-list", "HEAD";
chomp (my (@commits) = <$fd>);
close $fd;
foreach my $commit (@commits) {
"Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
"Subject: $co{'title'}\n";
if (defined $tagname) {
- print "X-Git-Tag: $tagname\n";
+ print "X-Git-Tag: $tagname\n";
}
print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
"\n";
git_print_page_path($file_name, $ftype);
open my $fd, "-|",
- "$GIT rev-list --full-history $hash_base -- \'$file_name\'";
+ $GIT, "rev-list", "--full-history", $hash_base, "--", "\'$file_name\'";
print "<table cellspacing=\"0\">\n";
my $alternate = 0;
while (my $line = <$fd>) {
my $alternate = 0;
if ($commit_search) {
$/ = "\0";
- open my $fd, "-|", "$GIT rev-list --header --parents $hash" or next;
+ open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
while (my $commit_text = <$fd>) {
if (!grep m/$searchtext/i, $commit_text) {
next;
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
- open my $fd, "-|", "$GIT rev-list $limit $hash" or die_error(undef, "Open failed.");
+ open my $fd, "-|", $GIT, "rev-list", $limit, $hash
+ or die_error(undef, "Open git-rev-list failed.");
my (@revlist) = map { chomp; $_ } <$fd>;
close $fd;