sub _deliver_each_msg {
my ($self, $dest, $tip, $new) = @_;
my $git = $self->{git};
+ my $git_pm = $git->try_git_pm;
foreach my $path (@$new) {
- _deliver_die($git->cat_blob("$tip:$path"), $dest);
+ _deliver_die($git->cat_blob("$tip:$path", $git_pm), $dest);
}
}
my $git = $self->{git};
require Ssoma::IMAP;
my $imap = Ssoma::IMAP->new($git);
+ my $git_pm = $git->try_git_pm;
foreach my $path (@$new) {
- $imap->imap_deliver($git->cat_blob("$tip:$path"));
+ $imap->imap_deliver($git->cat_blob("$tip:$path", $git_pm));
}
$imap->quit;
}
}
sub cat_blob {
- my ($self, $blob_id) = @_;
- my $cmd = "git cat-file blob $blob_id";
- my $str = `$cmd`;
- die "$cmd failed: $?\n" if $?;
+ my ($self, $blob_id, $git_pm) = @_;
+ my $str;
+ if ($git_pm) {
+ open my $fh, '>', \$str or
+ die "failed to setup string handle: $!\n";
+ binmode $fh;
+ my $bytes = $git_pm->cat_blob($blob_id, $fh);
+ close $fh or die "failed to close string handle: $!\n";
+ die "$blob_id invalid\n" if $bytes <= 0;
+ } else {
+ my $cmd = "git cat-file blob $blob_id";
+ $str = `$cmd`;
+ die "$cmd failed: $?\n" if $?;
+ }
$str;
}
system(@cmd) == 0 or die "command: ". join(' ', @cmd) . ": $?\n";
}
+# keep Git.pm optional, not all installations of git have it
+sub try_git_pm {
+ my ($self) = @_;
+ eval {
+ require Git;
+ Git->repository(Directory => $self->{git_dir});
+ };
+}
+
1;