obscache: move assert earlier in the code
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 03 May 2017 18:33:53 +0200
changeset 2325 04a0eda7dea9
parent 2324 3c7c4d92022f
child 2326 72853bade853
obscache: move assert earlier in the code If we are to crash, let us crash earlier.
hgext3rd/evolve/obscache.py
--- a/hgext3rd/evolve/obscache.py	Wed May 03 13:58:32 2017 +0200
+++ b/hgext3rd/evolve/obscache.py	Wed May 03 18:33:53 2017 +0200
@@ -239,6 +239,17 @@
         if startrev is None and startidx is None:
             return
 
+        # checks we never run 'update' without a lock
+        #
+        # There are a potential race condition otherwise, since the repo
+        # "might" have changed side the cache update above. However, this code
+        # will only be running in a lock so we ignore the issue for now.
+        #
+        # Lift this limitation, 'upgradeneeded' should return a bounded amount
+        # of changeset and markers to read with their associated cachekey. see
+        # 'upgradeneeded' for detail.
+        assert repo._currentlock(repo._lockref) is not None
+
         # process the new changesets
         cl = repo.changelog
         if startrev is not None:
@@ -290,14 +301,6 @@
                 if r is not None and (startrev is None or r < startrev):
                     self._data[r] = 1
 
-        assert repo._currentlock(repo._lockref) is not None
-        # XXX note that there are a potential race condition here, since the
-        # repo "might" have changed side the cache update above. However, this
-        # code will only be running in a lock so we ignore the issue for now.
-        #
-        # To work around this, 'upgradeneeded' should return a bounded amount
-        # of changeset and markers to read with their associated cachekey. see
-        # 'upgradeneeded' for detail.
         self._cachekey = getcachekey(repo)
 
     def save(self, repo):