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

Daniel Burrows dburrows@costa.debian.org
Sat, 23 Apr 2005 00:39:11 +0000


Author: dburrows
Date: Sat Apr 23 00:39:08 2005
New Revision: 3052

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/aptcache.cc
   branches/aptitude-0.3/aptitude/src/generic/aptcache.h
Log:
Add an interface routine that applies the currently selected solution.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sat Apr 23 00:39:08 2005
@@ -1,5 +1,10 @@
 2005-04-22  Daniel Burrows  <dburrows@debian.org>
 
+	* src/generic/aptcache.cc, src/generic/aptcache.h:
+
+	  Add an interface routine to easily apply the currently selected
+	  resolution.
+
 	* src/defaults.cc:
 
 	  Set up default key bindings for the problem resolver.

Modified: branches/aptitude-0.3/aptitude/src/generic/aptcache.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/aptcache.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/aptcache.cc	Sat Apr 23 00:39:08 2005
@@ -1394,6 +1394,38 @@
     return next_solution();
 }
 
+void aptitudeDepCache::apply_current_solution(undo_group *undo)
+{
+  aptitude_resolver::solution sol=get_current_solution();
+
+  begin_action_group();
+
+  for(map<aptitude_resolver::package,
+	aptitude_resolver::action>::const_iterator i=sol.get_actions().begin();
+      i!=sol.get_actions().end(); ++i)
+    {
+      pkgCache::PkgIterator pkg=i->first.get_pkg();
+      pkgCache::VerIterator curver=pkg.CurrentVer();
+      pkgCache::VerIterator actionver=i->second.ver.get_ver();
+
+      // Check what type of action it is.
+      if(actionver.end())
+	// removal.
+	internal_mark_delete(pkg, false, false, undo, false);
+      else if(actionver == curver)
+	// keep
+	internal_mark_keep(pkg, false, false, undo, false);
+      else
+	// install a particular version that's not the current one.
+	{
+	  set_candidate_version(actionver, undo);
+	  internal_mark_install(pkg, false, false, undo, false);
+	}
+    }
+
+  end_action_group(undo);
+}
+
 const aptitude_resolver::solution &aptitudeDepCache::next_solution()
 {
   if(solutions.empty())

Modified: branches/aptitude-0.3/aptitude/src/generic/aptcache.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/aptcache.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/aptcache.h	Sat Apr 23 00:39:08 2005
@@ -398,6 +398,21 @@
    */
   const generic_solution<aptitude_universe> &get_current_solution();
 
+  /** Requires that resolver_exists() is \b true.  If no solutions
+   *  have been calculated yet, will calculate and apply the first
+   *  solution.
+   *
+   *  \param undo an undo group in which to accumulate the actions of
+   *  the current solution.
+   *
+   *  \throws NoMoreSolutions if there are no solutions and the search
+   *  is exhausted.
+   *
+   *  \throws NoMoreTime if there are no solutions and the last effort
+   *  ran out of time.
+   */
+  void apply_current_solution(undo_group *undo);
+
   /** Advance to the next solution.
    *
    *  \return the next solution.  This reference is not guaranteed to