debugobsconvert: take the lock when writing the obsstore file
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 16 Jul 2017 11:11:06 +0200
changeset 2748 723f5b505c48
parent 2747 9fd6c8efda5b
child 2749 e1b7ea48e243
debugobsconvert: take the lock when writing the obsstore file We were upgrading the store unprotected.
hgext3rd/evolve/__init__.py
--- a/hgext3rd/evolve/__init__.py	Fri Jul 14 08:08:32 2017 +0530
+++ b/hgext3rd/evolve/__init__.py	Sun Jul 16 11:11:06 2017 +0200
@@ -2998,23 +2998,24 @@
     if new_format == repo.obsstore._version:
         msg = _('New format is the same as the old format, not upgrading!')
         raise error.Abort(msg)
-    f = repo.svfs('obsstore', 'wb', atomictemp=True)
-    known = set()
-    markers = []
-    for m in origmarkers:
-        # filter out invalid markers
-        if nullid in m[1]:
-            m = list(m)
-            m[1] = tuple(s for s in m[1] if s != nullid)
-            m = tuple(m)
-        if m in known:
-            continue
-        known.add(m)
-        markers.append(m)
-    ui.write(_('Old store is version %d, will rewrite in version %d\n') % (
-        repo.obsstore._version, new_format))
-    map(f.write, obsolete.encodemarkers(markers, True, new_format))
-    f.close()
+    with repo.lock():
+        f = repo.svfs('obsstore', 'wb', atomictemp=True)
+        known = set()
+        markers = []
+        for m in origmarkers:
+            # filter out invalid markers
+            if nullid in m[1]:
+                m = list(m)
+                m[1] = tuple(s for s in m[1] if s != nullid)
+                m = tuple(m)
+            if m in known:
+                continue
+            known.add(m)
+            markers.append(m)
+        ui.write(_('Old store is version %d, will rewrite in version %d\n') % (
+            repo.obsstore._version, new_format))
+        map(f.write, obsolete.encodemarkers(markers, True, new_format))
+        f.close()
     ui.write(_('Done!\n'))