Przeglądaj źródła

Dpkg::Deps: tweak the comparison algorithm to sort > lower than <

* scripts/Dpkg/Deps.pm: Add a compare function that compares
dependencies more intelligently than a comparison on their
string representation. In particular we want >= and >> to sort
lower than << and <= so that intervals are nicely displayed
as "a (>= 1), a (<< 2)" instead of the ugly "a (<< 2), a (>= 1)".
Raphael Hertzog 18 lat temu
rodzic
commit
c6c756d559
3 zmienionych plików z 53 dodań i 4 usunięć
  1. 8 0
      ChangeLog
  2. 3 0
      debian/changelog
  3. 42 4
      scripts/Dpkg/Deps.pm

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2007-12-11  Raphael Hertzog  <hertzog@debian.org>
+
+	* scripts/Dpkg/Deps.pm: Add a compare function that compares
+	dependencies more intelligently than a comparison on their
+	string representation. In particular we want >= and >> to sort
+	lower than << and <= so that intervals are nicely displayed
+	as "a (>= 1), a (<< 2)" instead of the ugly "a (<< 2), a (>= 1)".
+
 2007-12-10  Raphael Hertzog  <hertzog@debian.org>
 
 	* README.translators: Explain how to format Git commit messages.

+ 3 - 0
debian/changelog

@@ -26,6 +26,9 @@ dpkg (1.14.13) UNRELEASED; urgency=low
     -lm. Closes: #454616
   * Included files in symbols files (via #include) do no more need to repeat
     the header line. Closes: #455260
+  * Tweak the sort algorithm between dependencies so that intervals
+    are displayed as "a (>= 1), a (<< 2)" instead of the opposite.
+    Closes: #455520
 
   [ Updated man pages translations ]
   * Swedish (Peter Karlsson)

+ 42 - 4
scripts/Dpkg/Deps.pm

@@ -74,7 +74,8 @@ use Dpkg::ErrorHandling qw(warning);
 use Dpkg::Gettext;
 
 our @ISA = qw(Exporter);
-our @EXPORT_OK = qw(@pkg_dep_fields @src_dep_fields %dep_field_type);
+our @EXPORT_OK = qw(@pkg_dep_fields @src_dep_fields %dep_field_type
+		    %relation_ordering);
 
 # Some generic variables
 our @pkg_dep_fields = qw(Pre-Depends Depends Recommends Suggests Enhances
@@ -97,6 +98,15 @@ our %dep_field_type = (
 	'Build-Conflicts-Indep' => 'union',
 );
 
+our %relation_ordering = (
+	'undef' => 0,
+	'>=' => 1,
+	'>>' => 2,
+	'=' => 3,
+	'<<' => 4,
+	'<=' => 5,
+);
+
 # Some factorized function
 
 =item Dpkg::Deps::arch_is_superset(\@p, \@q)
@@ -285,8 +295,6 @@ this when parsing non-dependency fields like Conflicts (see
 
 =back
 
-=back
-
 =cut
 sub parse {
     my $dep_line = shift;
@@ -331,6 +339,36 @@ sub parse {
     return $dep_and;
 }
 
+=item Dpkg::Deps::compare($a, $b)
+
+This functions is used to order AND and Union dependencies prior to
+dumping.
+
+=back
+
+=cut
+sub compare {
+    my ($a, $b) = @_;
+    return -1 if $a->is_empty();
+    return 1 if $b->is_empty();
+    while ($a->isa('Dpkg::Deps::Multiple')) {
+	return -1 if $a->is_empty();
+	my @deps = $a->get_deps();
+	$a = $deps[0];
+    }
+    while ($b->isa('Dpkg::Deps::Multiple')) {
+	return 1 if $b->is_empty();
+	my @deps = $b->get_deps();
+	$b = $deps[0];
+    }
+    my $ar = defined($a->{relation}) ? $a->{relation} : "undef";
+    my $br = defined($b->{relation}) ? $b->{relation} : "undef";
+    return (($a->{package} cmp $b->{package}) ||
+	    ($relation_ordering{$ar} <=> $relation_ordering{$br}) ||
+	    ($a->{version} cmp $b->{version}));
+}
+
+
 package Dpkg::Deps::Simple;
 
 =head1 OBJECTS - Dpkg::Deps::*
@@ -762,7 +800,7 @@ sub get_deps {
 sub sort {
     my $self = shift;
     my @res = ();
-    @res = sort { $a->dump() cmp $b->dump() } @{$self->{list}};
+    @res = sort { Dpkg::Deps::compare($a, $b) } @{$self->{list}};
     $self->{list} = [ @res ];
 }