/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/bench_bundle.py

  • Committer: holger krekel
  • Date: 2006-08-11 17:25:00 UTC
  • mto: (1908.3.5 bench_usecases)
  • mto: This revision was merged to the branch mainline in revision 2068.
  • Revision ID: hpk@merlinux.de-20060811172500-fe5c683e2d0aa01a
route more creation code through cached_make
and refactor so that apply bundle works from an 
empty tree. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib.bundle import read_bundle
28
28
from bzrlib.revisionspec import RevisionSpec
29
29
 
30
 
# If the CACHEDIR flag is set, make_parametrized_tree below will cache the tree
31
 
# it creates in the .bazaar/temp dir.
32
 
CACHEDIR = os.path.expanduser("~/.bazaar/temp")
 
30
# if set, creation of test trees will be globally cached 
 
31
CACHEDIR = os.path.expanduser("~/.bazaar/devtemp")
 
32
#CACHEDIR = None 
33
33
 
 
34
def cached_make(maker, *args):
 
35
    if CACHEDIR is None:
 
36
        return maker(*args)
 
37
    olddir = os.getcwd()
 
38
    try:
 
39
        if not os.path.exists(CACHEDIR):
 
40
            os.makedirs(CACHEDIR)
 
41
        os.chdir(CACHEDIR)
 
42
        cache_name = "_".join([maker.__name__] + [str(x) for x in args])
 
43
        if not os.path.exists(cache_name):
 
44
            os.mkdir(cache_name)
 
45
            os.chdir(cache_name)
 
46
            try:
 
47
                maker(*args)
 
48
            except:
 
49
                os.chdir(CACHEDIR)
 
50
                shutil.rmtree(cache_name)
 
51
                raise
 
52
            os.chdir(CACHEDIR)
 
53
                
 
54
        for subdir in os.listdir(cache_name):
 
55
            shutil.copytree(os.path.join(cache_name, subdir),
 
56
                            os.path.join(olddir, subdir))
 
57
    finally:
 
58
        os.chdir(olddir)
34
59
 
35
60
class BundleBenchmark(Benchmark):
36
61
    """
37
62
    The bundle tests should (also) be done at a lower level with
38
63
    direct call to the bzrlib."""
39
 
    
 
64
   
 
65
    def make_kernel_like_tree_committed(self): 
 
66
        cached_make(self.make_kernel_like_tree)
 
67
        self.run_bzr('add')
 
68
        self.run_bzr('commit', '-m', 'initial import')
40
69
 
41
70
    def test_create_bundle_known_kernel_like_tree(self):
42
71
        """
43
72
        Create a bundle for a kernel sized tree with no ignored, unknowns,
44
73
        or added and one commit.""" 
45
 
        self.make_kernel_like_tree()
46
 
        self.run_bzr('add')
47
 
        self.run_bzr('commit', '-m', 'initial import')
 
74
        cached_make(self.make_kernel_like_tree_committed)
48
75
        self.time(self.run_bzr, 'bundle', '--revision', '..-1')
49
76
 
50
77
    def test_create_bundle_many_commit_tree (self):
51
78
        """
52
79
        Create a bundle for a tree with many commits but no changes.""" 
53
 
        self.make_many_commit_tree()
 
80
        cached_make(self.make_many_commit_tree)
54
81
        self.time(self.run_bzr, 'bundle', '--revision', '..-1')
55
82
 
56
83
    def test_create_bundle_heavily_merged_tree(self):
57
84
        """
58
85
        Create a bundle for a heavily merged tree.""" 
59
 
        self.make_heavily_merged_tree()
 
86
        cached_make(self.make_heavily_merged_tree)
60
87
        self.time(self.run_bzr, 'bundle', '--revision', '..-1')
61
88
        
62
89
    def test_apply_bundle_known_kernel_like_tree(self):
63
90
        """
64
91
        Create a bundle for a kernel sized tree with no ignored, unknowns,
65
92
        or added and one commit.""" 
66
 
        self.make_kernel_like_tree()
67
 
        self.run_bzr('add')
68
 
        self.run_bzr('commit', '-m', 'initial import')
69
 
        self.run_bzr('branch', '.', '../branch_a')
70
 
        self.run_bzr('bundle', '--revision', '..-1')
 
93
        cached_make(self.make_kernel_like_tree_committed)
71
94
        f = file('../bundle', 'wb')
72
95
        try:
73
96
            f.write(self.run_bzr('bundle', '--revision', '..-1')[0])
74
97
        finally:
75
98
            f.close()
 
99
        self.run_bzr("init", "../branch_a")
76
100
        os.chdir('../branch_a')
77
101
        self.time(self.run_bzr, 'merge', '../bundle')
78
102
 
91
115
        :param num_revisions: number of revisions
92
116
        :param num_files_in_bundle: number of files changed in the revisions
93
117
        """
94
 
        if CACHEDIR is None:
95
 
            return self._make_parametrized_tree(num_files, num_revisions,
96
 
                                                num_files_in_bundle)
97
 
        olddir = os.getcwd()
98
 
        try:
99
 
            if not os.path.exists(CACHEDIR):
100
 
                os.makedirs(CACHEDIR)
101
 
            os.chdir(CACHEDIR)
102
 
            cache_name = "make_parametrized_tree_%s_%s_%s" % (
103
 
                num_files, num_revisions, num_files_in_bundle)
104
 
            if not os.path.exists(cache_name):
105
 
                os.mkdir(cache_name)
106
 
                os.chdir(cache_name)
107
 
                self._make_parametrized_tree(num_files, num_revisions,
108
 
                                             num_files_in_bundle)
109
 
                os.chdir(CACHEDIR)
110
 
            for subdir in os.listdir(cache_name):
111
 
                shutil.copytree(os.path.join(cache_name, subdir),
112
 
                                os.path.join(olddir, subdir))
113
 
        finally:
114
 
            os.chdir(olddir)
115
 
 
116
 
    def _make_parametrized_tree(self, num_files, num_revisions,
117
 
                                num_files_in_bundle):
118
 
        # create files
119
118
        directories = []
120
119
        files = []
121
120
        count = 0
156
155
            for num_revisions in [1, 500, 1000]:
157
156
                code = """
158
157
def test_%s_files_%s_tree_%s_revision(self):
159
 
    self.make_parametrized_tree(%s, %s, %s)
 
158
    cached_make(self.make_parametrized_tree, %s, %s, %s)
160
159
    branch, _ = Branch.open_containing(".")
161
160
    revision_history = branch.revision_history()
162
161
    bundle_text = StringIO()