[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH v2] Dpkg::Version, Dpkg::Source::Package: move version-without-epoch outputting to the Version module



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.
---
 scripts/Dpkg/Source/Package.pm |    6 +-----
 scripts/Dpkg/Version.pm        |   14 +++++++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

* Guillem Jover <guillem@debian.org> [130209 18:43]:
> On Sat, 2013-02-09 at 15:18:04 +0100, Guillem Jover wrote:
> > On Sat, 2013-02-09 at 15:03:31 +0100, Bernhard R. Link wrote:
> > > 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.
> >
> > I like the idea, but I'd prefer the function to take a bitwise single
> > flag argument instead, with proper constants.
>
> Err, being this perl, an options hash argument would do even better.

how about this one?

diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm
index 47ea319..aff0eed 100644
--- a/scripts/Dpkg/Source/Package.pm
+++ b/scripts/Dpkg/Source/Package.pm
@@ -289,11 +289,7 @@ 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;
+    return $f->{'Source'} . "_" . $v->as_string({no_epoch=>1, no_revision=>!$with_revision});
 }
 
 sub find_original_tarballs {
diff --git a/scripts/Dpkg/Version.pm b/scripts/Dpkg/Version.pm
index 7c1c0f6..19c4509 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;
@@ -177,18 +177,22 @@ sub comparison {
     return version_compare_part($a->revision(), $b->revision());
 }
 
-=item "$v", $v->as_string()
+=item "$v", $v->as_string(), $v->as_string({no_epoch=>1, no_revision=>1})
 
 Returns the string representation of the version number.
 
 =cut
 
 sub as_string {
-    my ($self) = @_;
+    my ($self, $arg_ref) = @_;
+    my $no_epoch = $arg_ref->{no_epoch} || '';
+    $no_epoch ||= $self->{no_epoch};
+    my $no_revision = $arg_ref->{no_revision} || '';
+    $no_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;
 }
 
-- 
1.7.10.4


Reply to: