From 4d87a7d43579ecd11d31116e6e9dab4e6adb1af3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 8 Jul 2018 19:51:39 +0100 Subject: Dgit.pm: Move parsecontrol etc. out of dgit No functional change. Signed-off-by: Ian Jackson --- Debian/Dgit.pm | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'Debian/Dgit.pm') diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm index 5106f85..8f069f7 100644 --- a/Debian/Dgit.pm +++ b/Debian/Dgit.pm @@ -66,6 +66,8 @@ BEGIN { $negate_harmful_gitattrs changedir git_slurp_config_src gdr_ffq_prev_branchinfo + parsecontrolfh parsecontrol parsechangelog + getfield playtree_setup); # implicitly uses $main::us %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)], @@ -554,6 +556,59 @@ sub gdr_ffq_prev_branchinfo ($) { return ('branch', undef, $symref, $ffq_prev, $gdrlast); } +sub parsecontrolfh ($$;$) { + my ($fh, $desc, $allowsigned) = @_; + our $dpkgcontrolhash_noissigned; + my $c; + for (;;) { + my %opts = ('name' => $desc); + $opts{allow_pgp}= $allowsigned || !$dpkgcontrolhash_noissigned; + $c = Dpkg::Control::Hash->new(%opts); + $c->parse($fh,$desc) or die "parsing of $desc failed"; + last if $allowsigned; + last if $dpkgcontrolhash_noissigned; + my $issigned= $c->get_option('is_pgp_signed'); + if (!defined $issigned) { + $dpkgcontrolhash_noissigned= 1; + seek $fh, 0,0 or die "seek $desc: $!"; + } elsif ($issigned) { + fail "control file $desc is (already) PGP-signed. ". + " Note that dgit push needs to modify the .dsc and then". + " do the signature itself"; + } else { + last; + } + } + return $c; +} + +sub parsecontrol { + my ($file, $desc, $allowsigned) = @_; + my $fh = new IO::Handle; + open $fh, '<', $file or die "$file: $!"; + my $c = parsecontrolfh($fh,$desc,$allowsigned); + $fh->error and die $!; + close $fh; + return $c; +} + +sub parsechangelog { + my $c = Dpkg::Control::Hash->new(name => 'parsed changelog'); + my $p = new IO::Handle; + my @cmd = (qw(dpkg-parsechangelog), @_); + open $p, '-|', @cmd or die $!; + $c->parse($p); + $?=0; $!=0; close $p or failedcmd @cmd; + return $c; +} + +sub getfield ($$) { + my ($dctrl,$field) = @_; + my $v = $dctrl->{$field}; + return $v if defined $v; + fail "missing field $field in ".$dctrl->get_option('name'); +} + # ========== playground handling ========== # terminology: -- cgit v1.2.3 From 98f793a762f743f59663dcf61935a3648719fc4c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 8 Jul 2018 20:01:50 +0100 Subject: Dgit.pm: Break out parsechangelog_loop from dgit git-debrebase is going to want this. No functional change except to some debugging messages. Signed-off-by: Ian Jackson --- Debian/Dgit.pm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'Debian/Dgit.pm') diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm index 8f069f7..066915b 100644 --- a/Debian/Dgit.pm +++ b/Debian/Dgit.pm @@ -31,6 +31,7 @@ use Data::Dumper; use IPC::Open2; use File::Path; use File::Basename; +use Dpkg::Control::Hash; BEGIN { use Exporter (); @@ -67,7 +68,7 @@ BEGIN { changedir git_slurp_config_src gdr_ffq_prev_branchinfo parsecontrolfh parsecontrol parsechangelog - getfield + getfield parsechangelog_loop playtree_setup); # implicitly uses $main::us %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)], @@ -609,6 +610,27 @@ sub getfield ($$) { fail "missing field $field in ".$dctrl->get_option('name'); } +sub parsechangelog_loop ($$$) { + my ($clogcmd, $descbase, $fn) = @_; + # @$clogcmd is qw(dpkg-parsechangelog ...some...options...) + # calls $fn->($thisstanza, $desc); + debugcmd "|",@$clogcmd; + open CLOGS, "-|", @$clogcmd or die $!; + for (;;) { + my $stanzatext = do { local $/=""; ; }; + printdebug "clogp stanza ".Dumper($stanzatext) if $debuglevel>1; + last if !defined $stanzatext; + + my $desc = "$descbase, entry no.$."; + open my $stanzafh, "<", \$stanzatext or die; + my $thisstanza = parsecontrolfh $stanzafh, $desc, 1; + + $fn->($thisstanza, $desc); + } + die $! if CLOGS->error; + close CLOGS or $?==SIGPIPE or failedcmd @$clogcmd; +} + # ========== playground handling ========== # terminology: -- cgit v1.2.3 From 19309e667c41eb0a3149d1bdf7a1a20dc20dda2a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 8 Jul 2018 18:32:09 +0100 Subject: Dgit.pm: Move debinatag_maintview from dgit git-debrebase is about to want this for convert-from-gbp dgit split brain fixup. Signed-off-by: Ian Jackson --- Debian/Dgit.pm | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Debian/Dgit.pm') diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm index 066915b..0e2464d 100644 --- a/Debian/Dgit.pm +++ b/Debian/Dgit.pm @@ -42,6 +42,7 @@ BEGIN { @EXPORT = qw(setup_sigwarn forkcheck_setup forkcheck_mainprocess dep14_version_mangle debiantags debiantag_old debiantag_new + debiantag_maintview server_branch server_ref stat_exists link_ltarget hashfile @@ -209,6 +210,11 @@ sub debiantag_new ($$) { return "archive/$distro/".dep14_version_mangle $v; } +sub debiantag_maintview ($$) { + my ($v,$distro) = @_; + return "$distro/".dep14_version_mangle $v; +} + sub debiantags ($$) { my ($version,$distro) = @_; map { $_->($version, $distro) } (\&debiantag_new, \&debiantag_old); -- cgit v1.2.3