bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
2052.3.4
by John Arbash Meinel
 [merge] bzr.dev  | 
1  | 
# Copyright (C) 2006 Canonical Ltd
 | 
| 
1908.3.14
by Carl Friedrich Bolz
 Refactor the bundle benchmarks to use the existing helper functions.  | 
2  | 
#
 | 
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.
 | 
|
7  | 
#
 | 
|
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.
 | 
|
12  | 
#
 | 
|
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
 | 
|
16  | 
||
17  | 
"""Tree creator for many commits, including file changes."""
 | 
|
18  | 
||
19  | 
from bzrlib import (  | 
|
20  | 
bzrdir,  | 
|
21  | 
    )
 | 
|
22  | 
||
23  | 
from bzrlib.benchmarks.tree_creator import TreeCreator  | 
|
24  | 
||
25  | 
||
26  | 
class ManyCommitTreeCreator(TreeCreator):  | 
|
27  | 
"""Create an tree many files and many commits."""  | 
|
28  | 
||
29  | 
def __init__(self, test, link_bzr=False, num_files=10, num_commits=10):  | 
|
| 
1908.3.15
by Carl Friedrich Bolz
 Fix problems pointed out by John:  | 
30  | 
tree_name = 'many_files_many_commit_tree_%d_%d' % (  | 
31  | 
num_files, num_commits)  | 
|
| 
1908.3.14
by Carl Friedrich Bolz
 Refactor the bundle benchmarks to use the existing helper functions.  | 
32  | 
super(ManyCommitTreeCreator, self).__init__(test,  | 
| 
1908.3.15
by Carl Friedrich Bolz
 Fix problems pointed out by John:  | 
33  | 
tree_name=tree_name,  | 
| 
1908.3.14
by Carl Friedrich Bolz
 Refactor the bundle benchmarks to use the existing helper functions.  | 
34  | 
link_bzr=link_bzr,  | 
35  | 
link_working=False,  | 
|
36  | 
hot_cache=True)  | 
|
37  | 
self.files = ["%s" % (i, ) for i in range(num_files)]  | 
|
38  | 
self.num_files = num_files  | 
|
39  | 
self.num_commits = num_commits  | 
|
40  | 
||
41  | 
def _create_tree(self, root, in_cache=False):  | 
|
42  | 
num_files = self.num_files  | 
|
43  | 
num_commits = self.num_commits  | 
|
| 
1908.3.15
by Carl Friedrich Bolz
 Fix problems pointed out by John:  | 
44  | 
files = ["%s/%s" % (root, fn) for fn in self.files]  | 
| 
1908.3.14
by Carl Friedrich Bolz
 Refactor the bundle benchmarks to use the existing helper functions.  | 
45  | 
for fn in files:  | 
46  | 
f = open(fn, "wb")  | 
|
47  | 
try:  | 
|
48  | 
f.write("some content\n")  | 
|
49  | 
finally:  | 
|
50  | 
f.close()  | 
|
51  | 
tree = bzrdir.BzrDir.create_standalone_workingtree(root)  | 
|
| 
1908.3.15
by Carl Friedrich Bolz
 Fix problems pointed out by John:  | 
52  | 
tree.add(self.files)  | 
| 
1908.3.14
by Carl Friedrich Bolz
 Refactor the bundle benchmarks to use the existing helper functions.  | 
53  | 
tree.lock_write()  | 
54  | 
try:  | 
|
55  | 
tree.commit('initial commit')  | 
|
56  | 
for i in range(num_commits):  | 
|
57  | 
fn = files[i % len(files)]  | 
|
58  | 
content = range(i) + [i, i, i, ""]  | 
|
59  | 
f = open(fn, "wb")  | 
|
60  | 
try:  | 
|
61  | 
f.write("\n".join([str(i) for i in content]))  | 
|
62  | 
finally:  | 
|
63  | 
f.close()  | 
|
64  | 
tree.commit("changing file %s" % fn)  | 
|
65  | 
finally:  | 
|
66  | 
tree.unlock()  | 
|
67  | 
return tree  | 
|
68  |