gitweb: Use list for of open for running git commands, thorougly.
Use list form of open for running git commands and reading their output through pipe, for example open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash instead of open my $fd, "-|", "$GIT rev-list --header --parents $hash" Single letter options use ' instead of " as quotes, according to style used in list form of magic "-|" open. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jakub Narebski committed
Jul 30, 2006 at 18:28 UTC
b9182987a80f7e820cbe1f8c7c4dc26f8586e8cd
1 file changed
+27
-24
gitweb/gitweb.cgi
+27
-24
@@ -388,7 +388,7 @@ sub die_error {
388
sub git_get_type {
389
my $hash = shift;
390
391
- open my $fd, "-|", "$GIT cat-file -t $hash" or return;
391
+ open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
392
my $type = <$fd>;
393
close $fd or return;
394
chomp $type;
@@ -440,7 +440,7 @@ sub git_read_tag {
440
my %tag;
441
my @comment;
442
443
- open my $fd, "-|", "$GIT cat-file tag $tag_id" or return;
443
+ open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
444
$tag{'id'} = $tag_id;
445
while (my $line = <$fd>) {
446
chomp $line;
@@ -512,7 +512,7 @@ sub git_read_commit {
512
@commit_lines = @$commit_text;
513
} else {
514
$/ = "\0";
515
- open my $fd, "-|", "$GIT rev-list --header --parents --max-count=1 $commit_id" or return;
515
+ open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
516
@commit_lines = split '\n', <$fd>;
517
close $fd or return;
518
$/ = "\n";
@@ -610,7 +610,7 @@ sub git_diff_print {
610
if (defined $from) {
611
$from_tmp = "$git_temp/gitweb_" . $$ . "_from";
612
open my $fd2, "> $from_tmp";
613
- open my $fd, "-|", "$GIT cat-file blob $from";
613
+ open my $fd, "-|", $GIT, "cat-file", "blob", $from;
614
my @file = <$fd>;
615
print $fd2 @file;
616
close $fd2;
@@ -621,7 +621,7 @@ sub git_diff_print {
621
if (defined $to) {
622
$to_tmp = "$git_temp/gitweb_" . $$ . "_to";
623
open my $fd2, "> $to_tmp";
624
- open my $fd, "-|", "$GIT cat-file blob $to";
624
+ open my $fd, "-|", $GIT, "cat-file", "blob", $to;
625
my @file = <$fd>;
626
print $fd2 @file;
627
close $fd2;
@@ -1062,7 +1062,8 @@ sub git_summary {
1062
"<tr><td>owner</td><td>$owner</td></tr>\n" .
1063
"<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1064
"</table>\n";
1065
- open my $fd, "-|", "$GIT rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed.");
1065
+ open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head($project)
1066
+ or die_error(undef, "Open failed.");
1067
my (@revlist) = map { chomp; $_ } <$fd>;
1068
close $fd;
1069
print "<div>\n" .
@@ -1526,7 +1527,7 @@ sub git_get_hash_by_path {
1527
my $tree = $base;
1528
my @parts = split '/', $path;
1529
while (my $part = shift @parts) {
1529
- open my $fd, "-|", "$GIT ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1530
+ open my $fd, "-|", $GIT, "ls-tree", $tree or die_error(undef, "Open git-ls-tree failed.");
1531
my (@entries) = map { chomp; $_ } <$fd>;
1532
close $fd or return undef;
1533
foreach my $line (@entries) {
@@ -1622,7 +1623,7 @@ sub git_blob_plain {
1623
}
1624
}
1625
my $type = shift;
1625
- open my $fd, "-|", "$GIT cat-file blob $hash" or die_error("Couldn't cat $file_name, $hash");
1626
+ open my $fd, "-|", $GIT, "cat-file", "blob", $hash or die_error("Couldn't cat $file_name, $hash");
1627
1628
$type ||= git_blob_plain_mimetype($fd, $file_name);
1629
@@ -1654,7 +1655,7 @@ sub git_blob {
1655
}
1656
}
1657
my $have_blame = git_get_project_config_bool ('blame');
1657
- open my $fd, "-|", "$GIT cat-file blob $hash" or die_error(undef, "Open failed.");
1658
+ open my $fd, "-|", $GIT, "cat-file", "blob", $hash or die_error(undef, "Open failed.");
1659
my $mimetype = git_blob_plain_mimetype($fd, $file_name);
1660
if ($mimetype !~ m/^text\//) {
1661
close $fd;
@@ -1718,7 +1719,7 @@ sub git_tree {
1719
}
1720
}
1721
$/ = "\0";
1721
- open my $fd, "-|", "$GIT ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed.");
1722
+ open my $fd, "-|", $GIT, "ls-tree", '-z', $hash or die_error(undef, "Open git-ls-tree failed.");
1723
chomp (my (@entries) = <$fd>);
1724
close $fd or die_error(undef, "Reading tree failed.");
1725
$/ = "\n";
@@ -1799,7 +1800,8 @@ sub git_tree {
1800
1801
sub git_rss {
1802
# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1802
- open my $fd, "-|", "$GIT rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
1803
+ open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head($project)
1804
+ or die_error(undef, "Open failed.");
1805
my (@revlist) = map { chomp; $_ } <$fd>;
1806
close $fd or die_error(undef, "Reading rev-list failed.");
1807
print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
@@ -1819,7 +1821,7 @@ sub git_rss {
1821
last;
1822
}
1823
my %cd = date_str($co{'committer_epoch'});
1822
- open $fd, "-|", "$GIT diff-tree -r $co{'parent'} $co{'id'}" or next;
1824
+ open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
1825
my @difftree = map { chomp; $_ } <$fd>;
1826
close $fd or next;
1827
print "<item>\n" .
@@ -1907,7 +1909,7 @@ sub git_log {
1909
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1910
1911
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1910
- open my $fd, "-|", "$GIT rev-list $limit $hash" or die_error(undef, "Open failed.");
1912
+ open my $fd, "-|", $GIT, "rev-list", $limit, $hash or die_error(undef, "Open failed.");
1913
my (@revlist) = map { chomp; $_ } <$fd>;
1914
close $fd;
1915
@@ -1992,15 +1994,14 @@ sub git_commit {
1994
my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1995
1996
my @difftree;
1995
- my $root = "";
1997
my $parent = $co{'parent'};
1998
if (!defined $parent) {
1998
- $root = " --root";
1999
- $parent = "";
1999
+ $parent = "--root";
2000
}
2001
- open my $fd, "-|", "$GIT diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
2001
+ open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2002
+ or die_error(undef, "Open failed.");
2003
@difftree = map { chomp; $_ } <$fd>;
2003
- close $fd or die_error(undef, "Reading diff-tree failed.");
2004
+ close $fd or die_error(undef, "Reading git-diff-tree failed.");
2005
2006
# non-textual hash id's can be cached
2007
my $expires;
@@ -2244,7 +2245,8 @@ sub git_commitdiff {
2245
if (!defined $hash_parent) {
2246
$hash_parent = $co{'parent'};
2247
}
2247
- open my $fd, "-|", "$GIT diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2248
+ open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2249
+ or die_error(undef, "Open failed.");
2250
my (@difftree) = map { chomp; $_ } <$fd>;
2251
close $fd or die_error(undef, "Reading diff-tree failed.");
2252
@@ -2334,14 +2336,15 @@ sub git_commitdiff {
2336
2337
sub git_commitdiff_plain {
2338
mkdir($git_temp, 0700);
2337
- open my $fd, "-|", "$GIT diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2339
+ open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2340
+ or die_error(undef, "Open failed.");
2341
my (@difftree) = map { chomp; $_ } <$fd>;
2342
close $fd or die_error(undef, "Reading diff-tree failed.");
2343
2344
# try to figure out the next tag after this commit
2345
my $tagname;
2346
my $refs = read_info_ref("tags");
2344
- open $fd, "-|", "$GIT rev-list HEAD";
2347
+ open $fd, "-|", $GIT, "rev-list", "HEAD";
2348
chomp (my (@commits) = <$fd>);
2349
close $fd;
2350
foreach my $commit (@commits) {
@@ -2419,7 +2422,7 @@ sub git_history {
2422
git_print_page_path($file_name, $ftype);
2423
2424
open my $fd, "-|",
2422
- "$GIT rev-list --full-history $hash_base -- \'$file_name\'";
2425
+ $GIT, "rev-list", "--full-history", $hash_base, "--", "\'$file_name\'";
2426
print "<table cellspacing=\"0\">\n";
2427
my $alternate = 0;
2428
while (my $line = <$fd>) {
@@ -2506,7 +2509,7 @@ sub git_search {
2509
my $alternate = 0;
2510
if ($commit_search) {
2511
$/ = "\0";
2509
- open my $fd, "-|", "$GIT rev-list --header --parents $hash" or next;
2512
+ open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2513
while (my $commit_text = <$fd>) {
2514
if (!grep m/$searchtext/i, $commit_text) {
2515
next;
@@ -2627,7 +2630,7 @@ sub git_shortlog {
2630
" | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2631
2632
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2630
- open my $fd, "-|", "$GIT rev-list $limit $hash" or die_error(undef, "Open failed.");
2633
+ open my $fd, "-|", $GIT, "rev-list", $limit, $hash or die_error(undef, "Open failed.");
2634
my (@revlist) = map { chomp; $_ } <$fd>;
2635
close $fd;
2636