# HG changeset patch # User Adrian Buehlmann # Date 2011-02-12 09:58:11 # Node ID d747774ca9da14ec90b8dde8319a83f8aa0c42b5 # Parent d073468e3c5f2b6160c54a513badd031883ed2ad Make sure bundlerepo doesn't leak temp files (issue2491) Add empty repository.close() and call it in dispatch. Remove bundlerepository.__del__(), merging it into bundlerepository.close(), which overrides repository.close(). http://docs.python.org/reference/datamodel.html says: "It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits." diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py --- a/mercurial/bundlerepo.py +++ b/mercurial/bundlerepo.py @@ -251,11 +251,6 @@ class bundlerepository(localrepo.localre self.bundle.close() if self.tempfile is not None: os.unlink(self.tempfile) - - def __del__(self): - del self.bundle - if self.tempfile is not None: - os.unlink(self.tempfile) if self._tempparent: shutil.rmtree(self._tempparent, True) diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -589,8 +589,12 @@ def _dispatch(ui, args): msg = ' '.join(' ' in a and repr(a) or a for a in fullargs) ui.log("command", msg + "\n") d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) - return runcommand(lui, repo, cmd, fullargs, ui, options, d, - cmdpats, cmdoptions) + try: + return runcommand(lui, repo, cmd, fullargs, ui, options, d, + cmdpats, cmdoptions) + finally: + if repo: + repo.close() def _runcommand(ui, options, cmd, cmdfunc): def checkargs(): diff --git a/mercurial/repo.py b/mercurial/repo.py --- a/mercurial/repo.py +++ b/mercurial/repo.py @@ -35,3 +35,6 @@ class repository(object): def cancopy(self): return self.local() + + def close(self): + pass diff --git a/tests/test-bundle.t b/tests/test-bundle.t --- a/tests/test-bundle.t +++ b/tests/test-bundle.t @@ -188,6 +188,13 @@ Log -R full.hg in fresh empty date: Thu Jan 01 00:00:00 1970 +0000 summary: 0.0 +Make sure bundlerepo doesn't leak tempfiles (issue2491) + + $ ls .hg + 00changelog.i + cache + requires + store Pull ../full.hg into empty (with hook)