[Aptitude-devel] r2977 - in branches/aptitude-0.3/aptitude: . src/generic src/generic/problemresolver

Daniel Burrows dburrows@costa.debian.org
Sun, 10 Apr 2005 00:40:14 +0000


Author: dburrows
Date: Sun Apr 10 00:40:11 2005
New Revision: 2977

Added:
   branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.cc
Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/Makefile.am
   branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
Log:
Fill in the body of add_scores and fix various problems.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sun Apr 10 00:40:11 2005
@@ -1,5 +1,11 @@
 2005-04-09  Daniel Burrows  <dburrows@debian.org>
 
+	* src/generic/Makefile.am, src/generic/aptitude_resolver.cc, src/generic/aptitude_resolver.h, src/generic/problemresolver/problemresolver.h:
+
+	  Write the body of add_scores(), fix some problems with the
+	  generic resolver that came up in the process, and link it into
+	  the Makefile.
+
 	* src/generic/problemresolver/aptitude_resolver.h, src/generic/aptitude_resolver.h:
 
 	  Move the aptitude_resolver file into generic/ so that

Modified: branches/aptitude-0.3/aptitude/src/generic/Makefile.am
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/Makefile.am	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/Makefile.am	Sun Apr 10 00:40:11 2005
@@ -19,6 +19,8 @@
 	aptcache.cc	\
 	aptitudepolicy.h\
 	aptitudepolicy.cc\
+	aptitude_resolver.h\
+	aptitude_resolver.cc\
 	apt_undo_group.h\
 	apt_undo_group.cc\
 	config_signal.h \

Added: branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.cc	Sun Apr 10 00:40:11 2005
@@ -0,0 +1,76 @@
+// aptitude_resolver.cc
+//
+//   Copyright (C) 2005 Daniel Burrows
+//
+//   This program is free software; you can redistribute it and/or
+//   modify it under the terms of the GNU General Public License as
+//   published by the Free Software Foundation; either version 2 of
+//   the License, or (at your option) any later version.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//   General Public License for more details.
+//
+//   You should have received a copy of the GNU General Public License
+//   along with this program; see the file COPYING.  If not, write to
+//   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+//   Boston, MA 02111-1307, USA.
+
+#include "aptitude_resolver.h"
+
+void aptitude_resolver::add_scores(int preserve_score, int auto_score,
+				   int remove_score, int keep_score,
+				   int install_score, int upgrade_score,
+				   int non_default_score)
+{
+  // Should I stick with APT iterators instead?  This is a bit more
+  // convenient, though..
+  for(aptitude_universe::package_iterator pi=(*apt_cache_file)->PkgBegin();
+      !pi.end(); ++pi)
+    {
+      const aptitude_universe::package &p=*pi;
+      aptitudeDepCache::aptitude_state &state=(*apt_cache_file)->get_ext_state(p.get_pkg());
+
+      for(aptitude_universe::package::version_iterator vi=p.versions_begin(); !vi.end(); ++vi)
+	{
+	  aptitude_universe::version v=*vi;
+
+	  // Remember, the "current version" is the InstVer.
+	  if(v==p.current_version())
+	    {
+	      bool is_user_choice=false;
+	      if(!v.get_ver().end() && state.install_reason == aptitudeDepCache::manual)
+		is_user_choice=true;
+	      else if(v.get_ver().end() && state.remove_reason == aptitudeDepCache::manual)
+		is_user_choice=true;
+
+	      if(is_user_choice)
+		add_version_score(v, preserve_score);
+	      else
+		add_version_score(v, auto_score);
+	    }
+	  // Ok, if this version is selected it'll be a change.
+	  else if(v.get_ver()==p.get_pkg().CurrentVer())
+	    add_version_score(v, keep_score);
+	  else if(v.get_ver().end())
+	    add_version_score(v, remove_score);
+	  else if(v.get_ver()==(*apt_cache_file)[p.get_pkg()].CandidateVerIter(*apt_cache_file))
+	    {
+	      // Could try harder not to break holds.
+	      if(p.get_pkg().CurrentVer().end())
+		add_version_score(v, install_score);
+	      else
+		add_version_score(v, upgrade_score);
+	    }
+	  else
+	    // We know that:
+	    //  - this version wasn't requrested by the user
+	    //  - it's not the current version
+	    //  - it's not the candidate version
+	    //  - it's not a removal
+	    //  - it follows that this is a non-default version.
+	    add_version_score(v, non_default_score);
+	}
+    }
+}

Modified: branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h	Sun Apr 10 00:40:11 2005
@@ -24,6 +24,15 @@
 // conflicts...anyway, if not, then I need to be much more careful how
 // I iterate over conflicts if an OR is involved (it should be
 // basically ignored)
+//
+// General comment on how the iterators are handled: basically the
+// technique is (generally) to have a normalize() routine that
+// advances the current iterator(s) to the next "interesting"
+// iterator.  For instance, broken_dep_iterator::normalize() moves to
+// the next broken dependency (sort of).  If the current iterator is
+// already interesting, nothing happens.  This is used on
+// initialization and in operator++ (after advancing the iterator a
+// single step manually).
 
 #ifndef APTITUDE_RESOLVER_H
 #define APTITUDE_RESOLVER_H
@@ -32,11 +41,10 @@
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/version.h>
 
-#include <generic/apt.h>
-#include <generic/aptcache.h>
-#include <generic/rev_dep_iterator.h>
+#include "apt.h"
+#include "aptcache.h"
 
-#include "problemresolver.h"
+#include "problemresolver/problemresolver.h"
 
 class aptitude_resolver_version;
 
@@ -60,6 +68,11 @@
     return pkg.Name();
   }
 
+  pkgCache::PkgIterator get_pkg() const
+  {
+    return pkg;
+  }
+
   bool operator==(const aptitude_resolver_package &other) const
   {
     return pkg==other.pkg;
@@ -94,6 +107,16 @@
   {
   }
 
+  pkgCache::PkgIterator get_pkg()
+  {
+    return pkg;
+  }
+
+  pkgCache::VerIterator get_ver()
+  {
+    return ver;
+  }
+
   unsigned int get_id() const
   {
     if(!ver.end())
@@ -234,6 +257,10 @@
   {
   }
 
+  // For aptitude-specific code:
+  pkgCache::PkgIterator get_pkg() {return pkg;}
+  pkgCache::VerIterator get_ver() {return ver;}
+
   bool operator==(const version_iterator &other) const
   {
     return pkg == other.pkg && ver == other.ver;
@@ -330,7 +357,7 @@
    *  the given version. (note that v may be an end iterator..)
    */
   revdep_iterator(const pkgCache::VerIterator &v)
-    :ver(v), prv_lst(*apt_cache_file, 0, (pkgCache::Package *) 0),
+    :prv_lst(*apt_cache_file, 0, (pkgCache::Package *) 0), ver(v),
      provides_open(false)
   {
     // Note that if v is an end iterator, we present an empty list and
@@ -639,6 +666,12 @@
       return realiter!=other.realiter;
     }
 
+    // Override for aptitude-specific code.
+    pkgCache::PkgIterator get_pkg() const
+    {
+      return realiter;
+    }
+
     package operator*() const
     {
       return realiter;
@@ -991,13 +1024,17 @@
    * \param install_score the score to assign to removing a package
    * against the user's wishes.
    *
+   * \param upgrade_score the score to assign to upgrading a package
+   * against the user's wishes.
+   *
    * \param non_default_score the score to assign to installing a
    * non-default version of a package (such as a downgrade or an
    * experimental version).
    */
   void add_scores(int preserve_score, int auto_score,
 		  int remove_score, int keep_score,
-		  int install_score, int non_default_score);
+		  int install_score, int upgrade_score,
+		  int non_default_score);
 };
 
 #endif

Modified: branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h	Sun Apr 10 00:40:11 2005
@@ -681,13 +681,13 @@
    */
   void add_version_score(version &ver, int score)
   {
-    version_score[ver.get_id()]+=score;
+    version_scores[ver.get_id()]+=score;
   }
 
   /** \return the score of the version ver. */
   int get_version_score(version &ver)
   {
-    return version_score[ver.get_id()];
+    return version_scores[ver.get_id()];
   }
 
   /** Try to find the "next" solution: remove partial solutions from