Skip to content
Snippets Groups Projects
Commit 9ccddb7e330b authored by Boris Feld's avatar Boris Feld
Browse files

exchange: store tar cache in repos/.cache

Also extract clone test in their own class to avoid cloning several times
parent d99e66b6e060
No related branches found
No related tags found
No related merge requests found
...@@ -138,6 +138,6 @@ ...@@ -138,6 +138,6 @@
class ExchangeTrackSuite(BaseTrackTestSuite): class ExchangeTrackSuite(BaseTrackTestSuite):
param_names = BaseTrackTestSuite.param_names + ['single_rev', 'revset'] param_names = BaseTrackTestSuite.param_names + ['revset']
params = BaseTrackTestSuite.params + [[True, False]] + [['default~10']] params = BaseTrackTestSuite.params + [['default~10', None]]
...@@ -143,4 +143,4 @@ ...@@ -143,4 +143,4 @@
def setup(self, repo_name, single_rev, revset, *args, **kwargs): def setup(self, repo_name, revset, *args, **kwargs):
super(ExchangeTrackSuite, self).setup(repo_name, *args, **kwargs) super(ExchangeTrackSuite, self).setup(repo_name, *args, **kwargs)
...@@ -145,6 +145,8 @@ ...@@ -145,6 +145,8 @@
super(ExchangeTrackSuite, self).setup(repo_name, *args, **kwargs) super(ExchangeTrackSuite, self).setup(repo_name, *args, **kwargs)
self.single_rev = single_rev self.revset = revset
self.cachedir = os.path.join(REPOS_DIR, '.cache')
from base64 import b64encode from base64 import b64encode
...@@ -148,6 +150,4 @@ ...@@ -148,6 +150,4 @@
from base64 import b64encode from base64 import b64encode
self.safe_range = b64encode(revset)
self.tempdir = tempfile.mkdtemp(dir=os.environ.get('ASVTEMPDIR'))
...@@ -153,3 +153,3 @@ ...@@ -153,3 +153,3 @@
if single_rev is False: if revset is None:
self.cache_name = "%s.tar" % repo_name self.cache_name = "%s.tar" % repo_name
...@@ -155,7 +155,7 @@ ...@@ -155,7 +155,7 @@
self.cache_name = "%s.tar" % repo_name self.cache_name = "%s.tar" % repo_name
self.cache_path = os.path.join(self.tempdir, self.cache_name) self.cache_path = os.path.join(self.cachedir, self.cache_name)
if not os.path.isfile(self.cache_path): if not os.path.isfile(self.cache_path):
tar_cmd = "tar cf %s -C %s ." % (self.cache_path, self.repo_path) tar_cmd = "tar cf %s -C %s ." % (self.cache_path, self.repo_path)
self._single_execute(shlex.split(tar_cmd)) self._single_execute(shlex.split(tar_cmd))
else: else:
...@@ -157,10 +157,11 @@ ...@@ -157,10 +157,11 @@
if not os.path.isfile(self.cache_path): if not os.path.isfile(self.cache_path):
tar_cmd = "tar cf %s -C %s ." % (self.cache_path, self.repo_path) tar_cmd = "tar cf %s -C %s ." % (self.cache_path, self.repo_path)
self._single_execute(shlex.split(tar_cmd)) self._single_execute(shlex.split(tar_cmd))
else: else:
self.cache_name = "%s-%s-%s.tar" % (repo_name, single_rev, self.safe_range) safe_range = b64encode(revset)
self.cache_path = os.path.join(self.tempdir, self.cache_name) self.cache_name = "%s-%s.tar" % (repo_name, safe_range)
self.cache_path = os.path.join(self.cachedir, self.cache_name)
if not os.path.isfile(self.cache_path): if not os.path.isfile(self.cache_path):
# First clone it # First clone it
...@@ -164,7 +165,7 @@ ...@@ -164,7 +165,7 @@
if not os.path.isfile(self.cache_path): if not os.path.isfile(self.cache_path):
# First clone it # First clone it
clone_path = os.path.join(self.tempdir, "%s-%s-clone" % (repo_name, self.safe_range)) clone_path = os.path.join(self.cachedir, "%s-%s-clone" % (repo_name, safe_range))
rev = self._identify_id(revset) rev = self._identify_id(revset)
...@@ -178,5 +179,11 @@ ...@@ -178,5 +179,11 @@
shutil.rmtree(clone_path) shutil.rmtree(clone_path)
def teardown(self, *args, **kwargs): def _identify_id(self, revset):
rev = subprocess.check_output([
self.hgpath, '--cwd', self.repo_path, 'identify', '-i', "-r", revset], env=self.environ)
return rev.strip()
@contextlib.contextmanager
def clone_from_cache(self):
try: try:
...@@ -182,7 +189,59 @@ ...@@ -182,7 +189,59 @@
try: try:
shutil.rmtree(self.tempdir) import time
except Exception: clone_path = os.path.join(self.cachedir, 'clone-%s' % time.time())
pass
os.mkdir(clone_path)
cmd = "tar xf %s -C %s" % (self.cache_path, clone_path)
clone_time = self._single_execute(shlex.split(cmd))
yield clone_path
finally:
shutil.rmtree(clone_path)
def track_incoming(self, repo_name, revset):
with self.clone_from_cache() as clone_path:
cmd = [self.hgpath, '--cwd', clone_path, 'incoming', self.repo_path]
if revset:
cmd.extend(['-r', 'default'])
# Ignore the return code
return self._timeit(self._single_execute, (cmd, False))
def track_outgoing(self, repo_name, revset):
with self.clone_from_cache() as clone_path:
cmd = [self.hgpath, '--cwd', self.repo_path, 'outgoing',
clone_path]
if revset:
cmd.extend(['-r', 'default'])
# Ignore the return code
return self._timeit(self._single_execute, (cmd, False))
def track_push(self, repo_name, revset):
def clone_and_push():
with self.clone_from_cache() as clone_path:
cmd = [self.hgpath, '--cwd', self.repo_path, 'push', '-f',
clone_path]
if revset:
cmd.extend(['-r', 'default'])
return self._single_execute(cmd, False)
return self._timeit(clone_and_push)
class CloneTrackSuite(BaseTrackTestSuite):
param_names = BaseTrackTestSuite.param_names + ['single_rev', 'revset']
params = BaseTrackTestSuite.params + [[True, False]] + [['default~10']]
def track_clone(self, repo_name, single_rev, revset):
revset = 'default' if single_rev else None
def clone():
with self.clone(revset=revset) as (_, clone_time):
return clone_time
return self._timeit(clone)
def _identify_id(self, revset): def _identify_id(self, revset):
rev = subprocess.check_output([ rev = subprocess.check_output([
...@@ -202,56 +261,3 @@ ...@@ -202,56 +261,3 @@
yield clone_path, clone_time yield clone_path, clone_time
finally: finally:
shutil.rmtree(clone_path) shutil.rmtree(clone_path)
@contextlib.contextmanager
def clone_from_cache(self):
try:
import time
clone_path = os.path.join(self.tempdir, 'clone-%s' % time.time())
os.mkdir(clone_path)
cmd = "tar xf %s -C %s" % (self.cache_path, clone_path)
clone_time = self._single_execute(shlex.split(cmd))
yield clone_path
finally:
shutil.rmtree(clone_path)
def track_incoming(self, repo_name, single_rev, revset):
with self.clone_from_cache() as clone_path:
cmd = [self.hgpath, '--cwd', clone_path, 'incoming', self.repo_path]
if single_rev:
cmd.extend(['-r', 'default'])
# Ignore the return code
return self._timeit(self._single_execute, (cmd, False))
def track_outgoing(self, repo_name, single_rev, revset):
with self.clone_from_cache() as clone_path:
cmd = [self.hgpath, '--cwd', self.repo_path, 'outgoing',
clone_path]
if single_rev:
cmd.extend(['-r', 'default'])
# Ignore the return code
return self._timeit(self._single_execute, (cmd, False))
def track_push(self, repo_name, single_rev, revset):
def clone_and_push():
with self.clone_from_cache() as clone_path:
cmd = [self.hgpath, '--cwd', self.repo_path, 'push', '-f',
clone_path]
if single_rev:
cmd.extend(['-r', 'default'])
return self._single_execute(cmd, False)
return self._timeit(clone_and_push)
def track_clone(self, repo_name, single_rev, revset):
revset = 'default' if single_rev else None
def clone():
with self.clone(revset=revset) as (_, clone_time):
return clone_time
return self._timeit(clone)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment