Просмотр исходного кода

Dpkg: Move epoch-less or revision-less output logic to Dpkg::Version

Instead of doing the magic of generating a version string without epoch
and revision and a version string without epoch in Dpkg::Source::Package,
extend Dpkg::Version's as_string function to support generating that
string.

Based-on-patch-by: Bernhard R. Link <brlink@debian.org>
Signed-off-by: Guillem Jover <guillem@debian.org>
Guillem Jover лет назад: 13
Родитель
Сommit
ea422eb864
3 измененных файлов с 35 добавлено и 11 удалено
  1. 2 0
      debian/changelog
  2. 2 5
      scripts/Dpkg/Source/Package.pm
  3. 31 6
      scripts/Dpkg/Version.pm

+ 2 - 0
debian/changelog

@@ -112,6 +112,8 @@ dpkg (1.17.0) UNRELEASED; urgency=low
     Closes: #689193
   * Add support for a build_arch option in Dpkg::Deps deps_parse().
     Thanks to Colin Watson <cjwatson@ubuntu.com>. Closes: #697297
+  * Move epoch-less or revision-less output logic to Dpkg::Version.
+    Based on a patch by Bernhard R. Link <brlink@debian.org>.
 
   [ Updated programs translations ]
   * Fix typo in Spanish translation of update-alternatives.

+ 2 - 5
scripts/Dpkg/Source/Package.pm

@@ -295,11 +295,8 @@ sub get_basename {
         error(_g('source and version are required to compute the source basename'));
     }
     my $v = Dpkg::Version->new($f->{'Version'});
-    my $basename = $f->{'Source'} . '_' . $v->version();
-    if ($with_revision and $f->{'Version'} =~ /-/) {
-        $basename .= '-' . $v->revision();
-    }
-    return $basename;
+    my $vs = $v->as_string(omit_epoch => 1, omit_revision => !$with_revision);
+    return $f->{'Source'} . '_' . $vs;
 }
 
 sub find_original_tarballs {

+ 31 - 6
scripts/Dpkg/Version.pm

@@ -21,7 +21,7 @@ package Dpkg::Version;
 use strict;
 use warnings;
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 use Dpkg::ErrorHandling;
 use Dpkg::Gettext;
@@ -43,7 +43,7 @@ use constant {
 use overload
     '<=>' => \&comparison,
     'cmp' => \&comparison,
-    '""'  => \&as_string,
+    '""'  => sub { return $_[0]->as_string(); },
     'bool' => sub { return $_[0]->as_string() if $_[0]->is_valid(); },
     'fallback' => 1;
 
@@ -166,18 +166,37 @@ sub comparison {
     return version_compare_part($a->revision(), $b->revision());
 }
 
-=item "$v", $v->as_string()
+=item "$v", $v->as_string(), $v->as_string(%options)
+
+Accepts an optional option hash reference, affecting the string conversion.
+
+Options:
+
+=over 8
+
+=item omit_epoch (defaults to 0)
+
+Omit the epoch, if present, in the output string.
+
+=item omit_revision (defaults to 0)
+
+Omit the revision, if present, in the output string.
+
+=back
 
 Returns the string representation of the version number.
 
 =cut
 
 sub as_string {
-    my ($self) = @_;
+    my ($self, %opts) = @_;
+    my $no_epoch = $opts{omit_epoch} || $self->{no_epoch};
+    my $no_revision = $opts{omit_revision} || $self->{no_revision};
+
     my $str = '';
-    $str .= $self->{epoch} . ':' unless $self->{no_epoch};
+    $str .= $self->{epoch} . ':' unless $no_epoch;
     $str .= $self->{version};
-    $str .= '-' . $self->{revision} unless $self->{no_revision};
+    $str .= '-' . $self->{revision} unless $no_revision;
     return $str;
 }
 
@@ -395,6 +414,12 @@ sub version_check($) {
 
 =back
 
+=head1 CHANGES
+
+=head2 Version 1.01
+
+New argument: Accept an options argument in $v->as_string().
+
 =head1 AUTHOR
 
 Don Armstrong <don@donarmstrong.com>, Colin Watson