diff hgsubversion/maps.py @ 1478:797c7b58a735

maps: add a config option to tweak sqlite Sqlite is highly configurable by PRAGMA statements [1]. This patch adds a config option to give the user changes to tweak them. [1]: https://www.sqlite.org/pragma.html
author Jun Wu <quark@fb.com>
date Thu, 23 Jun 2016 20:03:30 +0100
parents a4f77acf7051
children bc73b80baf98
line wrap: on
line diff
--- a/hgsubversion/maps.py
+++ b/hgsubversion/maps.py
@@ -558,7 +558,7 @@ class SqliteRevMap(collections.MutableMa
     rowcount = util.fileproperty('_rowcount', lambda x: x._rowcountpath,
                                  default=0, deserializer=int)
 
-    def __init__(self, revmap_path, lastpulled_path):
+    def __init__(self, revmap_path, lastpulled_path, sqlitepragmas=None):
         self._filepath = revmap_path
         self._dbpath = revmap_path + '.db'
         self._rowcountpath = self._dbpath + '.rowcount'
@@ -566,6 +566,7 @@ class SqliteRevMap(collections.MutableMa
 
         self._db = None
         self._hashes = None
+        self._sqlitepragmas = sqlitepragmas
         self.firstpulled = 0
         self._updatefirstlastpulled()
         # __iter__ is expensive and thus disabled by default
@@ -720,6 +721,12 @@ class SqliteRevMap(collections.MutableMa
                 cachesize += os.stat(path).st_size * ratio // 1000
         self._db.execute('PRAGMA cache_size=%d' % (-cachesize))
 
+        # PRAGMA statements provided by the user
+        for pragma in (self._sqlitepragmas or []):
+            # drop malicious ones
+            if re.match(r'\A\w+=\w+\Z', pragma):
+                self._db.execute('PRAGMA %s' % pragma)
+
         # disable auto-commit. everything is inside a transaction
         self._db.isolation_level = 'DEFERRED'