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

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 4, 2015, 4:01 a.m.
Message ID <26f1b80d8c5fa5ed05df.1423022468@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7654/
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 1421820097 28800
#      Tue Jan 20 22:01:37 2015 -0800
# Node ID 26f1b80d8c5fa5ed05df0eafab61d2241a478934
# Parent  e1dbe0b215ae137eec53ceb12440536d570a83d2
obsolete: extract helpers from  _load()

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

Patch

diff -r e1dbe0b215ae -r 26f1b80d8c5f 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
@@ -605,17 +605,30 @@ 
         return self.add(transaction, markers)
 
     @util.nogc
-    def _load(self, markers):
+    def _addsuccessors(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.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)
+
+    @util.nogc
+    def _addchildren(self, markers):
+        for mark in markers:
             parents = mark[5]
             if parents is not None:
                 for p in parents:
                     self.children.setdefault(p, set()).add(mark)
+
+    def _load(self, markers):
+        markers = list(markers) # to allow repeated iteration
+        self._all.extend(markers)
+        self._addsuccessors(markers)
+        self._addprecursors(markers)
+        self._addchildren(markers)
         _checkinvalidmarkers(self)
 
     def relevantmarkers(self, nodes):