27
27
from bzrlib.bundle import read_bundle
28
28
from bzrlib.revisionspec import RevisionSpec
30
# If the CACHEDIR flag is set, make_parametrized_tree below will cache the tree
31
# it creates in the .bazaar/temp dir.
32
CACHEDIR = os.path.expanduser("~/.bazaar/temp")
30
# if set, creation of test trees will be globally cached
31
CACHEDIR = os.path.expanduser("~/.bazaar/devtemp")
34
def cached_make(maker, *args):
39
if not os.path.exists(CACHEDIR):
42
cache_name = "_".join([maker.__name__] + [str(x) for x in args])
43
if not os.path.exists(cache_name):
50
shutil.rmtree(cache_name)
54
for subdir in os.listdir(cache_name):
55
shutil.copytree(os.path.join(cache_name, subdir),
56
os.path.join(olddir, subdir))
35
60
class BundleBenchmark(Benchmark):
37
62
The bundle tests should (also) be done at a lower level with
38
63
direct call to the bzrlib."""
65
def make_kernel_like_tree_committed(self):
66
cached_make(self.make_kernel_like_tree)
68
self.run_bzr('commit', '-m', 'initial import')
41
70
def test_create_bundle_known_kernel_like_tree(self):
43
72
Create a bundle for a kernel sized tree with no ignored, unknowns,
44
73
or added and one commit."""
45
self.make_kernel_like_tree()
47
self.run_bzr('commit', '-m', 'initial import')
74
cached_make(self.make_kernel_like_tree_committed)
48
75
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
50
77
def test_create_bundle_many_commit_tree (self):
52
79
Create a bundle for a tree with many commits but no changes."""
53
self.make_many_commit_tree()
80
cached_make(self.make_many_commit_tree)
54
81
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
56
83
def test_create_bundle_heavily_merged_tree(self):
58
85
Create a bundle for a heavily merged tree."""
59
self.make_heavily_merged_tree()
86
cached_make(self.make_heavily_merged_tree)
60
87
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
62
89
def test_apply_bundle_known_kernel_like_tree(self):
64
91
Create a bundle for a kernel sized tree with no ignored, unknowns,
65
92
or added and one commit."""
66
self.make_kernel_like_tree()
68
self.run_bzr('commit', '-m', 'initial import')
69
self.run_bzr('branch', '.', '../branch_a')
70
self.run_bzr('bundle', '--revision', '..-1')
93
cached_make(self.make_kernel_like_tree_committed)
71
94
f = file('../bundle', 'wb')
73
96
f.write(self.run_bzr('bundle', '--revision', '..-1')[0])
99
self.run_bzr("init", "../branch_a")
76
100
os.chdir('../branch_a')
77
101
self.time(self.run_bzr, 'merge', '../bundle')
91
115
:param num_revisions: number of revisions
92
116
:param num_files_in_bundle: number of files changed in the revisions
95
return self._make_parametrized_tree(num_files, num_revisions,
99
if not os.path.exists(CACHEDIR):
100
os.makedirs(CACHEDIR)
102
cache_name = "make_parametrized_tree_%s_%s_%s" % (
103
num_files, num_revisions, num_files_in_bundle)
104
if not os.path.exists(cache_name):
107
self._make_parametrized_tree(num_files, num_revisions,
110
for subdir in os.listdir(cache_name):
111
shutil.copytree(os.path.join(cache_name, subdir),
112
os.path.join(olddir, subdir))
116
def _make_parametrized_tree(self, num_files, num_revisions,
117
num_files_in_bundle):