=== modified file 'apt-pkg/algorithms.cc'
--- apt-pkg/algorithms.cc	2010-11-10 11:24:48 +0000
+++ apt-pkg/algorithms.cc	2010-11-29 20:43:07 +0000
@@ -374,6 +374,13 @@
 {
    pkgDepCache::ActionGroup group(Cache);
 
+   /* Upgrade all installed packages first without autoinst to help the resolver
+      in versioned or-groups to upgrade the old solver instead of installing
+      a new one (if the old solver is not the first one [anymore]) */
+   for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
+      if (I->CurrentVer != 0)
+	 Cache.MarkInstall(I, false, 0, false);
+
    /* Auto upgrade all installed packages, this provides the basis 
       for the installation */
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)

=== modified file 'debian/changelog'
--- debian/changelog	2010-11-27 15:18:27 +0000
+++ debian/changelog	2010-11-29 20:43:07 +0000
@@ -6,7 +6,13 @@
       will actually test uncompressed indexes regardless of the internal
       default value of Acquire::GzipIndexes.
 
- -- Michael Vogt <mvo@debian.org>  Thu, 25 Nov 2010 16:08:01 +0100
+  [ David Kalnischkies ]
+  * apt-pkg/algorithms.cc:
+    - mark all installed packages first without auto installation in
+      a dist-upgrade to prefer upgrading packages instead of installing
+      new packages in versioned or-groups (Closes: #605394)
+
+ -- David Kalnischkies <kalnischkies@gmail.com>  Mon, 29 Nov 2010 21:41:56 +0100
 
 apt (0.8.9) unstable; urgency=low
 

=== added file 'test/integration/Packages-bug-605394-versioned-or-groups'
--- test/integration/Packages-bug-605394-versioned-or-groups	1970-01-01 00:00:00 +0000
+++ test/integration/Packages-bug-605394-versioned-or-groups	2010-11-29 20:43:07 +0000
@@ -0,0 +1,71 @@
+Package: apache2-mpm-prefork
+Priority: optional
+Section: httpd
+Installed-Size: 68
+Maintainer: Debian Apache Maintainers <debian-apache@lists.debian.org>
+Architecture: i386
+Source: apache2
+Version: 2.2.16-4
+Provides: apache2-mpm
+Conflicts: apache2-mpm
+Filename: pool/main/a/apache2/apache2-mpm-prefork_2.2.16-4_i386.deb
+Size: 2276
+MD5Sum: c0db3e637052e59dbdb2fa08f4cdcea4
+Description: Apache HTTP Server - traditional non-threaded model
+Task: web-server
+
+Package: apache2-mpm-worker
+Priority: optional
+Section: httpd
+Installed-Size: 68
+Maintainer: Debian Apache Maintainers <debian-apache@lists.debian.org>
+Architecture: i386
+Source: apache2
+Version: 2.2.16-4
+Provides: apache2-mpm
+Conflicts: apache2-mpm
+Filename: pool/main/a/apache2/apache2-mpm-worker_2.2.16-4_i386.deb
+Size: 2220
+MD5Sum: 71bccda875aa0afac700410b951370ba
+Description: Apache HTTP Server - high speed threaded model
+
+Package: libapache2-mod-php5
+Priority: optional
+Section: httpd
+Installed-Size: 7588
+Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
+Architecture: i386
+Source: php5
+Version: 5.3.3-4
+Depends: apache2-mpm-prefork (>> 2.0.52)
+Filename: pool/main/p/php5/libapache2-mod-php5_5.3.3-4_i386.deb
+Size: 2886980
+MD5Sum: b41ec4b98aa08966288570e07cd864ab
+Description: server-side, HTML-embedded scripting language (Apache 2 module)
+Task: web-server
+
+Package: php5-cgi
+Priority: optional
+Section: php
+Installed-Size: 14672
+Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
+Architecture: i386
+Source: php5
+Version: 5.3.3-4
+Filename: pool/main/p/php5/php5-cgi_5.3.3-4_i386.deb
+Size: 5713726
+MD5Sum: 9e579982032c7bb98508e16e314f45e9
+Description: server-side, HTML-embedded scripting language (CGI binary)
+
+Package: php5
+Priority: optional
+Section: php
+Installed-Size: 20
+Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
+Architecture: all
+Version: 5.3.3-4
+Depends: libapache2-mod-php5 (>= 5.3.3-4) | php5-cgi (>= 5.3.3-4)
+Filename: pool/main/p/php5/php5_5.3.3-4_all.deb
+Size: 1050
+MD5Sum: cbedd95ed5b868ba1ffd10747abc0ee3
+Description: server-side, HTML-embedded scripting language (metapackage)

=== added file 'test/integration/status-bug-605394-versioned-or-groups'
--- test/integration/status-bug-605394-versioned-or-groups	1970-01-01 00:00:00 +0000
+++ test/integration/status-bug-605394-versioned-or-groups	2010-11-29 20:43:07 +0000
@@ -0,0 +1,34 @@
+Package: apache2-mpm-worker
+Status: install ok installed
+Priority: optional
+Section: httpd
+Installed-Size: 68
+Maintainer: Debian Apache Maintainers <debian-apache@lists.debian.org>
+Architecture: i386
+Source: apache2
+Version: 2.2.16-4
+Provides: apache2-mpm
+Conflicts: apache2-mpm
+Description: Apache HTTP Server - high speed threaded model
+
+Package: php5-cgi
+Status: install ok installed
+Priority: optional
+Section: php
+Installed-Size: 14672
+Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
+Architecture: i386
+Source: php5
+Version: 5.3.3-3
+Description: server-side, HTML-embedded scripting language (CGI binary)
+
+Package: php5
+Status: install ok installed
+Priority: optional
+Section: php
+Installed-Size: 20
+Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
+Architecture: all
+Version: 5.3.3-3
+Depends: libapache2-mod-php5 (>= 5.3.3-3) | libapache2-mod-php5filter (>= 5.3.3-3) | php5-cgi (>= 5.3.3-3)
+Description: server-side, HTML-embedded scripting language (metapackage)

=== added file 'test/integration/test-bug-605394-versioned-or-groups'
--- test/integration/test-bug-605394-versioned-or-groups	1970-01-01 00:00:00 +0000
+++ test/integration/test-bug-605394-versioned-or-groups	2010-11-29 20:43:07 +0000
@@ -0,0 +1,25 @@
+#!/bin/sh
+set -e
+
+local TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture "i386"
+setupaptarchive
+
+testequal "Reading package lists...
+Building dependency tree...
+The following packages will be upgraded:
+  php5 php5-cgi
+2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
+Need to get 0 B/5715 kB of archives.
+After this operation, 0 B of additional disk space will be used.
+E: Trivial Only specified but this is not a trivial operation." aptget dist-upgrade --trivial-only
+
+msgtest "Solution process doesn't involve" 'apache2-mpm-prefork'
+
+if aptget dist-upgrade --trivial-only -o Debug::pkgProblemResolver=1 -o Debug::pkgDepCache::Marker=1 2>&1 | grep apache2-mpm-prefork > /dev/null; then
+	msgfail
+else
+	msgpass
+fi

