Clean up merge list handling:
authorZac Medico <zmedico@gentoo.org>
Fri, 2 May 2008 17:56:21 +0000 (17:56 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 2 May 2008 17:56:21 +0000 (17:56 -0000)
* In depgraph.loadResumeCommand(), populate _serialized_tasks_cache so that
  it can be returned from depgraph.altlist().
* Handle --skipfirst instide depgraph.loadResumeCommand(), and fix it to skip
  the first "merge" task and never skip "uninstall" tasks.
* Always get the merge list from depgraph.altlist() instead of using
  the mtimedb directly. The list returned from depgraph.altlist()
  contains Package instances with cached metadata.
* Remove obsolete code from depgraph.display() and MergeTask.merge() since
  the merge list always comes from depgraph.altlist() now, and never directly
  from the mtimedb.
(trunk r10092)

svn path=/main/branches/2.1.2/; revision=10093

bin/emerge

index e1342d4ded2a91086683e8c7ba7c359061a78240..8e307c5e96b2c16aabb188b202bccbd75e7b032a 100755 (executable)
@@ -3919,12 +3919,14 @@ class depgraph(object):
                                                node = tempgraph.order[0]
                                        else:
                                                node = nodes[0]
-                                       display_order.append(list(node))
+                                       display_order.append(node)
                                        tempgraph.remove(node)
                                display_order.reverse()
                                self.myopts.pop("--quiet", None)
                                self.myopts.pop("--verbose", None)
                                self.myopts["--tree"] = True
+                               print
+                               print
                                self.display(display_order)
                                print "!!! Error: circular dependencies:"
                                print
@@ -4267,18 +4269,7 @@ class depgraph(object):
                                        pkg_status = "nomerge"
                                built = pkg_type != "ebuild"
                                installed = pkg_type == "installed"
-                               try:
-                                       pkg = self._pkg_cache[tuple(x)]
-                               except KeyError:
-                                       if pkg_status != "uninstall":
-                                               raise
-                                       # A package scheduled for uninstall apparently
-                                       # isn't installed anymore. Since it's already
-                                       # been uninstalled, move on to the next task.
-                                       # This case should only be reachable in --resume
-                                       # mode, since otherwise the package would have
-                                       # been cached.
-                                       continue
+                               pkg = x
                                metadata = pkg.metadata
                                ebuild_path = None
                                repo_name = metadata["repository"]
@@ -4914,8 +4905,17 @@ class depgraph(object):
                """
                self._sets["args"].update(resume_data.get("favorites", []))
                mergelist = resume_data.get("mergelist", [])
+
+               if mergelist and "--skipfirst" in self.myopts:
+                       for i, task in enumerate(mergelist):
+                               if isinstance(task, list) and \
+                                       task and task[-1] == "merge":
+                                       del mergelist[i]
+                                       break
+
                fakedb = self.mydbapi
                trees = self.trees
+               serialized_tasks = []
                for x in mergelist:
                        if len(x) != 4:
                                continue
@@ -4945,7 +4945,9 @@ class depgraph(object):
                                type_name=pkg_type)
                        self._pkg_cache[pkg] = pkg
                        fakedb[myroot].cpv_inject(pkg)
+                       serialized_tasks.append(pkg)
                        self.spinner.update()
+               self._serialized_tasks_cache = serialized_tasks
 
        class _internal_exception(portage_exception.PortageException):
                def __init__(self, value=""):
@@ -5288,7 +5290,6 @@ class MergeTask(object):
                fetchonly = "--fetchonly" in self.myopts or \
                        "--fetch-all-uri" in self.myopts
                pretend = "--pretend" in self.myopts
-               mymergelist=[]
                ldpath_mtimes = mtimedb["ldpath"]
                xterm_titles = "notitles" not in self.settings.features
 
@@ -5296,12 +5297,6 @@ class MergeTask(object):
                        # We're resuming.
                        print colorize("GOOD", "*** Resuming merge...")
                        emergelog(xterm_titles, " *** Resuming merge...")
-                       mylist = mtimedb["resume"]["mergelist"][:]
-                       if "--skipfirst" in self.myopts and mylist:
-                               del mtimedb["resume"]["mergelist"][0]
-                               del mylist[0]
-                               mtimedb.commit()
-                       mymergelist = mylist
 
                # Verify all the manifests now so that the user is notified of failure
                # as soon as possible.
@@ -5335,12 +5330,12 @@ class MergeTask(object):
                system_set = root_config.sets["system"]
                args_set = InternalPackageSet(favorites)
                world_set = root_config.sets["world"]
-               if "--resume" not in self.myopts:
-                       mymergelist = mylist
-                       mtimedb["resume"]["mergelist"] = [list(x) for x in mymergelist \
-                               if isinstance(x, Package)]
-                       mtimedb.commit()
 
+               mtimedb["resume"]["mergelist"] = [list(x) for x in mylist \
+                       if isinstance(x, Package)]
+               mtimedb.commit()
+
+               mymergelist = mylist
                myfeat = self.settings.features[:]
                bad_resume_opts = set(["--ask", "--tree", "--changelog", "--skipfirst",
                        "--resume"])
@@ -5407,15 +5402,10 @@ class MergeTask(object):
                        vardb = vartree.dbapi
                        root_config = self.trees[myroot]["root_config"]
                        pkgsettings = self.pkgsettings[myroot]
-                       metadata = {}
                        if pkg_type == "blocks":
                                pass
                        elif pkg_type == "ebuild":
                                mydbapi = portdb
-                               metadata.update(izip(metadata_keys,
-                                       mydbapi.aux_get(pkg_key, metadata_keys)))
-                               pkgsettings.setcpv(pkg_key, mydb=mydbapi)
-                               metadata["USE"] = pkgsettings["PORTAGE_USE"]
                        else:
                                if pkg_type == "binary":
                                        mydbapi = bindb
@@ -5423,22 +5413,10 @@ class MergeTask(object):
                                        mydbapi = vardb
                                else:
                                        raise AssertionError("Package type: '%s'" % pkg_type)
-                               try:
-                                       metadata.update(izip(metadata_keys,
-                                               mydbapi.aux_get(pkg_key, metadata_keys)))
-                               except KeyError:
-                                       if not installed:
-                                               raise
-                                       # A package scheduled for uninstall apparently
-                                       # isn't installed anymore. Since it's already
-                                       # been uninstalled, move on to the next task.
-                                       continue
                        if not installed:
                                mergecount += 1
-                       pkg = Package(cpv=pkg_key, built=built,
-                               installed=installed, metadata=metadata,
-                               operation=operation, root=myroot,
-                               type_name=pkg_type)
+                       pkg = x
+                       metadata = pkg.metadata
                        if pkg.installed:
                                if not (buildpkgonly or fetchonly or pretend):
                                        self._uninstall_queue.append(pkg)
@@ -7714,9 +7692,7 @@ def action_build(settings, trees, mtimedb,
                "--verbose" in myopts) and \
                not ("--quiet" in myopts and "--ask" not in myopts):
                if "--resume" in myopts:
-                       mymergelist = mtimedb["resume"]["mergelist"]
-                       if "--skipfirst" in myopts:
-                               mymergelist = mymergelist[1:]
+                       mymergelist = mydepgraph.altlist()
                        if len(mymergelist) == 0:
                                print colorize("INFORM", "emerge: It seems we have nothing to resume...")
                                return os.EX_OK
@@ -7772,9 +7748,7 @@ def action_build(settings, trees, mtimedb,
 
        if ("--pretend" in myopts) and not ("--fetchonly" in myopts or "--fetch-all-uri" in myopts):
                if ("--resume" in myopts):
-                       mymergelist = mtimedb["resume"]["mergelist"]
-                       if "--skipfirst" in myopts:
-                               mymergelist = mymergelist[1:]
+                       mymergelist = mydepgraph.altlist()
                        if len(mymergelist) == 0:
                                print colorize("INFORM", "emerge: It seems we have nothing to resume...")
                                return os.EX_OK
@@ -7816,9 +7790,9 @@ def action_build(settings, trees, mtimedb,
                                it to write the mtimedb"""
                                mtimedb.filename = None
                                time.sleep(3) # allow the parent to have first fetch
+                       mymergelist = mydepgraph.altlist()
                        del mydepgraph
-                       retval = mergetask.merge(
-                               mtimedb["resume"]["mergelist"], favorites, mtimedb)
+                       retval = mergetask.merge(mymergelist, favorites, mtimedb)
                        merge_count = mergetask.curval
                else:
                        if "resume" in mtimedb and \