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 version 2 as published by
5
# the Free Software Foundation.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU General Public License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
"""Tests for bzr bundle performance."""
20
from StringIO import StringIO
22
from bzrlib.benchmarks import Benchmark
23
from bzrlib.workingtree import WorkingTree
24
from bzrlib.branch import Branch
25
from bzrlib.bundle.serializer import write_bundle
26
from bzrlib.revisionspec import RevisionSpec
29
class BundleBenchmark(Benchmark):
31
The bundle tests should (also) be done at a lower level with
32
direct call to the bzrlib."""
35
def test_create_bundle_known_kernel_like_tree(self):
37
Create a bundle for a kernel sized tree with no ignored, unknowns,
38
or added and one commit."""
39
self.make_kernel_like_tree()
41
self.run_bzr('commit', '-m', 'initial import')
42
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
44
def test_create_bundle_many_commit_tree (self):
46
Create a bundle for a tree with many commits but no changes."""
47
self.make_many_commit_tree()
48
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
50
def test_create_bundle_heavily_merged_tree(self):
52
Create a bundle for a heavily merged tree."""
53
self.make_heavily_merged_tree()
54
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
56
def test_apply_bundle_known_kernel_like_tree(self):
58
Create a bundle for a kernel sized tree with no ignored, unknowns,
59
or added and one commit."""
60
self.make_kernel_like_tree()
62
self.run_bzr('commit', '-m', 'initial import')
63
self.run_bzr('branch', '.', '../branch_a')
64
self.run_bzr('bundle', '--revision', '..-1')
65
f = file('../bundle', 'wb')
67
f.write(self.run_bzr('bundle', '--revision', '..-1')[0])
70
os.chdir('../branch_a')
71
self.time(self.run_bzr, 'merge', '../bundle')
74
class BundleLibraryLevelBenchmark(Benchmark):
76
def make_parametrized_tree(self, num_files, num_revisions,
78
"""Create a tree with given parameters. Always creates 2 levels of
79
directories with the given number of files. Then the given number of
80
revisions are created, changing some lines in one files in each
81
revision. Only num_files_in_bundle files are changed in these
84
:param num_files: number of files in tree
85
:param num_revisions: number of revisions
86
:param num_files_in_bundle: number of files changed in the revisions
92
for outer in range(num_files // 64 + 1):
93
directories.append("%s/" % outer)
94
for middle in range(8):
95
prefix = "%s/%s/" % (outer, middle)
96
directories.append(prefix)
97
for filename in range(min(8, num_files - count)):
99
files.append(prefix + str(filename))
101
self.build_tree(directories + files)
102
for d in directories:
103
self.run_bzr('add', d)
104
self.run_bzr('commit', '-m', 'initial repo layout')
106
affected_files = files[:num_files_in_bundle]
108
for changes_file in range(num_revisions // num_files_in_bundle + 1):
109
for f in affected_files:
111
if count >= num_revisions:
113
content = "\n".join([str(i) for i in range(changes_file)] +
114
[str(changes_file)] * 5) + "\n"
115
self.build_tree_contents([(f, content)])
116
self.run_bzr("commit", '-m', 'some changes')
117
assert count >= num_revisions
119
for treesize, treesize_h in [(5, "small"), (100, "moderate"),
121
for bundlefiles, bundlefiles_h in [(5, "few"), (100, "some"),
123
if bundlefiles > treesize:
125
for num_revisions in [1, 500, 1000]:
127
def test_%s_files_%s_tree_%s_revision(self):
128
self.make_parametrized_tree(%s, %s, %s)
129
branch, _ = Branch.open_containing(".")
130
revision_history = branch.revision_history()
131
bundle_text = StringIO()
132
self.time(write_bundle, branch.repository, revision_history[-1],
133
None, bundle_text)""" % (
134
bundlefiles_h, treesize_h, num_revisions,
135
treesize, num_revisions, bundlefiles)