stablerange: rework saving logic to be clearer and safer
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 27 Aug 2018 12:40:41 +0200
changeset 4013 434398b37e16
parent 4012 dbeac677e99a
child 4014 6fcda453b317
stablerange: rework saving logic to be clearer and safer
hgext3rd/evolve/stablerangecache.py
--- a/hgext3rd/evolve/stablerangecache.py	Mon Aug 27 12:12:49 2018 +0200
+++ b/hgext3rd/evolve/stablerangecache.py	Mon Aug 27 12:40:41 2018 +0200
@@ -261,19 +261,20 @@
             con = self._db()
             if con is None:
                 return
-            con.execute('BEGIN IMMEDIATE;')
             with con:
                 for req in _sqliteschema:
                     con.execute(req)
 
                 meta = [self._schemaversion,
-                        self._tiprev,
-                        self._tipnode,
+                        nodemod.nullrev,
+                        nodemod.nullid,
                 ]
                 con.execute(_newmeta, meta)
+                self._ondisktiprev = nodemod.nullrev
+                self._ondisktipnode = nodemod.nullid
         else:
             con = self._con
-            con.execute('BEGIN IMMEDIATE;')
+        with con:
             meta = con.execute(_querymeta).fetchone()
             if meta[2] != self._ondisktipnode or meta[1] != self._ondisktiprev:
                 # drifting is currently an issue because this means another
@@ -286,15 +287,14 @@
                         nodemod.hex(self._ondisktipnode), self._ondisktiprev)
                 repo.ui.warn(msg)
                 repo.ui.warn(hint % data)
-                con.execute('ROLLBACK;')
+                self._unsavedsubranges.clear()
                 return
-            meta = [self._tiprev,
-                    self._tipnode,
-            ]
-            con.execute(_updatemeta, meta)
-
-        self._saverange(con, repo)
-        con.commit()
+            else:
+                self._saverange(con, repo)
+                meta = [self._tiprev,
+                        self._tipnode,
+                ]
+                con.execute(_updatemeta, meta)
         self._ondisktiprev = self._tiprev
         self._ondisktipnode = self._tipnode
         self._unsavedsubranges.clear()