obshashrange: rework saving branching to be clearer and safer stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 27 Aug 2018 12:12:49 +0200
branchstable
changeset 4025 971d2e81b5b6
parent 4024 210f8abdfcd7
child 4026 b375398074b0
obshashrange: rework saving branching to be clearer and safer
hgext3rd/evolve/obsdiscovery.py
--- a/hgext3rd/evolve/obsdiscovery.py	Mon Aug 27 11:40:32 2018 +0200
+++ b/hgext3rd/evolve/obsdiscovery.py	Mon Aug 27 12:12:49 2018 +0200
@@ -609,9 +609,12 @@
                 for req in _sqliteschema:
                     con.execute(req)
 
-                con.execute(_newmeta, self._fullcachekey)
+                meta = [self._schemaversion] + list(self.emptykey)
+                con.execute(_newmeta, meta)
+                self._ondiskcachekey = self.emptykey
         else:
             con = self._con
+        with con:
             meta = con.execute(_querymeta).fetchone()
             if meta[1:] != self._ondiskcachekey:
                 # drifting is currently an issue because this means another
@@ -620,17 +623,20 @@
                 msg = _('obshashrange cache: skipping write, '
                         'database drifted under my feet\n')
                 repo.ui.warn(msg)
+                self._new.clear()
+                self._valid = False
+                if '_con' in vars(self):
+                    del self._con
+                self._valid = False
                 return
-        data = ((rangeid[0], rangeid[1], self.get(rangeid)) for rangeid in self._new)
-        con.executemany(_updateobshash, data)
-        cachekey = self._fullcachekey
-        con.execute(_clearmeta) # remove the older entry
-        con.execute(_newmeta, cachekey)
-        con.commit()
-        self._new.clear()
-        self._ondiskcachekey = self._cachekey
-        self._valid = True
-
+            data = ((rangeid[0], rangeid[1], self.get(rangeid)) for rangeid in self._new)
+            con.executemany(_updateobshash, data)
+            cachekey = self._fullcachekey
+            con.execute(_clearmeta) # remove the older entry
+            con.execute(_newmeta, cachekey)
+            self._new.clear()
+            self._valid = True
+            self._ondiskcachekey = self._cachekey
 @eh.wrapfunction(obsolete.obsstore, '_addmarkers')
 def _addmarkers(orig, obsstore, *args, **kwargs):
     obsstore.rangeobshashcache.clear()