Rewrite copytree as copyfiles
This inverts the logic of copytree to allow copying single files at
the top level.
--- a/mercurial/commands.py Wed Sep 07 19:16:36 2005 -0700
+++ b/mercurial/commands.py Wed Sep 07 19:21:38 2005 -0700
@@ -607,7 +607,7 @@
# 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"),
+ util.copyfiles(os.path.join(source, ".hg"), os.path.join(dest, ".hg"),
copyfile)
for fn in "dirstate", "lock", "hgrc", "localtags":
--- a/mercurial/util.py Wed Sep 07 19:16:36 2005 -0700
+++ b/mercurial/util.py Wed Sep 07 19:21:38 2005 -0700
@@ -217,20 +217,17 @@
os.unlink(dst)
os.rename(src, dst)
-def copytree(src, dst, copyfile):
+def copyfiles(src, dst, copyfile):
"""Copy a directory tree, files are copied using 'copyfile'."""
- names = os.listdir(src)
- os.mkdir(dst)
- for name in names:
- srcname = os.path.join(src, name)
- dstname = os.path.join(dst, name)
- if os.path.isdir(srcname):
- copytree(srcname, dstname, copyfile)
- elif os.path.isfile(srcname):
- copyfile(srcname, dstname)
- else:
- pass
+ if os.path.isdir(src):
+ os.mkdir(dst)
+ for name in os.listdir(src):
+ srcname = os.path.join(src, name)
+ dstname = os.path.join(dst, name)
+ copyfiles(srcname, dstname, copyfile)
+ else:
+ copyfile(src, dst)
def opener(base):
"""