# HG changeset patch # User Pierre-Yves David # Date 1535364769 -7200 # Node ID dbeac677e99a6f1e8578e95814232ab90d55c554 # Parent 3cb41bf56f16ecc777b12258068bf5f5974b0053 obshashrange: rework saving branching to be clearer and safer diff -r 3cb41bf56f16 -r dbeac677e99a 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 @@ -614,9 +614,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 @@ -625,17 +628,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()