summaryrefslogtreecommitdiff
path: root/Debian
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2017-01-06 17:01:14 +0000
committerIan Jackson <ijackson@chiark.greenend.org.uk>2017-01-06 18:32:14 +0000
commite9a3ab8ab115a663975026c84332a1d0bdc7264b (patch)
tree89b6070c7edae4b9f0b4adfa1fd2ebf1698d0a6b /Debian
parent9aec5c491b959a70d1485149fd9e5babc97adeec (diff)
Dgit.pm: Provide git_cat_file
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Diffstat (limited to 'Debian')
-rw-r--r--Debian/Dgit.pm26
1 files changed, 25 insertions, 1 deletions
diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm
index e9921d6..314bd8c 100644
--- a/Debian/Dgit.pm
+++ b/Debian/Dgit.pm
@@ -28,6 +28,7 @@ use IO::Handle;
use Config;
use Digest::SHA;
use Data::Dumper;
+use IPC::Open2;
BEGIN {
use Exporter ();
@@ -45,7 +46,8 @@ BEGIN {
waitstatusmsg failedcmd_waitstatus
failedcmd_report_cmd failedcmd
cmdoutput cmdoutput_errok
- git_rev_parse git_get_ref git_for_each_ref
+ git_rev_parse git_cat_file
+ git_get_ref git_for_each_ref
git_for_each_tag_referring is_fast_fwd
$package_re $component_re $deliberately_re
$branchprefix
@@ -306,6 +308,28 @@ sub git_rev_parse ($) {
return cmdoutput qw(git rev-parse), "$_[0]~0";
}
+sub git_cat_file ($) {
+ my ($objname) = @_;
+ # => ($type, $data) or ('missing', undef)
+ our ($gcf_pid, $gcf_i, $gcf_o);
+ if (!$gcf_pid) {
+ my @cmd = qw(git cat-file --batch);
+ debugcmd "GCF|", @cmd;
+ $gcf_pid = open2 $gcf_o, $gcf_i, @cmd or die $!;
+ }
+ printdebug "GCF>| ", $objname, "\n";
+ print $gcf_i $objname, "\n" or die $!;
+ my $x = <$gcf_o>;
+ printdebug "GCF<| ", $x;
+ if ($x =~ m/ (missing)$/) { return ($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);
+}
+
sub git_for_each_ref ($$;$) {
my ($pattern,$func,$gitdir) = @_;
# calls $func->($objid,$objtype,$fullrefname,$reftail);