~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge sftp-leaks into catch-them-all

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
"""Tree creator for many commits, but no changes"""
18
 
 
19
 
import errno
20
 
import os
21
 
 
22
 
from bzrlib import (
23
 
    bzrdir,
24
 
    )
25
 
 
26
 
from bzrlib.benchmarks.tree_creator import TreeCreator
27
 
 
28
 
 
29
 
class HeavilyMergedTreeCreator(TreeCreator):
30
 
    """Create a tree in which almost every commit is a merge.
31
 
 
32
 
    No file changes are included.  This produces two trees,
33
 
    one of which is returned.  Except for the first commit, every
34
 
    commit in its revision-history is a merge of another commit in the other
35
 
    tree.
36
 
    Not hardlinking the working tree, because there are no working tree files.
37
 
    """
38
 
 
39
 
    def __init__(self, test, link_bzr=True):
40
 
        super(HeavilyMergedTreeCreator, self).__init__(test,
41
 
            tree_name='heavily_merged_tree',
42
 
            link_bzr=link_bzr,
43
 
            link_working=False,
44
 
            hot_cache=True)
45
 
 
46
 
    def _create_tree(self, root, in_cache=False):
47
 
        try:
48
 
            os.mkdir(root)
49
 
        except (IOError, OSError), e:
50
 
            if e.errno not in (errno.EEXIST,):
51
 
                raise
52
 
 
53
 
        tree = bzrdir.BzrDir.create_standalone_workingtree(root)
54
 
        tree.lock_write()
55
 
        try:
56
 
            tree2 = tree.bzrdir.sprout(root + '/tree2').open_workingtree()
57
 
            tree2.lock_write()
58
 
            try:
59
 
                for i in xrange(250):
60
 
                    revision_id = tree.commit('no-changes commit %d-a' % i)
61
 
                    tree2.branch.fetch(tree.branch, revision_id)
62
 
                    tree2.add_parent_tree_id(revision_id)
63
 
                    revision_id = tree2.commit('no-changes commit %d-b' % i)
64
 
                    tree.branch.fetch(tree2.branch, revision_id)
65
 
                    tree.add_parent_tree_id(revision_id)
66
 
                tree.set_parent_ids(tree.get_parent_ids()[:1])
67
 
            finally:
68
 
                tree2.unlock()
69
 
        finally:
70
 
            tree.unlock()
71
 
        if in_cache:
72
 
            self._protect_files(root+'/.bzr')
73
 
        return tree
74
 
 
75