This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=d1d35a56e401181b6d15baf474a7db21d3372a65 commit d1d35a56e401181b6d15baf474a7db21d3372a65 Author: Guillem Jover <[email protected]> AuthorDate: Sat Oct 20 15:04:16 2018 +0200 Dpkg::Source::Package, dpkg-source: Switch to new Dpkg::Source::Format module This move all ad-hoc code to use the new Dpkg::Source::Format module. --- debian/changelog | 1 + scripts/Dpkg/Source/Package.pm | 52 ++++++++++++++++++------------------------ scripts/dpkg-source.pl | 12 ++++------ 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/debian/changelog b/debian/changelog index 456c1ec43..55d28b816 100644 --- a/debian/changelog +++ b/debian/changelog @@ -42,6 +42,7 @@ dpkg (1.19.3) UNRELEASED; urgency=medium - dpkg-maintscript-helper: Use an explicit escape instead of a literal backslash. - Quote shell variables. Reported by Johannes Schauer <[email protected]>. + - Switch perl code to use the new Dpkg::Source::Format module. * Build system: - get-version: Use a format string with printf. - run-script: Use $() instead of deprecated ``. diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm index 29e61170e..74daa712b 100644 --- a/scripts/Dpkg/Source/Package.pm +++ b/scripts/Dpkg/Source/Package.pm @@ -213,6 +213,7 @@ sub new { my $class = ref($this) || $this; my $self = { fields => Dpkg::Control->new(type => CTRL_PKG_SRC), + format => Dpkg::Source::Format->new(), options => {}, checksums => Dpkg::Checksums->new(), }; @@ -287,34 +288,28 @@ sub initialize { sub upgrade_object_type { my ($self, $update_format) = @_; $update_format //= 1; - $self->{fields}{'Format'} //= '1.0'; - my $format = $self->{fields}{'Format'}; - - if ($format =~ /^(\d+)(?:\.(\d+))?(?:\s+\(([a-z0-9]+)\))?$/) { - my ($major, $minor, $variant) = ($1, $2, $3); - - my $module = "Dpkg::Source::Package::V$major"; - $module .= '::' . ucfirst $variant if defined $variant; - eval qq{ - pop \@INC if \$INC[-1] eq '.'; - require $module; - \$minor = \$${module}::CURRENT_MINOR_VERSION; - }; - if ($@) { - error(g_("source package format '%s' is not supported: %s"), - $format, $@); - } - if ($update_format) { - $minor //= 0; - $self->{fields}{'Format'} = "$major.$minor"; - $self->{fields}{'Format'} .= " ($variant)" if defined $variant; - } - $module->prerequisites() if $module->can('prerequisites'); - bless $self, $module; - } else { - error(g_("source package format '%s' is invalid"), $format); + my $format = $self->{fields}{'Format'} // '1.0'; + my ($major, $minor, $variant) = $self->{format}->set($format); + + my $module = "Dpkg::Source::Package::V$major"; + $module .= '::' . ucfirst $variant if defined $variant; + eval qq{ + pop \@INC if \$INC[-1] eq '.'; + require $module; + \$minor = \$${module}::CURRENT_MINOR_VERSION; + }; + if ($@) { + error(g_("source package format '%s' is not supported: %s"), + $format, $@); } + if ($update_format) { + $self->{format}->set_from_parts($major, $minor, $variant); + $self->{fields}{'Format'} = $self->{format}->get(); + } + + $module->prerequisites() if $module->can('prerequisites'); + bless $self, $module; } =item $p->get_filename() @@ -548,10 +543,7 @@ sub extract { my $format_file = File::Spec->catfile($srcdir, 'format'); unless (-e $format_file) { mkdir($srcdir) unless -e $srcdir; - open(my $format_fh, '>', $format_file) - or syserr(g_('cannot write %s'), $format_file); - print { $format_fh } $self->{fields}{'Format'} . "\n"; - close($format_fh); + $self->{format}->save($format_file); } } diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl index 6a4825d22..2e5f41d31 100755 --- a/scripts/dpkg-source.pl +++ b/scripts/dpkg-source.pl @@ -396,14 +396,10 @@ if ($options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) { # Select the format to use if (not defined $build_format) { - if (-e "$dir/debian/source/format") { - open(my $format_fh, '<', "$dir/debian/source/format") - or syserr(g_('cannot read %s'), "$dir/debian/source/format"); - $build_format = <$format_fh>; - chomp($build_format) if defined $build_format; - error(g_('%s is empty'), "$dir/debian/source/format") - unless defined $build_format and length $build_format; - close($format_fh); + my $format_file = "$dir/debian/source/format"; + if (-e $format_file) { + my $format = Dpkg::Source::Format->new(filename => $format_file); + $build_format = $format->get(); } else { warning(g_('no source format specified in %s, ' . 'see dpkg-source(1)'), 'debian/source/format') -- Dpkg.Org's dpkg

