+sub parse_argv() {
+# parts the array $_[0] and $_[1] and returns the sub-array (modifies the original one)
+ my @ret = ();
+ my $args = shift;
+ my $separator = shift;
+ while($args->[0] && $args->[0] ne $separator) {
+ push @ret, shift @$args;
+ }
+ shift @$args if @$args;
+ return @ret;
+}
+
+sub parse_all_v3() {
+ my $srcs = shift;
+ my $db = get_all_source_info();
+ my $binary = $srcs->{'_binary'};
+
+ SRCS:
+ foreach my $name (keys %$srcs) {
+ next if $name eq '_binaries';
+
+ # state = installed, out-of-date, uncompiled, not-for-us
+ my $pkgs = $srcs->{$name};
+ my $pkg = $db->{$name};
+
+ unless ($pkg) {
+ next SRCS if $pkgs->{'status'} eq 'not-for-us';
+
+ # does at least one binary exist in the database and is more recent - if so, we're probably just outdated, ignore the source package
+ for my $bin (@{$pkgs->{'binary'}}) {
+ if ($binary->{$bin} and vercmp($pkgs->{'version'}, $binary->{$bin}) < 0) {
+ print "merge-v3: skiping $name\n" if $verbose;
+ next SRCS;
+ }
+ }
+ }
+
+ if ($pkgs->{'status'} eq 'installed' && $pkg->{'binary_nmu_version'} && $pkgs->{'binnmu'} < $pkg->{'binary_nmu_version'}) {
+ $pkgs->{'status'} = 'out-of-date';
+ }
+ if ($pkgs->{'status'} eq 'installed') {
+ if ($pkg->{'state'} ne 'Installed') {
+ change_state( \$pkg, 'Installed');
+ $pkg->{'version'} = $pkgs->{'version'};
+ $pkg->{'installed_version'} = $pkgs->{'version'};
+ $pkg->{'binary_nmu_version'} = $pkgs->{'binnmu'};
+ $pkg->{'section'} = $pkgs->{'section'};
+ $pkg->{'priority'} = $pkgs->{'priority'};
+ print "should set $name to installed\n" if $simulate;
+ log_ta( $pkg, "--merge-v3: installed" ) unless $simulate;
+ update_source_info($pkg) unless $simulate;
+ }
+ next;
+ }
+
+ if ($pkgs->{'status'} eq 'not-for-us') {
+ next if isin( $pkg->{'state'}, qw(Not-For-Us Installed Failed-Removed));
+
+ if (isin( $pkg->{'state'}, qw(Failed Build-Attempted Built))) {
+ change_state( \$pkg, "Failed-Removed" );
+ log_ta( $pkg, "--merge-v3: Failed-Removed" ) unless $simulate;
+ update_source_info($pkg) unless $simulate;
+ print "$name ($pkg->{'version'}): (virtually) deleted from database\n" if $verbose || $simulate;
+ next;
+ }
+
+ print "should delete $name (not-for-us)\n" if $verbose || $simulate || 1; # not implemented yet on purpose
+ next;
+ }
+
+ # only uncompiled / out-of-date are left, so check if anything new
+ next if $pkgs->{'version'} eq $pkg->{'version'};
+
+ print "should set $name to needs-builds\n" if $simulate;
+ if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
+ send_mail( $pkg->{'builder'},
+ "new version of $name (dist=$distribution)",
+ "As far as I'm informed, you're currently building the package $name\n".
+ "in version $pkg->{'version'}.\n\n".
+ "Now there's a new source version $pkgs->{'version'}. If you haven't finished\n".
+ "compiling $name yet, you can stop it to save some work.\n".
+ "Just to inform you...\n".
+ "(This is an automated message)\n" ) unless $simulate;
+ print "$name: new version ($pkgs->{'version'}) while building $pkg->{'version'} -- sending mail to builder ($pkg->{'builder'})\n"
+ if $verbose || $simulate;
+ }
+ change_state( \$pkg, 'Needs-Build');
+ $pkg->{'notes'} = $pkgs->{'status'};
+ $pkg->{'version'} = $pkgs->{'version'};
+ $pkg->{'section'} = $pkgs->{'section'};
+ $pkg->{'priority'} = $pkgs->{'priority'};
+ $pkg->{'dep'} = $pkgs->{'depends'};
+ $pkg->{'conf'} = $pkgs->{'conflicts'};
+ delete $pkg->{'builder'};
+ delete $pkg->{'binary_nmu_version'};
+ delete $pkg->{'binary_nmu_changelog'};
+ log_ta( $pkg, "--merge-v3: needs-build" ) unless $simulate;
+ update_source_info($pkg) unless $simulate;
+ print "$name ($pkgs->{'version'}) needs rebuilding now.\n" if $verbose || $simulate;
+ }
+
+ foreach my $name (keys %$db) {
+ next if $srcs->{$name};
+ my $pkg = $db->{$name};
+ # package disappeared - delete
+ change_state( \$pkg, 'deleted' );
+ log_ta( $pkg, "--merge-v3: deleted" ) unless $simulate;
+ print "$name ($pkg->{'version'}): deleted from database\n" if $verbose || $simulate;
+ del_source_info($name) unless $simulate;
+ delete $db->{$name};
+ }
+}