[PATCH] hg: move DirCleanup class so it's not nested

Augie Fackler raf at durin42.com
Fri Oct 5 18:17:37 CDT 2012


# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1349478656 18000
# Node ID 6f4b1adf77051c8a999831d6468f76d5a953f43f
# Parent  fa714f3ed2989aff64c267c9935251d9fc4f31ee
hg: move DirCleanup class so it's not nested

There wasn't any need for the class to be nested, and this makes the code
just a little easier to read.

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -217,6 +217,16 @@
         release(destlock)
         raise
 
+class _DirCleanup(object):
+    def __init__(self, dir_):
+        self.rmtree = shutil.rmtree
+        self.dir_ = dir_
+    def close(self):
+        self.dir_ = None
+    def cleanup(self):
+        if self.dir_:
+            self.rmtree(self.dir_, True)
+
 def clone(ui, peeropts, source, dest=None, pull=False, rev=None,
           update=True, stream=False, branch=None):
     """Make a copy of an existing repository.
@@ -281,16 +291,6 @@
         elif os.listdir(dest):
             raise util.Abort(_("destination '%s' is not empty") % dest)
 
-    class DirCleanup(object):
-        def __init__(self, dir_):
-            self.rmtree = shutil.rmtree
-            self.dir_ = dir_
-        def close(self):
-            self.dir_ = None
-        def cleanup(self):
-            if self.dir_:
-                self.rmtree(self.dir_, True)
-
     srclock = destlock = dircleanup = None
     srcrepo = srcpeer.local()
     try:
@@ -299,7 +299,7 @@
             abspath = os.path.abspath(util.urllocalpath(origsource))
 
         if islocal(dest):
-            dircleanup = DirCleanup(dest)
+            dircleanup = _DirCleanup(dest)
 
         copy = False
         if (srcrepo and srcrepo.cancopy() and islocal(dest)


More information about the Mercurial-devel mailing list