Mercurial > hg-stable
changeset 18441:1f794204abbd
hg: replace DirCleanup class with normal try/finally use
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 05 Oct 2012 18:10:56 -0500 |
parents | 35513c59f376 |
children | ecba9b0e7672 |
files | mercurial/hg.py |
diffstat | 1 files changed, 8 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hg.py Wed Jan 16 19:21:03 2013 +0100 +++ b/mercurial/hg.py Fri Oct 05 18:10:56 2012 -0500 @@ -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()