From c3288fb27efcca73ba87e27c2c2b41b4a1dfbd46 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 26 Jan 2017 04:27:02 +0000 Subject: repobrowse: simplify command generation for git commands This shortens the code quite a bit at a negligible performance cost, and the diffstat agrees. --- lib/PublicInbox/Git.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox/Git.pm') diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 648aaaf0..caca3b09 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -50,6 +50,11 @@ sub err ($) { $buf; } +sub cmd { + my $self = shift; + [ 'git', "--git-dir=$self->{git_dir}", @_ ]; +} + sub _bidi_pipe { my ($self, $batch, $in, $out, $pid) = @_; return if $self->{$pid}; @@ -58,9 +63,8 @@ sub _bidi_pipe { pipe($in_r, $in_w) or fail($self, "pipe failed: $!"); pipe($out_r, $out_w) or fail($self, "pipe failed: $!"); - my @cmd = ('git', "--git-dir=$self->{git_dir}", qw(cat-file), $batch); my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) }; - my $p = spawn(\@cmd, undef, $redir); + my $p = spawn(cmd($self, qw(cat-file), $batch), undef, $redir); defined $p or fail($self, "spawn failed: $!"); $self->{$pid} = $p; $out_w->autoflush(1); @@ -167,7 +171,7 @@ sub fail { sub popen { my ($self, @cmd) = @_; - my $cmd = [ 'git', "--git-dir=$self->{git_dir}" ]; + my $cmd = cmd($self); my ($env, $opt); if (ref $cmd[0]) { push @$cmd, @{$cmd[0]}; -- cgit v1.2.3-24-ge0c7