-
- local $/ = "\n";
- my $ref = $self->{ref};
- chomp($self->{tip} = $git->qx(qw(rev-parse --revs-only), $ref));
- if ($self->{path_type} ne '2/38' && $self->{tip}) {
- local $/ = "\0";
- my @tree = $git->qx(qw(ls-tree -r -z --name-only), $ref);
- chomp @tree;
- $self->{-tree} = { map { $_ => 1 } @tree };
- }
-
- my $git_dir = $git->{git_dir};
- my @cmd = ('git', "--git-dir=$git_dir", qw(fast-import
- --quiet --done --date-format=raw));
- my $rdr = { 0 => fileno($out_r), 1 => fileno($in_w) };
- my $pid = spawn(\@cmd, undef, $rdr);
- die "spawn fast-import failed: $!" unless defined $pid;
- $out_w->autoflush(1);
- $self->{in} = $in_r;
- $self->{out} = $out_w;
- $self->{pid} = $pid;
- $self->{nchg} = 0;
- binmode $out_w, ':raw' or die "binmode :raw failed: $!";
- binmode $in_r, ':raw' or die "binmode :raw failed: $!";
+ eval {
+ my ($git, $ref) = @$self{qw(git ref)};
+ local $/ = "\n";
+ chomp($self->{tip} = $git->qx(qw(rev-parse --revs-only), $ref));
+ die "fatal: rev-parse --revs-only $ref: \$?=$?" if $?;
+ if ($self->{path_type} ne '2/38' && $self->{tip}) {
+ my $t = $git->qx(qw(ls-tree -r -z --name-only), $ref);
+ die "fatal: ls-tree -r -z --name-only $ref: \$?=$?" if $?;
+ $self->{-tree} = { map { $_ => 1 } split(/\0/, $t) };
+ }
+ $in_r = $self->{in} = $git->popen(qw(fast-import
+ --quiet --done --date-format=raw),
+ undef, { 0 => $out_r });
+ $out_w->autoflush(1);
+ $self->{out} = $out_w;
+ $self->{nchg} = 0;
+ };
+ if ($@) {
+ $self->lock_release;
+ die $@;
+ }