changeset 1469:7bb2c6ca4d24

maps: implement migration from SqliteRevMap to RevMap It'd be good to let user migrate up and down freely.
author Jun Wu <quark@fb.com>
date Wed, 15 Jun 2016 18:25:26 +0100
parents b98ff95b5861
children b6e2bc962536
files hgsubversion/maps.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/maps.py
+++ b/hgsubversion/maps.py
@@ -420,6 +420,13 @@ class RevMap(dict):
                 raise
             return iter([])
         ver = int(f.readline())
+        if ver == SqliteRevMap.VERSION:
+            revmap = SqliteRevMap(self._filepath, self._lastpulled_file)
+            tmppath = '%s.tmp' % self._filepath
+            revmap.exportrevmapv1(tmppath)
+            os.rename(tmppath, self._filepath)
+            hgutil.unlinkpath(revmap._dbpath)
+            return self._readmapfile()
         if ver != self.VERSION:
             raise hgutil.Abort('revmap too new -- please upgrade')
         return f
@@ -732,6 +739,14 @@ class SqliteRevMap(collections.MutableMa
                 data[revnum, branch or None] = bin(ha)
             self._insert([(r, b, h) for (r, b), h in data.iteritems()])
 
+    @util.gcdisable
+    def exportrevmapv1(self, path):
+        with open(path, 'w') as f:
+            f.write('%s\n' % RevMap.VERSION)
+            for row in self._query('SELECT rev, branch, hash FROM revmap'):
+                rev, br, ha = row
+                f.write('%s %s %s\n' % (rev, hex(ha), br))
+
 
 class FileMap(object):