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

[SCM] Debian package checker branch, master, updated. 2.2.10-65-gb930777



The following commit has been merged in the master branch:
commit 7eed89ba8fed6aa313bd45db4752952d9077f916
Author: Adam D. Barratt <adam@adam-barratt.org.uk>
Date:   Fri May 29 19:04:40 2009 +0100

    Use libapt-pkg-perl for version comparison instead of forking dpkg
    
    * debian/control:
      + [ADB] Depend on libapt-pkg-perl.
    * lib/Lintian/Relation/Version.pm:
      + [ADB] Rework to use libapt-pkg-perl rather than calling "dpkg
        --compare-versions" repeatedly and keeping a potentially large
        cache of previous results.

diff --git a/debian/changelog b/debian/changelog
index 4e24d8e..888ad90 100755
--- a/debian/changelog
+++ b/debian/changelog
@@ -67,6 +67,8 @@ lintian (2.2.11) UNRELEASED; urgency=low
   * data/files/fonts:
     + [ADB] Refresh against unstable.
 
+  * debian/control:
+    + [ADB] Depend on libapt-pkg-perl.
   * debian/rules:
     + [ADB] Re-order the commands in the runtests target so that the
       "new style" testset is run first, as it now also tests the harness.
@@ -82,6 +84,10 @@ lintian (2.2.11) UNRELEASED; urgency=low
       tests so that tar's "implausibly old timestamp" errors use a
       consistent epoch.  Thanks, Raphael Geissert.
 
+  * lib/Lintian/Relation/Version.pm:
+    + [ADB] Rework to use libapt-pkg-perl rather than calling "dpkg
+      --compare-versions" repeatedly and keeping a potentially large
+      cache of previous results.
   * lib/scan_script.pl:
     + [RA] Removed.  A start at parsing shell scripts that was never
       finished and wasn't usable in its current form.
diff --git a/debian/control b/debian/control
index b825624..976b29f 100644
--- a/debian/control
+++ b/debian/control
@@ -19,7 +19,7 @@ Architecture: all
 Depends: perl, libdigest-md5-perl | perl (>> 5.8), dpkg-dev (>= 1.13.17),
  file, binutils, diffstat (>= 1.27-1), man-db (>= 2.4.0), gettext (>= 0.16),
  intltool-debian, libdigest-sha-perl, libparse-debianchangelog-perl (>= 0.6),
- libtimedate-perl, liburi-perl, libipc-run-perl
+ libtimedate-perl, liburi-perl, libipc-run-perl, libapt-pkg-perl
 Suggests: binutils-multiarch, libtext-template-perl, man-db (>= 2.5.1-1)
 Description: Debian package checker
  Lintian dissects Debian packages and reports bugs and policy
diff --git a/lib/Lintian/Relation/Version.pm b/lib/Lintian/Relation/Version.pm
index 96b4a4b..f69a539 100644
--- a/lib/Lintian/Relation/Version.pm
+++ b/lib/Lintian/Relation/Version.pm
@@ -3,6 +3,7 @@
 
 # Copyright (C) 1998 Christian Schwarz and Richard Braakman
 # Copyright (C) 2004-2009 Russ Allbery <rra@debian.org>
+# Copyright (C) 2009 Adam D. Barratt <adam@adam-barratt.org.uk>
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by the Free
@@ -24,17 +25,14 @@ use warnings;
 
 use Carp qw(croak);
 
-use Lintian::Command qw(spawn);
-
 use base 'Exporter';
 BEGIN {
     our @EXPORT = qw(versions_equal versions_lte versions_gte versions_lt
                      versions_gt versions_compare);
 }
 
-# We save a cache of every version comparison we've done so that we don't have
-# to fork dpkg again if the same comparison comes up.
-our %CACHE;
+use AptPkg::Config '$_config';
+my $versioning = $_config->system->versioning;
 
 =head1 NAME
 
@@ -52,9 +50,8 @@ Lintian::Relation::Version - Comparison operators on Debian versions
 =head1 DESCRIPTION
 
 This module provides five functions for comparing version numbers.  The
-underlying implementation uses C<dpkg --compare-versions> to ensure that
-the results match what dpkg will expect.  All comparisons are cached so
-that we do not fork B<dpkg> again if we see the same comparison.
+underlying implementation uses C<libapt-pkg-perl> to ensure that
+the results match what dpkg will expect.
 
 =head1 FUNCTIONS
 
@@ -71,21 +68,10 @@ sub versions_equal {
     my $result;
 
     return 1 if $p eq $q;
-    return 1 if $CACHE{"$p == $q"};
-    return 1 if $CACHE{"$p <= $q"} and $CACHE{"$p >= $q"};
-    return 0 if $CACHE{"$p != $q"};
-    return 0 if $CACHE{"$p << $q"};
-    return 0 if $CACHE{"$p >> $q"};
-
-    $result = compare($p, 'eq', $q);
-
-    if ($result) {
-        $CACHE{"$p == $q"} = 1;
-    } else {
-        $CACHE{"$p != $q"} = 1;
-    }
 
-    return $result;
+    $result = $versioning->compare($p, $q);
+    
+    return ($result == 0);
 }
 
 =item versions_lte(A, B)
@@ -100,21 +86,10 @@ sub versions_lte {
     my $result;
 
     return 1 if $p eq $q;
-    return 1 if $CACHE{"$p <= $q"};
-    return 1 if $CACHE{"$p == $q"};
-    return 1 if $CACHE{"$p << $q"};
-    return 0 if $CACHE{"$p >> $q"};
-    return 0 if $CACHE{"$p >= $q"} and $CACHE{"$p != $q"};
 
-    $result = compare($p, 'le', $q);
+    $result = $versioning->compare($p, $q);
 
-    if ($result) {
-        $CACHE{"$p <= $q"} = 1;
-    } else {
-        $CACHE{"$p >> $q"} = 1;
-    }
-
-    return $result;
+    return ($result <= 0);
 }
 
 =item versions_gte(A, B)
@@ -129,21 +104,10 @@ sub versions_gte {
     my $result;
 
     return 1 if $p eq $q;
-    return 1 if $CACHE{"$p >= $q"};
-    return 1 if $CACHE{"$p == $q"};
-    return 1 if $CACHE{"$p >> $q"};
-    return 0 if $CACHE{"$p << $q"};
-    return 0 if $CACHE{"$p <= $q"} and $CACHE{"$p != $q"};
-
-    $result = compare($p, 'ge', $q);
 
-    if ($result) {
-        $CACHE{"$p >= $q"} = 1;
-    } else {
-        $CACHE{"$p << $q"} = 1;
-    }
+    $result = $versioning->compare($p, $q);
 
-    return $result;
+    return ($result >= 0);
 }
 
 =item versions_lt(A, B)
@@ -157,21 +121,10 @@ sub versions_lt {
     my $result;
 
     return 0 if $p eq $q;
-    return 1 if $CACHE{"$p << $q"};
-    return 0 if $CACHE{"$p == $q"};
-    return 0 if $CACHE{"$p >= $q"};
-    return 0 if $CACHE{"$p >> $q"};
-    return 1 if $CACHE{"$p <= $q"} and $CACHE{"$p != $q"};
-
-    $result = compare($p, 'lt', $q);
 
-    if ($result) {
-        $CACHE{"$p << $q"} = 1;
-    } else {
-        $CACHE{"$p >= $q"} = 1;
-    }
+    $result = $versioning->compare($p, $q);
 
-    return $result;
+    return ($result < 0);
 }
 
 =item versions_gt(A, B)
@@ -185,21 +138,10 @@ sub versions_gt {
     my $result;
 
     return 0 if $p eq $q;
-    return 1 if $CACHE{"$p >> $q"};
-    return 0 if $CACHE{"$p == $q"};
-    return 0 if $CACHE{"$p <= $q"};
-    return 0 if $CACHE{"$p << $q"};
-    return 1 if $CACHE{"$p >= $q"} and $CACHE{"$p != $q"};
 
-    $result = compare($p, 'gt', $q);
+    $result = $versioning->compare($p, $q);
 
-    if ($result) {
-        $CACHE{"$p >> $q"} = 1;
-    } else {
-        $CACHE{"$p <= $q"} = 1;
-    }
-
-    return $result;
+    return ($result > 0);
 }
 
 =item versions_compare(A, OP, B)
@@ -219,22 +161,12 @@ sub versions_compare {
     else { croak("unknown operator $op") }
 }
 
-# The internal function used to do the comparisons.
-sub compare {
-    return spawn(undef, ['dpkg', '--compare-versions', @_]);
-}
-
 =back
 
-=head1 NOTES
-
-This module can probably be dropped once Dpkg::Version is available on the
-host where lintian.debian.org is generated.  Using Dpkg::Version directly
-will be much more efficient.
-
 =head1 AUTHOR
 
-Originally written by Russ Allbery <rra@debian.org> for Lintian.
+Originally written by Russ Allbery <rra@debian.org> for Lintian and adapted
+to use libapt-pkg-perl by Adam D. Barratt <adam@adam-barratt-org.uk>.
 
 =head1 SEE ALSO
 

-- 
Debian package checker


Reply to: