/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/tree_creator/many_commit.py

  • Committer: Carl Friedrich Bolz
  • Date: 2006-08-19 02:17:16 UTC
  • mto: (1908.3.21 usecases-benchmarks)
  • mto: This revision was merged to the branch mainline in revision 2068.
  • Revision ID: cfbolz@gmx.de-20060819021716-4a2cdd443e83721b
Refactor the bundle benchmarks to use the existing helper functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
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):
 
30
        super(ManyCommitTreeCreator, self).__init__(test,
 
31
            tree_name='many_files_many_commit_tree',
 
32
            link_bzr=link_bzr,
 
33
            link_working=False,
 
34
            hot_cache=True)
 
35
        self.files = ["%s" % (i, ) for i in range(num_files)]
 
36
        self.num_files = num_files
 
37
        self.num_commits = num_commits
 
38
 
 
39
    def _create_tree(self, root, in_cache=False):
 
40
        num_files = self.num_files
 
41
        num_commits = self.num_commits
 
42
        files = ["%s/%s" % (root, i) for i in range(num_files)]
 
43
        for fn in files:
 
44
            f = open(fn, "wb")
 
45
            try:
 
46
                f.write("some content\n")
 
47
            finally:
 
48
                f.close()
 
49
        tree = bzrdir.BzrDir.create_standalone_workingtree(root)
 
50
        tree.add([str(i) for i in range(num_files)])
 
51
        tree.lock_write()
 
52
        try:
 
53
            tree.commit('initial commit')
 
54
            for i in range(num_commits):
 
55
                fn = files[i % len(files)]
 
56
                content = range(i) + [i, i, i, ""]
 
57
                f = open(fn, "wb")
 
58
                try:
 
59
                    f.write("\n".join([str(i) for i in content]))
 
60
                finally:
 
61
                    f.close()
 
62
                tree.commit("changing file %s" % fn)
 
63
        finally:
 
64
            tree.unlock()
 
65
        self.files = ["%s" % (i, ) for i in range(num_files)]
 
66
        return tree
 
67