comparison mercurial/commands.py @ 917:7f3f55903496

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.
author mpm@selenic.com
date Tue, 16 Aug 2005 14:53:47 -0800
parents 24a31f46fa13
children fe69ecd3437c
comparison
equal deleted inserted replaced
916:fe094cca9915 917:7f3f55903496
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 from demandload import demandload 8 from demandload import demandload
9 demandload(globals(), "os re sys signal shutil") 9 demandload(globals(), "os re sys signal shutil")
10 demandload(globals(), "fancyopts ui hg util") 10 demandload(globals(), "fancyopts ui hg util lock")
11 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") 11 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
12 demandload(globals(), "errno socket version struct atexit") 12 demandload(globals(), "errno socket version struct atexit")
13 13
14 class UnknownCommand(Exception): 14 class UnknownCommand(Exception):
15 """Exception raised if command is not in the command table.""" 15 """Exception raised if command is not in the command table."""
492 abspath = os.path.abspath(source) 492 abspath = os.path.abspath(source)
493 copyfile = (os.stat(dest).st_dev == other.dev() 493 copyfile = (os.stat(dest).st_dev == other.dev()
494 and getattr(os, 'link', None) or shutil.copy2) 494 and getattr(os, 'link', None) or shutil.copy2)
495 if copyfile is not shutil.copy2: 495 if copyfile is not shutil.copy2:
496 ui.note("cloning by hardlink\n") 496 ui.note("cloning by hardlink\n")
497 # we use a lock here because because we're not nicely ordered
498 l = lock.lock(os.path.join(source, ".hg", "lock"))
499
497 util.copytree(os.path.join(source, ".hg"), os.path.join(dest, ".hg"), 500 util.copytree(os.path.join(source, ".hg"), os.path.join(dest, ".hg"),
498 copyfile) 501 copyfile)
499 try: 502 try:
500 os.unlink(os.path.join(dest, ".hg", "dirstate")) 503 os.unlink(os.path.join(dest, ".hg", "dirstate"))
501 except OSError: 504 except OSError: