Tighten up clone locking
authormpm@selenic.com
Wed, 07 Sep 2005 19:37:11 -0700
changeset 1209 920682a532df
parent 1208 4644df4944ff
child 1210 27f2ec705332
Tighten up clone locking Add a lock on the destination, expand comment on source lock
mercurial/commands.py
--- a/mercurial/commands.py	Wed Sep 07 19:30:23 2005 -0700
+++ b/mercurial/commands.py	Wed Sep 07 19:37:11 2005 -0700
@@ -605,10 +605,14 @@
         if copyfile is not shutil.copy2:
             ui.note("cloning by hardlink\n")
 
-        # we use a lock here because because we're not nicely ordered
-        l = lock.lock(os.path.join(source, ".hg", "lock"))
+        # we use a lock here because if we race with commit, we can
+        # end up with extra data in the cloned revlogs that's not
+        # pointed to by changesets, thus causing verify to fail
+        l1 = lock.lock(os.path.join(source, ".hg", "lock"))
 
+        # and here to avoid premature writing to the target
         os.mkdir(os.path.join(dest, ".hg"))
+        l2 = lock.lock(os.path.join(dest, ".hg", "lock"))
 
         files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i"
         for f in files.split():