diff options
author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2017-07-09 14:12:47 +0100 |
---|---|---|
committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2018-06-16 12:25:49 +0100 |
commit | e07f113726f46b8ab921ceecd4e282d93b39c2a2 (patch) | |
tree | e1028ca3422d5866b0af7d4f51e147e36305d055 /Debian/Dgit.pm | |
parent | 54a18d290527b6aa515592d27f90f35187757e8c (diff) |
Dgit.pm: git_cat_file: Introduce $etype parameter
No functional change for existing callers.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Diffstat (limited to 'Debian/Dgit.pm')
-rw-r--r-- | Debian/Dgit.pm | 18 |
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 ($$;$) { |