Patchwork [07,of,16] phases: make _filterunknown a member function of phasecache

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 2, 2013, 1:09 a.m.
Message ID <223cb873a170ee0d9c6a.1357088969@yamac.lan>
Download mbox | patch
Permalink /patch/351/
State Superseded, archived
Commit 767d1c602c8bcee7abbf36a44c4c06a5127f5a83
Headers show

Comments

Pierre-Yves David - Jan. 2, 2013, 1:09 a.m.
# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1355682488 -7200
# Node ID 223cb873a170ee0d9c6a9d3ec93aeb8057ca4ffe
# Parent  42d39c8232de6b32d6e489329bf10656960ae8a7
phases: make _filterunknown a member function of phasecache

We'd like the ability to call filterunknown on an existing phasecache
instance after nodes are destroyed.
Kevin Bullock - Jan. 3, 2013, 11:08 p.m.
On Jan 1, 2013, at 7:09 PM, Pierre-Yves David wrote:

> # HG changeset patch
> # User Idan Kamara <idankk86 at gmail.com>
> # Date 1355682488 -7200
> # Node ID 223cb873a170ee0d9c6a9d3ec93aeb8057ca4ffe
> # Parent  42d39c8232de6b32d6e489329bf10656960ae8a7
> phases: make _filterunknown a member function of phasecache
> 
> We'd like the ability to call filterunknown on an existing phasecache
> instance after nodes are destroyed.

It's generally poor form to move a function, change its arguments, and arbitrarily rename its local variables all in one change. Looks okay though.

pacem in terris / ??? / ?????? / ????????? / ??
Kevin R. Bullock

Patch

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -107,28 +107,10 @@  import util, error
 
 allphases = public, draft, secret = range(3)
 trackedphases = allphases[1:]
 phasenames = ['public', 'draft', 'secret']
 
-def _filterunknown(ui, changelog, phaseroots):
-    """remove unknown nodes from the phase boundary
-
-    Nothing is lost as unknown nodes only hold data for their descendants.
-    """
-    updated = False
-    nodemap = changelog.nodemap # to filter unknown nodes
-    for phase, nodes in enumerate(phaseroots):
-        missing = [node for node in nodes if node not in nodemap]
-        if missing:
-            for mnode in missing:
-                ui.debug(
-                    'removing unknown node %s from %i-phase boundary\n'
-                    % (short(mnode), phase))
-            nodes.symmetric_difference_update(missing)
-            updated = True
-    return updated
-
 def _readroots(repo, phasedefaults=None):
     """Read phase roots from disk
 
     phasedefaults is a list of fn(repo, roots) callable, which are
     executed if the phase roots file does not exist. When phases are
@@ -154,19 +136,18 @@  def _readroots(repo, phasedefaults=None)
             raise
         if phasedefaults:
             for f in phasedefaults:
                 roots = f(repo, roots)
         dirty = True
-    if _filterunknown(repo.ui, repo.changelog, roots):
-        dirty = True
     return roots, dirty
 
 class phasecache(object):
     def __init__(self, repo, phasedefaults, _load=True):
         if _load:
             # Cheap trick to allow shallow-copy without copy module
             self.phaseroots, self.dirty = _readroots(repo, phasedefaults)
+            self.filterunknown(repo)
             self.opener = repo.sopener
             self._phaserevs = None
 
     def copy(self):
         # Shallow copy meant to ensure isolation in
@@ -265,10 +246,30 @@  class phasecache(object):
             ctxs = repo.set('roots(%ln::)', currentroots)
             currentroots.intersection_update(ctx.node() for ctx in ctxs)
             self._updateroots(targetphase, currentroots)
         repo.invalidatevolatilesets()
 
+    def filterunknown(self, repo):
+        """remove unknown nodes from the phase boundary
+
+        Nothing is lost as unknown nodes only hold data for their descendants.
+        """
+        filtered = False
+        nodemap = repo.changelog.nodemap # to filter unknown nodes
+        for phase, nodes in enumerate(self.phaseroots):
+            missing = [node for node in nodes if node not in nodemap]
+            if missing:
+                for mnode in missing:
+                    repo.ui.debug(
+                        'removing unknown node %s from %i-phase boundary\n'
+                        % (short(mnode), phase))
+                nodes.symmetric_difference_update(missing)
+                filtered = True
+        if filtered:
+            self.dirty = True
+            self._phaserevs = None
+
 def advanceboundary(repo, targetphase, nodes):
     """Add nodes to a phase changing other nodes phases if necessary.
 
     This function move boundary *forward* this means that all nodes
     are set in the target phase or kept in a *lower* phase.