Author: jamessan
Date: 2010-01-11 02:27:07 +0000 (Mon, 11 Jan 2010)
New Revision: 2079

Modified:
   trunk/debian/changelog
   trunk/scripts/chdist.pl
Log:
chdist: Use Dpkg::Version to perform version comparisons.

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog      2010-01-11 02:26:39 UTC (rev 2078)
+++ trunk/debian/changelog      2010-01-11 02:27:07 UTC (rev 2079)
@@ -13,7 +13,9 @@
       known madison URL.
     + Detect an existing '?' in a URL and use '&' to append more cgi
       parameters.  Thanks to Raphael Geissert.
-  * chdist: Add "use strict" and update for compliance.
+  * chdist:
+    + Add "use strict" and update for compliance.
+    + Use Dpkg::Version to perform version comparisons.
 
  -- James Vega <[email protected]>  Sat, 02 Jan 2010 22:30:26 -0500
 

Modified: trunk/scripts/chdist.pl
===================================================================
--- trunk/scripts/chdist.pl     2010-01-11 02:26:39 UTC (rev 2078)
+++ trunk/scripts/chdist.pl     2010-01-11 02:27:07 UTC (rev 2079)
@@ -104,6 +104,7 @@
 use File::Basename;
 use Getopt::Long qw(:config require_order);
 use Cwd qw(abs_path cwd);
+use Dpkg::Version;
 
 my $progname = basename($0);
 
@@ -222,18 +223,6 @@
   return "APT_CONFIG=$datadir/$dist/etc/apt/apt.conf";
 }
 
-sub compare_versions {
-  # Compare two versions
-  my ($va, $vb) = @_;
-  if (!vb) {
-    die "E: Must provide two versions\n";
-  }
-
-  my $test = `/usr/bin/dpkg --compare-versions $va lt $vb && echo 'true' || 
echo 'false'`;
-  chomp $test;
-  return $test;
-}
-
 ###
 
 sub aptcache {
@@ -450,21 +439,19 @@
            die "E: Can only compare versions if there are two distros.\n";
         }
         if (!$status) {
-          if ($versions[0] eq $versions[1]) {
+          my $cmp = version_compare($versions[0], $versions[1]);
+          if (!$cmp) {
             $status = "same_version";
-          } else {
-            $test = compare_versions($versions[0], $versions[1]);
-            if ($test eq 'true') {
-               $status = "newer_in_$dists[1]";
-               if ( $versions[1] =~ m|^$esc_vers[0]| ) {
-                  $details = " local_changes_in_$dists[1]";
-               }
-            } else {
-               $status = "newer_in_$dists[0]";
-               if ( $versions[0] =~ m|^$esc_vers[1]| ) {
-                  $details = " local_changes_in_$dists[0]";
-               }
+          } elsif ($cmp < 0) {
+            $status = "newer_in_$dists[1]";
+            if ( $versions[1] =~ m|^$esc_vers[0]| ) {
+               $details = " local_changes_in_$dists[1]";
             }
+          } else {
+             $status = "newer_in_$dists[0]";
+             if ( $versions[0] =~ m|^$esc_vers[1]| ) {
+                $details = " local_changes_in_$dists[0]";
+             }
           }
         }
         $line .= " $status $details";
@@ -552,21 +539,19 @@
            die "E: Can only compare versions if there are two types.\n";
         }
         if (!$status) {
-          if ($versions[0] eq $versions[1]) {
+          my $cmp = version_compare($versions[0], $versions[1]);
+          if (!$cmp) {
             $status = "same_version";
-          } else {
-            $test = compare_versions($versions[0], $versions[1]);
-            if ($test eq 'true') {
-               $status = "newer_in_$comp_types[1]";
-               if ( $versions[1] =~ m|^$esc_vers[0]| ) {
-                  $details = " local_changes_in_$comp_types[1]";
-               }
-            } else {
-               $status = "newer_in_$comp_types[0]";
-               if ( $versions[0] =~ m|^$esc_vers[1]| ) {
-                  $details = " local_changes_in_$comp_types[0]";
-               }
+          } elsif ($cmp < 0) {
+            $status = "newer_in_$comp_types[1]";
+            if ( $versions[1] =~ m|^$esc_vers[0]| ) {
+               $details = " local_changes_in_$comp_types[1]";
             }
+          } else {
+             $status = "newer_in_$comp_types[0]";
+             if ( $versions[0] =~ m|^$esc_vers[1]| ) {
+                $details = " local_changes_in_$comp_types[0]";
+             }
           }
         }
         $line .= " $status $details";



-- 
To unsubscribe, send mail to [email protected].

Reply via email to