Patchwork [1,of,3,V2] obsolete: extract helpers from _load()

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 5, 2015, 7:22 a.m.
Message ID <4308a09f48704f942b65.1423120972@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7683/
State Changes Requested
Headers show

Comments

Martin von Zweigbergk - Feb. 5, 2015, 7:22 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1421820097 28800
#      Tue Jan 20 22:01:37 2015 -0800
# Node ID 4308a09f48704f942b65e5604ab05b02ef0a9780
# Parent  e1dbe0b215ae137eec53ceb12440536d570a83d2
obsolete: extract helpers from  _load()

In preparation for making the successors, precursors, and children
dictionaries lazily populated, break up _load() into one function for
adding markers to each dictionary.

Patch

diff -r e1dbe0b215ae -r 4308a09f4870 mercurial/obsolete.py
--- a/mercurial/obsolete.py	Mon Feb 02 19:58:41 2015 -0500
+++ b/mercurial/obsolete.py	Tue Jan 20 22:01:37 2015 -0800
@@ -470,6 +470,25 @@ 
         """The flags field of the marker"""
         return self._data[2]
 
+@util.nogc
+def _addsuccessors(successors, markers):
+    for mark in markers:
+        successors.setdefault(mark[0], set()).add(mark)
+
+@util.nogc
+def _addprecursors(precursors, markers):
+    for mark in markers:
+        for suc in mark[1]:
+            precursors.setdefault(suc, set()).add(mark)
+
+@util.nogc
+def _addchildren(children, markers):
+    for mark in markers:
+        parents = mark[5]
+        if parents is not None:
+            for p in parents:
+                children.setdefault(p, set()).add(mark)
+
 def _checkinvalidmarkers(obsstore):
     """search for marker with invalid data and raise error if needed
 
@@ -604,18 +623,12 @@ 
         version, markers = _readmarkers(data)
         return self.add(transaction, markers)
 
-    @util.nogc
     def _load(self, markers):
-        for mark in markers:
-            self._all.append(mark)
-            pre, sucs = mark[:2]
-            self.successors.setdefault(pre, set()).add(mark)
-            for suc in sucs:
-                self.precursors.setdefault(suc, set()).add(mark)
-            parents = mark[5]
-            if parents is not None:
-                for p in parents:
-                    self.children.setdefault(p, set()).add(mark)
+        markers = list(markers) # to allow repeated iteration
+        self._all.extend(markers)
+        _addsuccessors(self.successors, markers)
+        _addprecursors(self.precursors, markers)
+        _addchildren(self.children, markers)
         _checkinvalidmarkers(self)
 
     def relevantmarkers(self, nodes):