changeset 4013:434398b37e16

stablerange: rework saving logic to be clearer and safer
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 27 Aug 2018 12:40:41 +0200
parents dbeac677e99a
children 6fcda453b317
files hgext3rd/evolve/stablerangecache.py
diffstat 1 files changed, 12 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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()