mercurial/commands.py
changeset 542 eda4c32c167a
parent 541 abaea35387a8
parent 535 fba26990604a
child 546 c8ae964109c1
--- a/mercurial/commands.py	Thu Jun 30 07:16:05 2005 +0100
+++ b/mercurial/commands.py	Thu Jun 30 21:47:23 2005 +0100
@@ -232,6 +232,9 @@
             f = name.find('@')
             if f >= 0:
                 name = name[:f]
+            f = name.find('<')
+            if f >= 0:
+                name = name[f+1:]
             bcache[rev] = name
             return name
 
@@ -269,55 +272,59 @@
     """make a copy of an existing repository"""
     source = ui.expandpath(source)
 
-    success = False
+    if dest is None:
+        dest = os.path.basename(os.path.normpath(source))
 
-    if dest is None:
-        dest = os.path.basename(source)
-        if dest == source:
-            ui.warn('abort: source and destination are the same\n')
-            sys.exit(1)
+    if os.path.exists(dest):
+        ui.warn("abort: destination '%s' already exists\n" % dest)
+        return 1
 
-    os.mkdir(dest)
+    class dircleanup:
+        def __init__(self, dir):
+            self.dir = dir
+            os.mkdir(dir)
+        def close(self):
+            self.dir = None
+        def __del__(self):
+            if self.dir:
+                import shutil
+                shutil.rmtree(self.dir, True)
 
-    try:
-        link = 0
-        if not (source.startswith("http://") or
-                source.startswith("hg://") or
-                source.startswith("old-http://")):
-            d1 = os.stat(dest).st_dev
-            d2 = os.stat(source).st_dev
-            if d1 == d2: link = 1
+    d = dircleanup(dest)
 
-        if link:
-            ui.debug("copying by hardlink\n")
-            util.system("cp -al '%s'/.hg '%s'/.hg" % (source, dest))
-            try:
-                os.remove(os.path.join(dest, ".hg", "dirstate"))
-            except: pass
+    link = 0
+    if not (source.startswith("http://") or
+            source.startswith("hg://") or
+            source.startswith("old-http://")):
+        d1 = os.stat(dest).st_dev
+        d2 = os.stat(source).st_dev
+        if d1 == d2: link = 1
 
-            repo = hg.repository(ui, dest)
+    if link:
+        ui.note("copying by hardlink\n")
+        util.system("cp -al '%s'/.hg '%s'/.hg" % (source, dest))
+        try:
+            os.remove(os.path.join(dest, ".hg", "dirstate"))
+        except: pass
+
+        repo = hg.repository(ui, dest)
 
-        else:
-            repo = hg.repository(ui, dest, create=1)
-            other = hg.repository(ui, source)
-            fetch = repo.findincoming(other)
-            if fetch:
-                cg = other.changegroup(fetch)
-                repo.addchangegroup(cg)
+    else:
+        repo = hg.repository(ui, dest, create=1)
+        other = hg.repository(ui, source)
+        fetch = repo.findincoming(other)
+        if fetch:
+            cg = other.changegroup(fetch)
+            repo.addchangegroup(cg)
 
-        f = repo.opener("hgrc", "w")
-        f.write("[paths]\n")
-        f.write("default = %s\n" % source)
-
-        if not opts['noupdate']:
-            update(ui, repo)
+    f = repo.opener("hgrc", "w")
+    f.write("[paths]\n")
+    f.write("default = %s\n" % source)
 
-        success = True
+    if not opts['noupdate']:
+        update(ui, repo)
 
-    finally:
-        if not success:
-            import shutil
-            shutil.rmtree(dest, True)
+    d.close()
 
 def commit(ui, repo, *files, **opts):
     """commit the specified files or all outstanding changes"""