summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Debian/Dgit.pm18
1 files changed, 14 insertions, 4 deletions
diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm
index f299450..abcf123 100644
--- a/Debian/Dgit.pm
+++ b/Debian/Dgit.pm
@@ -348,11 +348,21 @@ sub git_rev_parse ($) {
return cmdoutput qw(git rev-parse), "$_[0]~0";
}
-sub git_cat_file ($) {
- my ($objname) = @_;
+sub git_cat_file ($;$) {
+ my ($objname, $etype) = @_;
# => ($type, $data) or ('missing', undef)
# in scalar context, just the data
+ # if $etype defined, dies unless type is $etype or in @$etype
our ($gcf_pid, $gcf_i, $gcf_o);
+ my $chk = sub {
+ my ($gtype, $data) = @_;
+ if ($etype) {
+ $etype = [$etype] unless ref $etype;
+ confess "$objname expected @$etype but is $gtype"
+ unless grep { $gtype eq $_ } @$etype;
+ }
+ return ($gtype, $data);
+ };
if (!$gcf_pid) {
my @cmd = qw(git cat-file --batch);
debugcmd "GCF|", @cmd;
@@ -362,13 +372,13 @@ sub git_cat_file ($) {
print $gcf_i $objname, "\n" or die $!;
my $x = <$gcf_o>;
printdebug "GCF<| ", $x;
- if ($x =~ m/ (missing)$/) { return ($1, undef); }
+ if ($x =~ m/ (missing)$/) { return $chk->($1, undef); }
my ($type, $size) = $x =~ m/^.* (\w+) (\d+)\n/ or die "$objname ?";
my $data;
(read $gcf_o, $data, $size) == $size or die "$objname $!";
$x = <$gcf_o>;
$x eq "\n" or die "$objname ($_) $!";
- return ($type, $data);
+ return $chk->($type, $data);
}
sub git_for_each_ref ($$;$) {