]> git.donarmstrong.com Git - debbugs.git/commitdiff
* Add sort_versions routine
authorDon Armstrong <don@donarmstrong.com>
Tue, 4 May 2010 02:22:55 +0000 (19:22 -0700)
committerDon Armstrong <don@donarmstrong.com>
Tue, 4 May 2010 02:22:55 +0000 (19:22 -0700)
 * Add largest_source_version_only option to get_versions; make it the
   default to cope with multiple source versions in a distribution
   (suite).

Debbugs/Common.pm
Debbugs/Control.pm
Debbugs/Packages.pm

index 9760912a6445e1a2e0c848e7b0509cab790e0c0e..ef1b8bbe96cb75e746ed00be5fd52b0b620a97f1 100644 (file)
@@ -44,6 +44,7 @@ BEGIN{
                                qw(getmaintainers_reverse),
                                qw(getpseudodesc),
                                qw(package_maintainer),
+                               qw(sort_versions),
                               ],
                     misc   => [qw(make_list globify_scalar english_join checkpid),
                                qw(cleanup_eval_fail),
@@ -446,6 +447,33 @@ sub getpseudodesc {
     return $_pseudodesc;
 }
 
+=head2 sort_versions
+
+     sort_versions('1.0-2','1.1-2');
+
+Sorts versions using AptPkg::Versions::compare if it is available, or
+Debbugs::Versions::Dpkg::vercmp if it isn't.
+
+=cut
+
+our $vercmp;
+BEGIN{
+    use Debbugs::Versions::Dpkg;
+    $vercmp=\&Debbugs::Versions::Dpkg::vercmp;
+
+# eventually we'll use AptPkg:::Version or similar, but the current
+# implementation makes this *super* difficult.
+
+#     eval {
+#      use AptPkg::Version;
+#      $vercmp=\&AptPkg::Version::compare;
+#     };
+}
+
+sub sort_versions{
+    return sort {$vercmp->($a,$b)} @_;
+}
+
 
 =head1 DATE
 
index d994170bb0f24fa6c5f72cd525ebb505556f64a2..4ec2a101ae878272f90646d489acbfeb5e7ecd15 100644 (file)
@@ -106,7 +106,7 @@ BEGIN{
 }
 
 use Debbugs::Config qw(:config);
-use Debbugs::Common qw(:lock buglog :misc get_hashname);
+use Debbugs::Common qw(:lock buglog :misc get_hashname sort_versions);
 use Debbugs::Status qw(bug_archiveable :read :hook writebug splitpackages split_status_fields get_bug_status);
 use Debbugs::CGI qw(html_escape);
 use Debbugs::Log qw(:misc);
@@ -1422,11 +1422,11 @@ sub set_found {
                # We only care about reopening the bug if the bug is
                # not done
                if (defined $data->{done} and length $data->{done}) {
-                   my @svers_order = sort {Debbugs::Versions::Dpkg::vercmp($a,$b);}
-                       map {m{([^/]+)$}; $1;} @svers;
+                   my @svers_order = sort_versions(map {m{([^/]+)$}; $1;}
+                                                   @svers);
                    # determine if we need to reopen
-                   my @fixed_order = sort {Debbugs::Versions::Dpkg::vercmp($a,$b);}
-                       map {m{([^/]+)$}; $1;} keys %fixed_versions;
+                   my @fixed_order = sort_versions(map {m{([^/]+)$}; $1;}
+                                                   keys %fixed_versions);
                    if (not @fixed_order or
                        (Debbugs::Versions::Dpkg::vercmp($svers_order[-1],$fixed_order[-1]) >= 0)) {
                        $reopened = 1;
index b4b5ef7411fa18e821a4c5244a2a246506e1249d..5c4d22367d78a7eb66f0156109b9d54969fe0478 100644 (file)
@@ -37,7 +37,7 @@ use Fcntl qw(O_RDONLY);
 use MLDBM qw(DB_File Storable);
 use Storable qw(dclone);
 use Params::Validate qw(validate_with :types);
-use Debbugs::Common qw(make_list globify_scalar);
+use Debbugs::Common qw(make_list globify_scalar sort_versions);
 
 use List::Util qw(min max);
 
@@ -393,6 +393,11 @@ may change in the future, so if you care, please code accordingly.)
 =item return_archs -- returns a version=>[archs] hash indicating which
 architectures are at which versions.
 
+=item largest_source_version_only -- if there is more than one source
+version in a particular distribution, discards all versions but the
+largest in that distribution. Defaults to 1, as this used to be the
+way that the Debian archive worked.
+
 =back
 
 When called in scalar context, this function will return hashrefs or
@@ -426,6 +431,9 @@ sub get_versions{
                                           return_archs => {type => BOOLEAN,
                                                            default => 0,
                                                           },
+                                          largest_source_version_only => {type => BOOLEAN,
+                                                                      default => 1,
+                                                                         },
                                          },
                               );
      my $versions;
@@ -460,10 +468,16 @@ sub get_versions{
                                        $_ ne 'source'
                                    } $source_only?'source':keys %{$version->{$dist}})) {
                    next unless defined $version->{$dist}{$arch};
-                   for my $ver (ref $version->{$dist}{$arch} ?
-                                keys %{$version->{$dist}{$arch}} :
-                                $version->{$dist}{$arch}
-                               ) {
+                   my @vers = ref $version->{$dist}{$arch} eq 'HASH' ?
+                       keys %{$version->{$dist}{$arch}} :
+                           make_list($version->{$dist}{$arch});
+                   if ($param{largest_source_version_only} and
+                       $arch eq 'source' and @vers > 1) {
+                       # order the versions, then pick the biggest version number
+                       @vers = sort_versions(@vers);
+                       @vers = $vers[-1];
+                   }
+                   for my $ver (@vers) {
                         my $f_ver = $ver;
                         if ($param{source}) {
                              ($f_ver) = make_source_versions(package => $package,