diff hggit/git_handler.py @ 1024:78959c8e5e60

wlock: take wlock when writing map file Upstream Mercurial now has a devel-warning when writing to a file without taking a lock. Since we already need write access to write the map file, let's take the wlock as well.
author Durham Goode <durham@fb.com>
date Mon, 17 Jul 2017 05:49:23 -0700 (2017-07-17)
parents 17f64b9bfa62
children 078c3912afce
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -197,16 +197,17 @@
         self._map_hg_real = map_hg_real
 
     def save_map(self, map_file):
-        file = self.repo.vfs(map_file, 'w+', atomictemp=True)
-        map_hg = self._map_hg
-        buf = cStringIO.StringIO()
-        bwrite = buf.write
-        for hgsha, gitsha in map_hg.iteritems():
-            bwrite("%s %s\n" % (gitsha, hgsha))
-        file.write(buf.getvalue())
-        buf.close()
-        # If this complains, atomictempfile no longer has close
-        file.close()
+        with self.repo.wlock():
+            file = self.repo.vfs(map_file, 'w+', atomictemp=True)
+            map_hg = self._map_hg
+            buf = cStringIO.StringIO()
+            bwrite = buf.write
+            for hgsha, gitsha in map_hg.iteritems():
+                bwrite("%s %s\n" % (gitsha, hgsha))
+            file.write(buf.getvalue())
+            buf.close()
+            # If this complains, atomictempfile no longer has close
+            file.close()
 
     def load_tags(self):
         self.tags = {}