1
# Copyright (C) 2006 by Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tree creators for kernel-like trees"""
27
from bzrlib.benchmarks.tree_creator import TreeCreator
30
class KernelLikeTreeCreator(TreeCreator):
31
"""Create a basic tree with ~10k unversioned files"""
33
def __init__(self, test, link_working=False, url=None):
34
super(KernelLikeTreeCreator, self).__init__(test,
35
tree_name='kernel_like_tree',
36
link_working=link_working,
41
def create(self, root):
42
"""Create all the kernel files in the given location.
44
This is overloaded for compatibility reasons.
46
if self._url is not None:
47
b = bzrdir.BzrDir.create_branch_convenience(self._url)
48
d = bzrdir.BzrDir.create(root)
49
bzrlib.branch.BranchReferenceFormat().initialize(d, b)
50
tree = d.create_workingtree()
52
tree = bzrdir.BzrDir.create_standalone_workingtree(root)
54
if not self._link_working or not self.is_caching_enabled():
55
# Turns out that 'shutil.copytree()' is no faster than
56
# just creating them. Probably the python overhead.
57
# Plain _make_kernel_files takes 3-5s
59
# using hardlinks takes < 1s.
60
self._create_tree(root=root, in_cache=False)
64
cache_dir = self._get_cache_dir()
65
osutils.copy_tree(cache_dir, root,
66
handlers={'file':os.link})
69
def _create_tree(self, root, in_cache=False):
70
# a kernel tree has ~10000 and 500 directory, with most files around
72
# we simulate this by three levels of dirs named 0-7, givin 512 dirs,
75
for outer in range(8):
76
files.append("%s/" % outer)
77
for middle in range(8):
78
files.append("%s/%s/" % (outer, middle))
79
for inner in range(8):
80
prefix = "%s/%s/%s/" % (outer, middle, inner)
82
files.extend([prefix + str(foo) for foo in range(20)])
83
cwd = osutils.getcwd()
85
self._test.build_tree(files)
88
self._protect_files(root)
91
class KernelLikeAddedTreeCreator(TreeCreator):
93
def __init__(self, test, link_working=False, hot_cache=True):
94
super(KernelLikeAddedTreeCreator, self).__init__(test,
95
tree_name='kernel_like_added_tree',
96
link_working=link_working,
100
def _create_tree(self, root, in_cache=False):
101
"""Create a kernel-like tree with the all files added
103
:param root: The root directory to create the files
104
:param in_cache: Is this being created in the cache dir?
106
kernel_creator = KernelLikeTreeCreator(self._test,
107
link_working=in_cache)
108
tree = kernel_creator.create(root=root)
110
# Add everything to it
113
add.smart_add_tree(tree, [root], recurse=True, save=True)
115
self._protect_files(root+'/.bzr')
121
class KernelLikeCommittedTreeCreator(TreeCreator):
122
"""Create a tree with ~10K files, and a single commit adding all of them"""
124
def __init__(self, test, link_working=False, link_bzr=False,
126
super(KernelLikeCommittedTreeCreator, self).__init__(test,
127
tree_name='kernel_like_committed_tree',
128
link_working=link_working,
132
def _create_tree(self, root, in_cache=False):
133
"""Create a kernel-like tree with all files committed
135
:param root: The root directory to create the files
136
:param in_cache: Is this being created in the cache dir?
138
kernel_creator = KernelLikeAddedTreeCreator(self._test,
139
link_working=in_cache,
140
hot_cache=(not in_cache))
141
tree = kernel_creator.create(root=root)
142
tree.commit('first post', rev_id='r1')
145
self._protect_files(root+'/.bzr')