changeset 4026:b375398074b0 stable

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 971d2e81b5b6
children 130a60a51fff
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
@@ -262,19 +262,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
@@ -287,15 +288,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()