Patchwork hg: replace DirCleanup class with normal try/finally use

login
register
mail settings
Submitter Augie Fackler
Date Jan. 18, 2013, 5:54 p.m.
Message ID <5f95b0fa9aa57903bfcf.1358531692@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/675/
State Accepted
Commit 1f794204abbd7dd4bc329ae0c7c4fd7ce56b33af
Headers show

Comments

Augie Fackler - Jan. 18, 2013, 5:54 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1349478656 18000
# Node ID 5f95b0fa9aa57903bfcf5753836cd7107de723ef
# Parent  35513c59f376a39a60f1d8f602bea23725d6a61d
hg: replace DirCleanup class with normal try/finally use
Matt Mackall - Jan. 18, 2013, 5:59 p.m.
On Fri, 2013-01-18 at 12:54 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1349478656 18000
> # Node ID 5f95b0fa9aa57903bfcf5753836cd7107de723ef
> # Parent  35513c59f376a39a60f1d8f602bea23725d6a61d
> hg: replace DirCleanup class with normal try/finally use

Queued for default, thanks.

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -291,17 +291,7 @@ 
         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
+    srclock = destlock = cleandir = None
     srcrepo = srcpeer.local()
     try:
         abspath = origsource
@@ -309,7 +299,7 @@ 
             abspath = os.path.abspath(util.urllocalpath(origsource))
 
         if islocal(dest):
-            dircleanup = DirCleanup(dest)
+            cleandir = dest
 
         copy = False
         if (srcrepo and srcrepo.cancopy() and islocal(dest)
@@ -333,13 +323,13 @@ 
                 os.mkdir(dest)
             else:
                 # only clean up directories we create ourselves
-                dircleanup.dir_ = hgdir
+                cleandir = hgdir
             try:
                 destpath = hgdir
                 util.makedir(destpath, notindexed=True)
             except OSError, inst:
                 if inst.errno == errno.EEXIST:
-                    dircleanup.close()
+                    cleandir = None
                     raise util.Abort(_("destination '%s' already exists")
                                      % dest)
                 raise
@@ -367,7 +357,7 @@ 
                                 # only pass ui when no srcrepo
             except OSError, inst:
                 if inst.errno == errno.EEXIST:
-                    dircleanup.close()
+                    cleandir = None
                     raise util.Abort(_("destination '%s' already exists")
                                      % dest)
                 raise
@@ -387,8 +377,7 @@ 
             else:
                 raise util.Abort(_("clone from remote to remote not supported"))
 
-        if dircleanup:
-            dircleanup.close()
+        cleandir = None
 
         # clone all bookmarks except divergent ones
         destrepo = destpeer.local()
@@ -454,8 +443,8 @@ 
         return srcpeer, destpeer
     finally:
         release(srclock, destlock)
-        if dircleanup is not None:
-            dircleanup.cleanup()
+        if cleandir is not None:
+            shutil.rmtree(cleandir, True)
         if srcpeer is not None:
             srcpeer.close()