$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};
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);
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]};
my $env = $req->{env};
my $q =$req->{'q'} = PublicInbox::RepobrowseGitQuery->new($env);
my $h = $q->{h};
- my $git_dir = "--git-dir=$git->{git_dir}";
my $read_log = sub {
- my $cmd = ['git', $git_dir,
- qw(log --no-notes --no-color --abbrev-commit),
- $git->abbrev, $ATOM_FMT, "-$max", $h, '--' ];
+ my $cmd = $git->cmd(qw(log --no-notes --no-color
+ --abbrev-commit), $git->abbrev,
+ $ATOM_FMT, "-$max", $h, '--');
my $expath = $req->{expath};
push @$cmd, $expath if $expath ne '';
my $rdr = { 2 => $git->err_begin };
$env->{'qspawn.response'} = $_[0];
return $read_log->() if $h ne '';
- my $cmd = [ 'git', $git_dir, qw(symbolic-ref --short HEAD) ];
+ my $cmd = $git->cmd(qw(symbolic-ref --short HEAD));
my $rdr = { 2 => $git->err_begin };
my $qsp = PublicInbox::Qspawn->new($cmd, undef, undef, $rdr);
$qsp->psgi_qx($env, undef, sub {
}
my $git = $req->{repo_info}->{git};
- my $cmd = [ 'git', "--git-dir=$git->{git_dir}", qw(show
- -z --numstat -p --encoding=UTF-8
+ my $cmd = $git->cmd(qw(show -z --numstat -p --encoding=UTF-8
--no-notes --no-color -c),
- $git->abbrev, GIT_FMT, $id, '--' ];
+ $git->abbrev, GIT_FMT, $id, '--');
my $rdr = { 2 => $git->err_begin };
my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
$req->{'q'} = $q;
my $id2 = $q->{id2};
my $git = $req->{repo_info}->{git};
- my $cmd = [ 'git', "--git-dir=$git->{git_dir}", qw(diff-tree
- -z --numstat -p --encoding=UTF-8
- --no-color -M -B -D -r),
- $id2, $id, '--' ];
+ my $cmd = $git->cmd(qw(diff-tree -z --numstat -p --encoding=UTF-8
+ --no-color -M -B -D -r), $id2, $id, '--');
my $expath = $req->{expath};
push @$cmd, $expath if $expath ne '';
my $o = { nofollow => 1, noindex => 1 };
my $h = $q->{h};
$h eq '' and $h = 'HEAD';
my $git = $repo_info->{git};
- my $git_dir = $git->{git_dir};
-
- # n.b. no need to escape $h, this -debug line will never
- # be seen if $h is invalid
- # XXX but we should probably validate refnames before execve...
- $req->{-debug} = "git log --git-dir=$git_dir $h --";
- my $cmd = [ 'git', "--git-dir=$git_dir",
- qw(log --no-notes --no-color --abbrev-commit),
- $git->abbrev, $LOG_FMT, "-$max", $h, '--' ];
+ my $cmd = $git->cmd(qw(log --no-notes --no-color --abbrev-commit),
+ $git->abbrev, $LOG_FMT, "-$max", $h, '--');
my $rdr = { 2 => $git->err_begin };
my $title = "log: $repo_info->{repo} (" . utf8_html($h). ')';
$req->{lhtml} = $self->html_start($req, $title) . "\n\n";
# limit scope, don't take extra args to avoid wasting server
# resources buffering:
my $range = "$id~1..$id^0";
- my @cmd = ('git', "--git-dir=$git->{git_dir}", @CMD,
- $sig." $range", $range, '--');
+ my $cmd = $git->cmd(@CMD, $sig." $range", $range, '--');
my $expath = $req->{expath};
- push @cmd, $expath if $expath ne '';
+ push @$cmd, $expath if $expath ne '';
- my $qsp = PublicInbox::Qspawn->new(\@cmd);
+ my $qsp = PublicInbox::Qspawn->new($cmd);
$qsp->psgi_return($env, undef, sub {
my ($r) = @_;
my $h = ['Content-Type', 'text/plain; charset=UTF-8'];
$req->{tpfx} = $pfx;
$req->{tstart} = "<html><head><title>$title</title></head><body>".$t;
- my $cmd = [ 'git', "--git-dir=$git->{git_dir}",
- qw(ls-tree --name-only -z), $git->abbrev, $hex ];
+ my $cmd = $git->cmd(qw(ls-tree --name-only -z), $git->abbrev, $hex);
my $rdr = { 2 => $git->err_begin };
my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
my $env = $req->{env};
delete $env->{'repobrowse.tree_cb'};
delete $env->{'qspawn.quiet'};
my $pfx = "$repo_info->{snapshot_pfx}-$ref/";
- my $cmd = [ 'git', "--git-dir=$git->{git_dir}", 'archive',
- "--prefix=$pfx", "--format=$fmt", $tree ];
+ my $cmd = $git->cmd('archive',
+ "--prefix=$pfx", "--format=$fmt", $tree);
my $rdr = { 2 => $git->err_begin };
my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
$qsp->psgi_return($env, undef, sub {
});
};
- my @cmd = ('git', "--git-dir=$git->{git_dir}",
- qw(rev-parse --verify --revs-only));
+ my $cmd = $git->cmd(qw(rev-parse --verify --revs-only));
# try prefixing "v" or "V" for tag names to get the tree
my @refs = ("V$ref", "v$ref", $ref);
$env->{'qspawn.quiet'} = 1;
}
my $rdr = { 2 => $git->err_begin };
my $r = pop @refs;
- my $qsp = PublicInbox::Qspawn->new([@cmd, $r], undef, $rdr);
+ my $qsp = PublicInbox::Qspawn->new([@$cmd, $r], undef, $rdr);
$qsp->psgi_qx($env, undef, $env->{'repobrowse.tree_cb'});
};
sub {
# n.b. we would use %(HEAD) in for-each-ref --format if we could
# rely on git 1.9.0+, but it's too soon for that in early 2017...
- my $cmd = [ 'git', "--git-dir=$git->{git_dir}", qw(symbolic-ref HEAD) ];
+ my $cmd = $git->cmd(qw(symbolic-ref HEAD));
my $rdr = { 2 => $git->err_begin };
my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
sub {
sub git_tree_show {
my ($req, $hex, $q) = @_;
my $git = $req->{repo_info}->{git};
- my $cmd = [ 'git', "--git-dir=$git->{git_dir}", qw(ls-tree -l -z),
- $git->abbrev, $hex ];
+ my $cmd = $git->cmd(qw(ls-tree -l -z), $git->abbrev, $hex);
my $rdr = { 2 => $git->err_begin };
my $qsp = PublicInbox::Qspawn->new($cmd, undef, $rdr);
my $t = cur_path($req, $q);