Mercurial > hgsubversion
diff svnwrap/svn_swig_wrapper.py @ 81:85dcea81f22b
SubversionRepo: close files before rmtree() in diff3
Open files cannot be removed if open (by default) under Windows.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 14 Nov 2008 16:18:24 -0600 |
parents | ed3dd5bf45da |
children | 6c9b7cf1c5aa |
line wrap: on
line diff
--- a/svnwrap/svn_swig_wrapper.py +++ b/svnwrap/svn_swig_wrapper.py @@ -362,7 +362,6 @@ class SubversionRepo(object): # in an svnserve from the 1.2 era) self.init_ra_and_client() - old_cwd = os.getcwd() assert path[0] != '/' url = self.svn_url + '/' + path url2 = url @@ -370,24 +369,28 @@ class SubversionRepo(object): url2 = self.svn_url + '/' + other_path if other_rev is None: other_rev = revision - 1 + old_cwd = os.getcwd() tmpdir = tempfile.mkdtemp('svnwrap_temp') try: # hot tip: the swig bridge doesn't like StringIO for these bad boys out_path = os.path.join(tmpdir, 'diffout') error_path = os.path.join(tmpdir, 'differr') - out = open(out_path, 'w') - err = open(error_path, 'w') - client.diff3([], url2, optrev(other_rev), url, optrev(revision), - True, True, deleted, ignore_type, 'UTF-8', out, err, - self.client_context, self.pool) - out.close() - err.close() + out, err = None, None + try: + out = open(out_path, 'w') + err = open(error_path, 'w') + client.diff3([], url2, optrev(other_rev), url, optrev(revision), + True, True, deleted, ignore_type, 'UTF-8', out, err, + self.client_context, self.pool) + finally: + if out: out.close() + if err: err.close() assert len(open(error_path).read()) == 0 diff = open(out_path).read() - os.chdir(old_cwd) return diff finally: shutil.rmtree(tmpdir) + os.chdir(old_cwd) def get_file(self, path, revision): """Return content and mode of file at given path and revision.