Show More
@@ -6,7 +6,7 | |||||
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") |
|
9 | demandload(globals(), "os re sys signal shutil") | |
10 | demandload(globals(), "fancyopts ui hg util") |
|
10 | demandload(globals(), "fancyopts ui hg util") | |
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") |
|
12 | demandload(globals(), "errno socket version struct") | |
@@ -384,7 +384,6 def clone(ui, source, dest = None, **opt | |||||
384 |
|
384 | |||
385 | class Dircleanup: |
|
385 | class Dircleanup: | |
386 | def __init__(self, dir_): |
|
386 | def __init__(self, dir_): | |
387 | import shutil |
|
|||
388 | self.rmtree = shutil.rmtree |
|
387 | self.rmtree = shutil.rmtree | |
389 | self.dir_ = dir_ |
|
388 | self.dir_ = dir_ | |
390 | os.mkdir(dir_) |
|
389 | os.mkdir(dir_) | |
@@ -401,10 +400,12 def clone(ui, source, dest = None, **opt | |||||
401 |
|
400 | |||
402 | if other.dev() != -1: |
|
401 | if other.dev() != -1: | |
403 | abspath = os.path.abspath(source) |
|
402 | abspath = os.path.abspath(source) | |
404 |
|
403 | copyfile = (os.stat(dest).st_dev == other.dev() | ||
405 | if other.dev() != -1 and os.stat(dest).st_dev == other.dev(): |
|
404 | and getattr(os, 'link', None) or shutil.copy2) | |
|
405 | if copyfile is not shutil.copy2: | |||
406 | ui.note("cloning by hardlink\n") |
|
406 | ui.note("cloning by hardlink\n") | |
407 | util.system("cp -al '%s'/.hg '%s'/.hg" % (source, dest)) |
|
407 | util.copytree(os.path.join(source, ".hg"), os.path.join(dest, ".hg"), | |
|
408 | copyfile) | |||
408 | try: |
|
409 | try: | |
409 | os.unlink(os.path.join(dest, ".hg", "dirstate")) |
|
410 | os.unlink(os.path.join(dest, ".hg", "dirstate")) | |
410 | except IOError: |
|
411 | except IOError: |
@@ -46,6 +46,21 def rename(src, dst): | |||||
46 | os.unlink(dst) |
|
46 | os.unlink(dst) | |
47 | os.rename(src, dst) |
|
47 | os.rename(src, dst) | |
48 |
|
48 | |||
|
49 | def copytree(src, dst, copyfile): | |||
|
50 | """Copy a directory tree, files are copied using 'copyfile'.""" | |||
|
51 | names = os.listdir(src) | |||
|
52 | os.mkdir(dst) | |||
|
53 | ||||
|
54 | for name in names: | |||
|
55 | srcname = os.path.join(src, name) | |||
|
56 | dstname = os.path.join(dst, name) | |||
|
57 | if os.path.isdir(srcname): | |||
|
58 | copytree(srcname, dstname, copyfile) | |||
|
59 | elif os.path.isfile(srcname): | |||
|
60 | copyfile(srcname, dstname) | |||
|
61 | else: | |||
|
62 | raise IOError("Not a regular file: %r" % srcname) | |||
|
63 | ||||
49 | # Platfor specific varients |
|
64 | # Platfor specific varients | |
50 | if os.name == 'nt': |
|
65 | if os.name == 'nt': | |
51 | nulldev = 'NUL:' |
|
66 | nulldev = 'NUL:' |
General Comments 0
You need to be logged in to leave comments.
Login now