Mercurial > hgsubversion
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 80:83179a183927 | 81:85dcea81f22b |
|---|---|
| 360 """ | 360 """ |
| 361 # works around an svn server keeping too many open files (observed | 361 # works around an svn server keeping too many open files (observed |
| 362 # in an svnserve from the 1.2 era) | 362 # in an svnserve from the 1.2 era) |
| 363 self.init_ra_and_client() | 363 self.init_ra_and_client() |
| 364 | 364 |
| 365 old_cwd = os.getcwd() | |
| 366 assert path[0] != '/' | 365 assert path[0] != '/' |
| 367 url = self.svn_url + '/' + path | 366 url = self.svn_url + '/' + path |
| 368 url2 = url | 367 url2 = url |
| 369 if other_path is not None: | 368 if other_path is not None: |
| 370 url2 = self.svn_url + '/' + other_path | 369 url2 = self.svn_url + '/' + other_path |
| 371 if other_rev is None: | 370 if other_rev is None: |
| 372 other_rev = revision - 1 | 371 other_rev = revision - 1 |
| 372 old_cwd = os.getcwd() | |
| 373 tmpdir = tempfile.mkdtemp('svnwrap_temp') | 373 tmpdir = tempfile.mkdtemp('svnwrap_temp') |
| 374 try: | 374 try: |
| 375 # hot tip: the swig bridge doesn't like StringIO for these bad boys | 375 # hot tip: the swig bridge doesn't like StringIO for these bad boys |
| 376 out_path = os.path.join(tmpdir, 'diffout') | 376 out_path = os.path.join(tmpdir, 'diffout') |
| 377 error_path = os.path.join(tmpdir, 'differr') | 377 error_path = os.path.join(tmpdir, 'differr') |
| 378 out = open(out_path, 'w') | 378 out, err = None, None |
| 379 err = open(error_path, 'w') | 379 try: |
| 380 client.diff3([], url2, optrev(other_rev), url, optrev(revision), | 380 out = open(out_path, 'w') |
| 381 True, True, deleted, ignore_type, 'UTF-8', out, err, | 381 err = open(error_path, 'w') |
| 382 self.client_context, self.pool) | 382 client.diff3([], url2, optrev(other_rev), url, optrev(revision), |
| 383 out.close() | 383 True, True, deleted, ignore_type, 'UTF-8', out, err, |
| 384 err.close() | 384 self.client_context, self.pool) |
| 385 finally: | |
| 386 if out: out.close() | |
| 387 if err: err.close() | |
| 385 assert len(open(error_path).read()) == 0 | 388 assert len(open(error_path).read()) == 0 |
| 386 diff = open(out_path).read() | 389 diff = open(out_path).read() |
| 387 os.chdir(old_cwd) | |
| 388 return diff | 390 return diff |
| 389 finally: | 391 finally: |
| 390 shutil.rmtree(tmpdir) | 392 shutil.rmtree(tmpdir) |
| 393 os.chdir(old_cwd) | |
| 391 | 394 |
| 392 def get_file(self, path, revision): | 395 def get_file(self, path, revision): |
| 393 """Return content and mode of file at given path and revision. | 396 """Return content and mode of file at given path and revision. |
| 394 | 397 |
| 395 Content is raw svn content, symlinks content is still prefixed | 398 Content is raw svn content, symlinks content is still prefixed |
