Patchwork [5,of,8] obsutil: move 'foreground' to the new modules

login
register
mail settings
Submitter Pierre-Yves David
Date June 27, 2017, 8:56 a.m.
Message ID <d04b168d55057262ffd0.1498553808@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21759/
State Superseded
Headers show

Comments

Pierre-Yves David - June 27, 2017, 8:56 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1498520434 -7200
#      Tue Jun 27 01:40:34 2017 +0200
# Node ID d04b168d55057262ffd07c71f9d822924d65ba4f
# Parent  81137fb5e9ef24aec5940e08a5f5b17ac7576da0
# EXP-Topic obsutil
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r d04b168d5505
obsutil: move 'foreground' to the new modules

We have a new 'obsutil' module now. We move the high level utility there to
bring 'obsolete.py' back to a more reasonable size.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -19,7 +19,7 @@  from . import (
     encoding,
     error,
     lock as lockmod,
-    obsolete,
+    obsutil,
     scmutil,
     txnutil,
     util,
@@ -681,7 +681,7 @@  def validdest(repo, old, new):
         # (new != nullrev has been excluded by the previous check)
         return True
     elif repo.obsstore:
-        return new.node() in obsolete.foreground(repo, [old.node()])
+        return new.node() in obsutil.foreground(repo, [old.node()])
     else:
         # still an independent clause as it is lazier (and therefore faster)
         return old.descendant(new)
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -28,7 +28,7 @@  from . import (
     error,
     filemerge,
     match as matchmod,
-    obsolete,
+    obsutil,
     pycompat,
     scmutil,
     subrepo,
@@ -1590,8 +1590,8 @@  def update(repo, node, branchmerge, forc
                 dirty = wc.dirty(missing=True)
                 if dirty:
                     # Branching is a bit strange to ensure we do the minimal
-                    # amount of call to obsolete.foreground.
-                    foreground = obsolete.foreground(repo, [p1.node()])
+                    # amount of call to obsutil.foreground.
+                    foreground = obsutil.foreground(repo, [p1.node()])
                     # note: the <node> variable contains a random identifier
                     if repo[node].node() in foreground:
                         pass # allow updating to successors
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -869,32 +869,6 @@  def successormarkers(ctx):
     for data in ctx.repo().obsstore.successors.get(ctx.node(), ()):
         yield marker(ctx.repo(), data)
 
-def foreground(repo, nodes):
-    """return all nodes in the "foreground" of other node
-
-    The foreground of a revision is anything reachable using parent -> children
-    or precursor -> successor relation. It is very similar to "descendant" but
-    augmented with obsolescence information.
-
-    Beware that possible obsolescence cycle may result if complex situation.
-    """
-    repo = repo.unfiltered()
-    foreground = set(repo.set('%ln::', nodes))
-    if repo.obsstore:
-        # We only need this complicated logic if there is obsolescence
-        # XXX will probably deserve an optimised revset.
-        nm = repo.changelog.nodemap
-        plen = -1
-        # compute the whole set of successors or descendants
-        while len(foreground) != plen:
-            plen = len(foreground)
-            succs = set(c.node() for c in foreground)
-            mutable = [c.node() for c in foreground if c.mutable()]
-            succs.update(obsutil.allsuccessors(repo.obsstore, mutable))
-            known = (n for n in succs if n in nm)
-            foreground = set(repo.set('%ln::', known))
-    return set(c.node() for c in foreground)
-
 # keep compatibility for the 4.3 cycle
 def allprecursors(obsstore, nodes, ignoreflags=0):
     movemsg = 'obsolete.allprecursors moved to obsutil.allprecursors'
@@ -911,6 +885,11 @@  def exclusivemarkers(repo, nodes):
     repo.ui.deprecwarn(movemsg, '4.3')
     return obsutil.exclusivemarkers(repo, nodes)
 
+def foreground(repo, nodes):
+    movemsg = 'obsolete.foreground moved to obsutil.foreground'
+    repo.ui.deprecwarn(movemsg, '4.3')
+    return obsutil.foreground(repo, nodes)
+
 def successorssets(repo, initialnode, cache=None):
     movemsg = 'obsolete.successorssets moved to obsutil.successorssets'
     repo.ui.deprecwarn(movemsg, '4.3')
diff --git a/mercurial/obsutil.py b/mercurial/obsutil.py
--- a/mercurial/obsutil.py
+++ b/mercurial/obsutil.py
@@ -203,6 +203,32 @@  def exclusivemarkers(repo, nodes):
 
     return exclmarkers
 
+def foreground(repo, nodes):
+    """return all nodes in the "foreground" of other node
+
+    The foreground of a revision is anything reachable using parent -> children
+    or precursor -> successor relation. It is very similar to "descendant" but
+    augmented with obsolescence information.
+
+    Beware that possible obsolescence cycle may result if complex situation.
+    """
+    repo = repo.unfiltered()
+    foreground = set(repo.set('%ln::', nodes))
+    if repo.obsstore:
+        # We only need this complicated logic if there is obsolescence
+        # XXX will probably deserve an optimised revset.
+        nm = repo.changelog.nodemap
+        plen = -1
+        # compute the whole set of successors or descendants
+        while len(foreground) != plen:
+            plen = len(foreground)
+            succs = set(c.node() for c in foreground)
+            mutable = [c.node() for c in foreground if c.mutable()]
+            succs.update(allsuccessors(repo.obsstore, mutable))
+            known = (n for n in succs if n in nm)
+            foreground = set(repo.set('%ln::', known))
+    return set(c.node() for c in foreground)
+
 def successorssets(repo, initialnode, cache=None):
     """Return set of all latest successors of initial nodes