obscache: extract _updatemarkers code into its own function
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 03 May 2017 20:56:26 +0200
changeset 2327 6b751daad348
parent 2326 72853bade853
child 2328 7ccacaa38782
obscache: extract _updatemarkers code into its own function This split the update logic from the bit retrieving markers. That cannot be bad.
hgext3rd/evolve/obscache.py
--- a/hgext3rd/evolve/obscache.py	Wed May 03 18:46:48 2017 +0200
+++ b/hgext3rd/evolve/obscache.py	Wed May 03 20:56:26 2017 +0200
@@ -258,7 +258,6 @@
 
         # process the new obsmarkers
         if startidx is not None:
-            rev = cl.nodemap.get
             markers = repo.obsstore._all
             # Note:
             #
@@ -275,13 +274,8 @@
             #      responsible for adding a markers.
             #
             #   Option 2 is probably a bit more invasive, but more solid on the long run
-
-            for i in xrange(startidx, len(repo.obsstore)):
-                r = rev(markers[i][0])
-                # If markers affect a newly added nodes, it would have been
-                # caught in the previous loop, (so we skip < startrev)
-                if r is not None and (startrev is None or r < startrev):
-                    self._data[r] = 1
+            markers = [markers[i] for i in xrange(startidx, len(repo.obsstore))]
+            self._updatemarkers(repo, markers)
 
         self._cachekey = getcachekey(repo)
 
@@ -307,6 +301,14 @@
                 val = 0
             self._data.append(val)
 
+    def _updatemarkers(self, repo, obsmarkers):
+        """update the cache with new markers"""
+        rev = repo.changelog.nodemap.get
+        for m in obsmarkers:
+            r = rev(m[0])
+            if r is not None:
+                self._data[r] = 1
+
     def save(self, repo):
         """save the data to disk"""