Patchwork [2,of,6] obsolete: create accessors successors(), precursors(), children()

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 4, 2015, 4:01 a.m.
Message ID <518d3caf2307a7699ec0.1423022469@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7653/
State Superseded
Headers show

Comments

Martin von Zweigbergk - Feb. 4, 2015, 4:01 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1421821984 28800
#      Tue Jan 20 22:33:04 2015 -0800
# Node ID 518d3caf2307a7699ec078afe9b1e6991640941c
# Parent  26f1b80d8c5fa5ed05df0eafab61d2241a478934
obsolete: create accessors successors(), precursors(), children()

Add trivial accessor methods for now. They will soon get smarter and
be responsible for populating the dictionaries the first time they are
called.

Patch

diff -r 26f1b80d8c5f -r 518d3caf2307 mercurial/obsolete.py
--- a/mercurial/obsolete.py	Tue Jan 20 22:01:37 2015 -0800
+++ b/mercurial/obsolete.py	Tue Jan 20 22:33:04 2015 -0800
@@ -476,7 +476,7 @@ 
     Exist as a separated function to allow the evolve extension for a more
     subtle handling.
     """
-    if node.nullid in obsstore.precursors:
+    if node.nullid in obsstore._precursors:
         raise util.Abort(_('bad obsolescence marker detected: '
                            'invalid successors nullid'))
 
@@ -502,9 +502,9 @@ 
         # caches for various obsolescence related cache
         self.caches = {}
         self._all = []
-        self.precursors = {}
-        self.successors = {}
-        self.children = {}
+        self._precursors = {}
+        self._successors = {}
+        self._children = {}
         self.sopener = sopener
         data = sopener.tryread('obsstore')
         self._version = defaultformat
@@ -607,13 +607,13 @@ 
     @util.nogc
     def _addsuccessors(self, markers):
         for mark in markers:
-            self.successors.setdefault(mark[0], set()).add(mark)
+            self._successors.setdefault(mark[0], set()).add(mark)
 
     @util.nogc
     def _addprecursors(self, markers):
         for mark in markers:
             for suc in mark[1]:
-                self.precursors.setdefault(suc, set()).add(mark)
+                self._precursors.setdefault(suc, set()).add(mark)
 
     @util.nogc
     def _addchildren(self, markers):
@@ -621,7 +621,16 @@ 
             parents = mark[5]
             if parents is not None:
                 for p in parents:
-                    self.children.setdefault(p, set()).add(mark)
+                    self._children.setdefault(p, set()).add(mark)
+
+    def successors(self):
+        return self._successors
+
+    def precursors(self):
+        return self._precursors
+
+    def children(self):
+        return self._children
 
     def _load(self, markers):
         markers = list(markers) # to allow repeated iteration
@@ -645,8 +654,8 @@ 
         pendingnodes = set(nodes)
         seenmarkers = set()
         seennodes = set(pendingnodes)
-        precursorsmarkers = self.precursors
-        children = self.children
+        precursorsmarkers = self.precursors()
+        children = self.children()
         while pendingnodes:
             direct = set()
             for current in pendingnodes:
@@ -747,12 +756,12 @@ 
 
 def precursormarkers(ctx):
     """obsolete marker marking this changeset as a successors"""
-    for data in ctx._repo.obsstore.precursors.get(ctx.node(), ()):
+    for data in ctx._repo.obsstore.precursors().get(ctx.node(), ()):
         yield marker(ctx._repo, data)
 
 def successormarkers(ctx):
     """obsolete marker making this changeset obsolete"""
-    for data in ctx._repo.obsstore.successors.get(ctx.node(), ()):
+    for data in ctx._repo.obsstore.successors().get(ctx.node(), ()):
         yield marker(ctx._repo, data)
 
 def allsuccessors(obsstore, nodes, ignoreflags=0):
@@ -764,10 +773,11 @@ 
     initial nodes too."""
     remaining = set(nodes)
     seen = set(remaining)
+    successors = obsstore.successors()
     while remaining:
         current = remaining.pop()
         yield current
-        for mark in obsstore.successors.get(current, ()):
+        for mark in successors.get(current, ()):
             # ignore marker flagged with specified flag
             if mark[2] & ignoreflags:
                 continue
@@ -786,10 +796,11 @@ 
 
     remaining = set(nodes)
     seen = set(remaining)
+    precursors = obsstore.precursors()
     while remaining:
         current = remaining.pop()
         yield current
-        for mark in obsstore.precursors.get(current, ()):
+        for mark in precursors.get(current, ()):
             # ignore marker flagged with specified flag
             if mark[2] & ignoreflags:
                 continue
@@ -864,7 +875,7 @@ 
 
     """
 
-    succmarkers = repo.obsstore.successors
+    succmarkers = repo.obsstore.successors()
 
     # Stack of nodes we search successors sets for
     toproceed = [initialnode]
@@ -1086,7 +1097,7 @@ 
     obs = set()
     getrev = repo.changelog.nodemap.get
     getphase = repo._phasecache.phase
-    for n in repo.obsstore.successors:
+    for n in repo.obsstore.successors():
         rev = getrev(n)
         if rev is not None and getphase(repo, rev):
             obs.add(rev)
@@ -1144,10 +1155,10 @@ 
     """the set of rev that compete to be the final successors of some revision.
     """
     divergent = set()
-    obsstore = repo.obsstore
+    precursors = repo.obsstore.precursors()
     newermap = {}
     for ctx in repo.set('(not public()) - obsolete()'):
-        mark = obsstore.precursors.get(ctx.node(), ())
+        mark = precursors.get(ctx.node(), ())
         toprocess = set(mark)
         while toprocess:
             prec = toprocess.pop()[0]
@@ -1157,7 +1168,7 @@ 
             if len(newer) > 1:
                 divergent.add(ctx.rev())
                 break
-            toprocess.update(obsstore.precursors.get(prec, ()))
+            toprocess.update(precursors.get(prec, ()))
     return divergent