This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=e671160c6823815c07b40137eb846fd930b33201

commit e671160c6823815c07b40137eb846fd930b33201
Author: Guillem Jover <[email protected]>
AuthorDate: Fri Dec 19 23:38:04 2025 +0100

    Dpkg::Version: Add new has_epoch() and has_revision() methods
    
    The class keeps track of whether the epoch and revision were present
    when the string got parsed, but because at least for the revision
    the revision method will return 0 even when there was no revision,
    adding introspecting methods helps analyze the version object.
    
    Closes: #1123630
---
 scripts/Dpkg/Source/Package/V1.pm        |  8 +++----
 scripts/Dpkg/Source/Package/V2.pm        |  4 ++--
 scripts/Dpkg/Source/Package/V3/Native.pm |  4 ++--
 scripts/Dpkg/Version.pm                  | 40 ++++++++++++++++++++++++--------
 scripts/t/Dpkg_Version.t                 | 19 +++++++++------
 5 files changed, 50 insertions(+), 25 deletions(-)

diff --git a/scripts/Dpkg/Source/Package/V1.pm 
b/scripts/Dpkg/Source/Package/V1.pm
index e53415cd9..1a86fe122 100644
--- a/scripts/Dpkg/Source/Package/V1.pm
+++ b/scripts/Dpkg/Source/Package/V1.pm
@@ -208,7 +208,7 @@ sub do_extract {
         if ($tarfile =~ m/\.orig\.tar\.gz$/) {
             # We only need to warn on this branch, because of the $native reset
             # below, otherwise the V3::Native module will handle the warning.
-            if (! $v->__is_native()) {
+            if ($v->has_revision()) {
                 warning(g_('native package version may not have a revision'));
             }
 
@@ -217,7 +217,7 @@ sub do_extract {
             $native = 0;
         }
     } else {
-        if ($v->__is_native()) {
+        if (! $v->has_revision()) {
             warning(g_('non-native package version does not contain a 
revision'))
         }
     }
@@ -385,9 +385,9 @@ sub do_build {
     my $v = Dpkg::Version->new($self->{fields}->{'Version'});
     if ($sourcestyle =~ m/[kpursKPUR]/) {
         error(g_('non-native package version does not contain a revision'))
-            if $v->__is_native();
+            if ! $v->has_revision();
     } else {
-        if (! $v->__is_native) {
+        if ($v->has_revision()) {
             if (run_vendor_hook('has-fuzzy-native-source')) {
                 warning(g_('native package version may not have a revision'));
             } else {
diff --git a/scripts/Dpkg/Source/Package/V2.pm 
b/scripts/Dpkg/Source/Package/V2.pm
index fd9fabbb9..053dddae1 100644
--- a/scripts/Dpkg/Source/Package/V2.pm
+++ b/scripts/Dpkg/Source/Package/V2.pm
@@ -219,7 +219,7 @@ sub do_extract {
     }
 
     my $v = Dpkg::Version->new($fields->{'Version'});
-    if ($v->__is_native()) {
+    if (! $v->has_revision()) {
         warning(g_('non-native package version does not contain a revision'))
     }
 
@@ -371,7 +371,7 @@ sub can_build {
 
     my $v = Dpkg::Version->new($self->{fields}->{'Version'});
     return (0, g_('non-native package version does not contain a revision'))
-        if $v->__is_native();
+        if ! $v->has_revision();
 
     return 1 if $self->find_original_tarballs(include_supplementary => 0);
     return 1 if $self->{options}{create_empty_orig} and
diff --git a/scripts/Dpkg/Source/Package/V3/Native.pm 
b/scripts/Dpkg/Source/Package/V3/Native.pm
index 0739c4afd..73679ffe5 100644
--- a/scripts/Dpkg/Source/Package/V3/Native.pm
+++ b/scripts/Dpkg/Source/Package/V3/Native.pm
@@ -71,7 +71,7 @@ sub do_extract {
     error(g_('no tarfile in Files field')) unless $tarfile;
 
     my $v = Dpkg::Version->new($fields->{'Version'});
-    if (! $v->__is_native()) {
+    if ($v->has_revision()) {
         warning(g_('native package version may not have a revision'));
     }
 
@@ -92,7 +92,7 @@ sub can_build {
     my ($self, $dir) = @_;
 
     my $v = Dpkg::Version->new($self->{fields}->{'Version'});
-    if (! $v->__is_native()) {
+    if ($v->has_revision()) {
         if (run_vendor_hook('has-fuzzy-native-source')) {
             warning(g_('native package version may not have a revision'));
         } else {
diff --git a/scripts/Dpkg/Version.pm b/scripts/Dpkg/Version.pm
index c1e489f41..894268a8a 100644
--- a/scripts/Dpkg/Version.pm
+++ b/scripts/Dpkg/Version.pm
@@ -32,7 +32,7 @@ them.
 
 =cut
 
-package Dpkg::Version 1.04;
+package Dpkg::Version 1.05;
 
 use v5.36;
 
@@ -192,7 +192,8 @@ source package format can end up having a non-native 
version, adding
 to the confusion of the whole concept. And while this method would
 be fine to be used on vendors that have a coherent native source concept,
 this is not a pattern that will be portably relied on. Thus this method
-is being deprecated.
+is being deprecated. Depending on the context, using the $v->has_revision()
+method might be sensible.
 
 =cut
 
@@ -201,16 +202,31 @@ sub is_native {
     warnings::warnif('deprecated',
         'using Dpkg::Version->is_native() has been made incoherent and ' .
         'confusing on some dpkg vendors; it is deprecated as not having ' .
-        'portable semantics anymore');
-    return $self->__is_native();
+        'portable semantics anymore; depending on the context, using ' .
+        'has_revsion() might be sensible');
+    return ! $self->has_revision();
 }
 
-# Internal symbol for dpkg project use only, no API guarantees provided.
-# While a new method could be provided such as has_revision() (and
-# has_epoch()), the intent and semantics would be similar.
-sub __is_native {
-    my $self = shift;
-    return $self->{no_revision};
+=item $v->has_epoch()
+
+Returns true if the version has an epoch, false otherwise.
+
+=cut
+
+sub has_epoch($self)
+{
+    return ! $self->{no_epoch};
+}
+
+=item $v->has_revision()
+
+Returns true if the version has a revision, false otherwise.
+
+=cut
+
+sub has_revision($self)
+{
+    return ! $self->{no_revision};
 }
 
 =item $v1 <=> $v2, $v1 < $v2, $v1 <= $v2, $v1 > $v2, $v1 >= $v2
@@ -503,6 +519,10 @@ sub version_check {
 
 =head1 CHANGES
 
+=head2 Version 1.05 (dpkg 1.23.3)
+
+New methods: $v->has_epoch(), $v->has_revision().
+
 =head2 Version 1.04 (dpkg 1.23.0)
 
 Deprecated method: $v->is_native().
diff --git a/scripts/t/Dpkg_Version.t b/scripts/t/Dpkg_Version.t
index 3435b2414..227a8502e 100644
--- a/scripts/t/Dpkg_Version.t
+++ b/scripts/t/Dpkg_Version.t
@@ -15,7 +15,7 @@
 
 use v5.36;
 
-use Test::More tests => 1747;
+use Test::More tests => 1752;
 
 use IPC::Cmd qw(can_run);
 
@@ -122,17 +122,22 @@ ok(! $ver->is_valid(), 'version does not start with digit 
1/2');
 $ver = Dpkg::Version->new('0:foo5.2');
 ok(! $ver->is_valid(), 'version does not start with digit 2/2');
 
-# Native and non-native versions.
+# Upstream versions with revision and without.
 $ver = Dpkg::Version->new('1.0');
-ok($ver->__is_native(), 'upstream version is native');
+ok(! $ver->has_epoch(), 'upstream version does not have epoch');
+ok(! $ver->has_revision(), 'upstream version does not have revision');
 $ver = Dpkg::Version->new('1:1.0');
-ok($ver->__is_native(), 'upstream version w/ epoch is native');
+ok($ver->has_epoch(), 'upstream version w/ epoch has epoch');
+ok(! $ver->has_revision(), 'upstream version w/ epoch does not have revision');
 $ver = Dpkg::Version->new('1:1.0:1.0');
-ok($ver->__is_native(), 'upstream version w/ epoch and colon is native');
+ok($ver->has_epoch(), 'upstream version w/ epoch and colon has epoch');
+ok(! $ver->has_revision(), 'upstream version w/ epoch and colon does not have 
revision');
 $ver = Dpkg::Version->new('1.0-1');
-ok(! $ver->__is_native(), 'upstream version w/ revision is not native');
+ok(! $ver->has_epoch(), 'upstream version w/ revision does not have epoch');
+ok($ver->has_revision(), 'upstream version w/ revision has revision');
 $ver = Dpkg::Version->new('1.0-1.0-1');
-ok(! $ver->__is_native(), 'upstream version w/ dash and revision is not 
native');
+ok(! $ver->has_epoch(), 'upstream version w/ dash and revision does not have 
epoch');
+ok($ver->has_revision(), 'upstream version w/ dash and revision has revision');
 
 # Comparisons.
 foreach my $case (@tests) {

-- 
Dpkg.Org's dpkg

Reply via email to