The following commit has been merged in the master branch:
commit ea422eb8649dd15a3f5f2994af8e57c7c2e1e465
Author: Guillem Jover <[email protected]>
Date:   Sun Feb 10 13:18:28 2013 +0100

    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 <[email protected]>
    Signed-off-by: Guillem Jover <[email protected]>

diff --git a/debian/changelog b/debian/changelog
index a58d449..caa2a8c 100644
--- a/debian/changelog
+++ b/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 <[email protected]>. Closes: #697297
+  * Move epoch-less or revision-less output logic to Dpkg::Version.
+    Based on a patch by Bernhard R. Link <[email protected]>.
 
   [ Updated programs translations ]
   * Fix typo in Spanish translation of update-alternatives.
diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm
index 6187db4..0d510fb 100644
--- a/scripts/Dpkg/Source/Package.pm
+++ b/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 {
diff --git a/scripts/Dpkg/Version.pm b/scripts/Dpkg/Version.pm
index 38830d9..82a3936 100644
--- a/scripts/Dpkg/Version.pm
+++ b/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 <[email protected]>, Colin Watson

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to