From 188136747e4562e4e2a6df176b02ad8c057073a0 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 2 Mar 2015 00:46:45 -0800 Subject: [PATCH] Project.pm: eliminate unnecessary use of shell There's no reason to use the shell to do simple reading and writing of git values. Switch to multi-arg system, pipe reading and redirected output to eliminate unneccary use of the shell. --- Girocco/Project.pm | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/Girocco/Project.pm b/Girocco/Project.pm index a07189b..a6b2bb6 100644 --- a/Girocco/Project.pm +++ b/Girocco/Project.pm @@ -90,7 +90,8 @@ our %reservedprojectnames = ( ); sub _update_index { - system($Girocco::Config::basedir . '/gitweb/genindex.sh'); + my $genindex = "$Girocco::Config::basedir/gitweb/genindex.sh"; + system($genindex $genindex); } sub _property_path { @@ -106,11 +107,13 @@ sub _property_fget { $pname = $propmapro{$name} unless $pname; $pname or die "unknown property: $name"; if ($pname =~ s/^://) { - my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "gitweb.$pname"`; + my $val = get_git("--git-dir=$self->{path}", 'config', "gitweb.$pname"); + defined($val) or $val = ''; chomp $val; return $val; } elsif ($pname =~ s/^%//) { - my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "$pname"`; + my $val = get_git("--git-dir=$self->{path}", 'config', $pname); + defined($val) or $val = ''; chomp $val; return $val; } @@ -150,12 +153,14 @@ sub _properties_load { foreach my $prop (keys %propmapro) { $self->{$prop} = $self->_property_fget($prop); } - my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config --bool "gitweb.statusupdates" 2>/dev/null`; + my $val = get_git("--git-dir=$self->{path}", 'config', '--bool', 'gitweb.statusupdates'); + defined($val) or $val = ''; chomp $val; $val = ($val eq 'false') ? 0 : 1; $self->{statusupdates} = $val; delete $self->{auth}; - $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "gitweb.repoauth"`; + $val = get_git("--git-dir=$self->{path}", 'config', 'gitweb.repoauth'); + defined($val) or $val = ''; chomp $val; if ($val =~ /^# ([A-Z]+)AUTH ([0-9a-f]+) (\d+)/) { my $expire = $3; @@ -255,13 +260,27 @@ sub _alternates_setup { chmod 0664, $filename or warn "cannot chmod $filename: $!"; } - # The symlink is problematic since git remote prune will traverse it. - #symlink "$forkee_path/refs", $self->{path}.'/refs/forkee'; - # copy refs from parent project - system("'$Girocco::Config::git_bin' --git-dir='$forkee_path' show-ref > '$self->{path}/packed-refs'"); - # initialize HEAD, hacky version - system("cp $forkee_path/HEAD $self->{path}/HEAD"); + open(SAVEOUT, ">&STDOUT") || die "couldn't dup STDOUT: $!"; + my $result = open(STDOUT, '>', "$self->{path}/packed-refs"); + my $resultstr = $!; + if (!$result) { + open(STDOUT, ">&SAVEOUT") || die "couldn't dup SAVEOUT to STDOUT: $!"; + close(SAVEOUT) or die "couldn't close SAVEOUT: $!"; + die "could not write fork's packed-refs file: $resultstr"; + } + system($Girocco::Config::git_bin, "--git-dir=$forkee_path", 'for-each-ref', '--format=%(objectname) %(refname)'); + $result = close(STDOUT); + $resultstr = $!; + open(STDOUT, ">&SAVEOUT") || die "couldn't dup SAVEOUT to STDOUT: $!"; + close(SAVEOUT) or die "couldn't close SAVEOUT: $!"; + $result or die "could not close fork's packed-refs file: $resultstr"; + + # initialize HEAD + my $HEAD = get_git("--git-dir=$forkee_path", 'symbolic-ref', 'HEAD'); + defined($HEAD) && $HEAD =~ m,^refs/heads/., or $HEAD = 'refs/heads/master'; + chomp $HEAD; + system($Girocco::Config::git_bin, "--git-dir=$self->{path}", 'symbolic-ref', 'HEAD', $HEAD); chmod 0664, "$self->{path}/packed-refs", "$self->{path}/HEAD"; } @@ -771,7 +790,8 @@ sub get_heads { sub get_HEAD { my $self = shift; - my $HEAD = `$Girocco::Config::git_bin --git-dir=$self->{path} symbolic-ref HEAD`; + my $HEAD = get_git("--git-dir=$self->{path}", 'symbolic-ref', 'HEAD'); + defined($HEAD) or $HEAD = ''; chomp $HEAD; die "could not get HEAD" if ($HEAD !~ m{^refs/heads/(.+)$}); return $1; -- 2.11.4.GIT