comparison tests/test_util.py @ 910:312f36a425f0

Ignore invalid utf8 in commit messages Old svn allowed users to include invalid utf8 in their commits. Since there are real repos with said invalid utf8, we need to be able to import them, even if svn won't.
author David Schleimer <dschleimer@fb.com>
date Thu, 17 May 2012 14:15:14 -0700
parents c4ee11a5d04c
children 772280aed751 7e9d805a0e1f
comparison
equal deleted inserted replaced
909:e42a05915edf 910:312f36a425f0
5 import os 5 import os
6 import shutil 6 import shutil
7 import stat 7 import stat
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 import tarfile
10 import tempfile 11 import tempfile
11 import unittest 12 import unittest
12 import urllib 13 import urllib
13 14
14 _rootdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 15 _rootdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
299 proc = subprocess.Popen(['svnadmin', 'load', path,], stdin=inp, 300 proc = subprocess.Popen(['svnadmin', 'load', path,], stdin=inp,
300 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 301 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
301 proc.communicate() 302 proc.communicate()
302 return path 303 return path
303 304
305 def load_repo_tarball(self, fixture_name):
306 '''Extracts a tarball of an svn repo and returns the svn repo path.'''
307 path = self._makerepopath()
308 assert not os.path.exists(path)
309 os.mkdir(path)
310 tarball = tarfile.open(os.path.join(FIXTURES, fixture_name))
311 # This is probably somewhat fragile, but I'm not sure how to
312 # do better in particular, I think it assumes that the tar
313 # entries are in the right order and that directories appear
314 # before their contents. This is a valid assummption for sane
315 # tarballs, from what I can tell. In particular, for a simple
316 # tarball of a svn repo with paths relative to the repo root,
317 # it seems to work
318 for entry in tarball:
319 tarball.extract(entry, path)
320 return path
321
304 def fetch(self, repo_path, subdir=None, stupid=False, layout='auto', startrev=0, 322 def fetch(self, repo_path, subdir=None, stupid=False, layout='auto', startrev=0,
305 externals=None, noupdate=True, dest=None, rev=None): 323 externals=None, noupdate=True, dest=None, rev=None):
306 if layout == 'single': 324 if layout == 'single':
307 if subdir is None: 325 if subdir is None:
308 subdir = 'trunk' 326 subdir = 'trunk'
331 dispatch(cmd) 349 dispatch(cmd)
332 350
333 return hg.repository(testui(), self.wc_path) 351 return hg.repository(testui(), self.wc_path)
334 352
335 def load_and_fetch(self, fixture_name, *args, **opts): 353 def load_and_fetch(self, fixture_name, *args, **opts):
336 repo_path = self.load_svndump(fixture_name) 354 if fixture_name.endswith('.svndump'):
355 repo_path = self.load_svndump(fixture_name)
356 elif fixture_name.endswith('tar.gz'):
357 repo_path = self.load_repo_tarball(fixture_name)
358 else:
359 assert False, 'Unknown fixture type'
337 360
338 return self.fetch(repo_path, *args, **opts), repo_path 361 return self.fetch(repo_path, *args, **opts), repo_path
339 362
340 def _load_fixture_and_fetch(self, *args, **kwargs): 363 def _load_fixture_and_fetch(self, *args, **kwargs):
341 repo, repo_path = self.load_and_fetch(*args, **kwargs) 364 repo, repo_path = self.load_and_fetch(*args, **kwargs)