The following commit has been merged in the master branch:
commit 664359dc060e3200fcc6ae7057fd2d50d44cd59b
Author: James Vega <james...@debian.org>
Date:   Wed Jul 27 22:39:33 2011 -0400

    chdist: Use newest binary version, when multiple exist, for 
compare-src-bin-*.
    
    Signed-off-by: James Vega <james...@debian.org>

diff --git a/debian/changelog b/debian/changelog
index da4a08e..6b7b1f4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -21,8 +21,11 @@ devscripts (2.11.1) UNRELEASED; urgency=low
     at the end of the source files.  (Closes: #625620)
   * debuild: Call dpkg-source --before-build/--after-build when emulating
     dpkg-buildpackage.  (Closes: #628481)
-  * chdist: Create /etc/apt/apt.conf.d and /etc/apt/preferences.d in the
-    chdist directory structure.  (Closes: #528274, LP: #566682)
+  * chdist:
+    + Create /etc/apt/apt.conf.d and /etc/apt/preferences.d in the chdist
+      directory structure.  (Closes: #528274, LP: #566682)
+    + When multiple binary versions exist, use newest version for
+      compare-src-bin-*.
 
   [ Christoph Berg ]
   * dscextract: new script, extracts a single file from a Debian source
diff --git a/scripts/chdist.pl b/scripts/chdist.pl
index 398fd8c..33a4591 100755
--- a/scripts/chdist.pl
+++ b/scripts/chdist.pl
@@ -469,102 +469,97 @@ sub dist_compare(\@;$;$) {
 
 
 sub compare_src_bin {
-   my ($dist, $do_compare) = @_;
+    my ($dist, $do_compare) = @_;
 
-   $do_compare = 0 if $do_compare eq 'false';
-
-   dist_check($dist);
-
-
-   # Get all packages
-   my %packages;
-   my @parse_types = ('Sources', 'Packages');
-   my @comp_types  = ('Sources_Bin', 'Packages');
+    dist_check($dist);
 
-   foreach my $type (@parse_types) {
-      my $files = get_distfiles($dist, $type);
-      my @files = @$files;
-      foreach my $file ( @files ) {
-         my $parsed_file = parseFile($file);
-         foreach my $package ( keys(%{$parsed_file}) ) {
-            if ( $packages{$dist}{$package} ) {
-               warn "W: Package $package is already listed for $dist. Not 
overriding.\n";
-            } else {
-               $packages{$type}{$package} = $parsed_file->{$package};
-            }
-         }
-      }
-   }
+    # Get all packages
+    my %packages;
+    my @parse_types = ('Sources', 'Packages');
+    my @comp_types  = ('Sources_Bin', 'Packages');
+
+    foreach my $type (@parse_types) {
+       my $files = get_distfiles($dist, $type);
+       my @files = @$files;
+       foreach my $file ( @files ) {
+           my $parsed_file = parseFile($file);
+           foreach my $package ( keys(%{$parsed_file}) ) {
+               if ( $packages{$dist}{$package} ) {
+                   warn "W: Package $package is already listed for $dist. Not 
overriding.\n";
+               } else {
+                   $packages{$type}{$package} = $parsed_file->{$package};
+               }
+           }
+       }
+    }
 
-   # Build 'Sources_Bin' hash
-   foreach my $package ( keys( %{$packages{Sources}} ) ) {
-      my $package_h = \%{$packages{Sources}{$package}};
-      if ( $package_h->{'Binary'} ) {
-         my @binaries = split(", ", $package_h->{'Binary'});
-         my $version  = $package_h->{'Version'};
-         foreach my $binary (@binaries) {
-            if ( $packages{Sources_Bin}{$binary} ) {
-               # TODO: replace if new version is newer (use dpkg 
--compare-version?)
-               warn "There is already a version for binary $binary. Not 
replacing.\n";
-            } else {
-               $packages{Sources_Bin}{$binary}{Version} = $version;
-            }
-         }
-      } else {
-         warn "Source $package has no binaries!\n";
-      }
-   }
+    # Build 'Sources_Bin' hash
+    foreach my $package ( keys( %{$packages{Sources}} ) ) {
+       my $package_h = \%{$packages{Sources}{$package}};
+       if ( $package_h->{'Binary'} ) {
+           my @binaries = split(", ", $package_h->{'Binary'});
+           my $version  = $package_h->{'Version'};
+           foreach my $binary (@binaries) {
+               if (defined $packages{Sources_Bin}{$binary}) {
+                   my $alt_ver = $packages{Sources_Bin}{$binary}{Version};
+                   # Skip this entry if it's an older version than we already
+                   # have
+                   if (version_compare($version, $alt_ver) < 0) {
+                       next;
+                   }
+               }
+               $packages{Sources_Bin}{$binary}{Version} = $version;
+           }
+       } else {
+           warn "Source $package has no binaries!\n";
+       }
+    }
 
-   # Get entire list of packages
-   my @all_packages = uniq sort ( map { keys(%{$packages{$_}}) } @comp_types );
+    # Get entire list of packages
+    my @all_packages = uniq sort ( map { keys(%{$packages{$_}}) } @comp_types 
);
 
-  foreach my $package (@all_packages) {
-     my $line = "$package ";
-     my $status = "";
-     my $details;
+    foreach my $package (@all_packages) {
+       my $line = "$package ";
+       my $status = "";
+       my $details;
 
-     foreach my $type (@comp_types) {
-        if ( $packages{$type}{$package} ) {
-           $line .= "$packages{$type}{$package}{'Version'} ";
-        } else {
-           $line .= "UNAVAIL ";
-           $status = "not_in_$type";
-        }
-     }
+       foreach my $type (@comp_types) {
+           if ( $packages{$type}{$package} ) {
+               $line .= "$packages{$type}{$package}{'Version'} ";
+           } else {
+               $line .= "UNAVAIL ";
+               $status = "not_in_$type";
+           }
+       }
 
-     my @versions = map { $packages{$_}{$package}{'Version'} } @comp_types;
-     # Escaped versions
-     my @esc_vers = @versions;
-     foreach my $vers (@esc_vers) {
-        $vers =~ s|\+|\\\+|;
-     }
+       my @versions = map { $packages{$_}{$package}{'Version'} } @comp_types;
 
-     # Do compare
-     if ($do_compare) {
-        if ($#comp_types != 1) {
-           die "E: Can only compare versions if there are two types.\n";
-        }
-        if (!$status) {
-          my $cmp = version_compare($versions[0], $versions[1]);
-          if (!$cmp) {
-            $status = "same_version";
-          } 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";
-     }
+       # Do compare
+       if ($do_compare) {
+           if (!@comp_types) {
+               fatal('Can only compare versions if there are two types.');
+           }
+           if (!$status) {
+               my $cmp = version_compare($versions[0], $versions[1]);
+               if (!$cmp) {
+                   $status = "same_version";
+               } elsif ($cmp < 0) {
+                   $status = "newer_in_$comp_types[1]";
+                   if ( $versions[1] =~ m|^\Q$versions[0]\E| ) {
+                       $details = " local_changes_in_$comp_types[1]";
+                   }
+               } else {
+                   $status = "newer_in_$comp_types[0]";
+                   if ( $versions[0] =~ m|^\Q$versions[1]\E| ) {
+                       $details = " local_changes_in_$comp_types[0]";
+                   }
+               }
+           }
+           $line .= " $status $details";
+       }
 
-     print "$line\n";
-  }
+       print "$line\n";
+    }
 }
 
 sub grep_file(\@$)

-- 
Git repository for devscripts


-- 
To unsubscribe, send mail to pkg-devscripts-unsubscr...@teams.debian.net.

Reply via email to