Fix hg clone race with writer
authormpm@selenic.com
Tue, 16 Aug 2005 14:53:47 -0800
changeset 917 7f3f55903496
parent 916 fe094cca9915
child 918 fe69ecd3437c
Fix hg clone race with writer Most read operations in hg don't need locks because we order reads and writes for consistency. Clone is an exception to this as we're copying entire file histories and could end up with more file history copied than we have commits. For now, make clone take a lock on the source repo. Non-hardlinked clone should eventually be changed to use lockless pull.
mercurial/commands.py
mercurial/util.py
--- a/mercurial/commands.py	Tue Aug 16 14:17:27 2005 -0800
+++ b/mercurial/commands.py	Tue Aug 16 14:53:47 2005 -0800
@@ -7,7 +7,7 @@
 
 from demandload import demandload
 demandload(globals(), "os re sys signal shutil")
-demandload(globals(), "fancyopts ui hg util")
+demandload(globals(), "fancyopts ui hg util lock")
 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
 demandload(globals(), "errno socket version struct atexit")
 
@@ -494,6 +494,9 @@
                     and getattr(os, 'link', None) or shutil.copy2)
         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"))
+
         util.copytree(os.path.join(source, ".hg"), os.path.join(dest, ".hg"),
                       copyfile)
         try:
--- a/mercurial/util.py	Tue Aug 16 14:17:27 2005 -0800
+++ b/mercurial/util.py	Tue Aug 16 14:53:47 2005 -0800
@@ -187,7 +187,7 @@
         elif os.path.isfile(srcname):
             copyfile(srcname, dstname)
         else:
-            raise IOError("Not a regular file: %r" % srcname)
+            pass
 
 def _makelock_file(info, pathname):
     ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL)