/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/tests/test_info.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2012 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import sys
 
18
from urllib import quote
18
19
 
19
 
from .. import (
 
20
from bzrlib import (
20
21
    branch as _mod_branch,
21
 
    controldir,
22
 
    errors,
 
22
    bzrdir,
23
23
    info,
24
24
    tests,
25
25
    workingtree,
26
26
    repository as _mod_repository,
27
27
    )
28
 
from ..bzr import (
29
 
    branch as _mod_bzrbranch,
30
 
    )
31
28
 
32
29
 
33
30
class TestInfo(tests.TestCaseWithTransport):
35
32
    def test_describe_standalone_layout(self):
36
33
        tree = self.make_branch_and_tree('tree')
37
34
        self.assertEqual('Empty control directory', info.describe_layout())
38
 
        self.assertEqual(
39
 
            'Unshared repository with trees and colocated branches',
40
 
            info.describe_layout(tree.branch.repository, control=tree.controldir))
 
35
        self.assertEqual('Unshared repository with trees',
 
36
            info.describe_layout(tree.branch.repository))
41
37
        tree.branch.repository.set_make_working_trees(False)
42
 
        self.assertEqual('Unshared repository with colocated branches',
43
 
                         info.describe_layout(tree.branch.repository, control=tree.controldir))
 
38
        self.assertEqual('Unshared repository',
 
39
            info.describe_layout(tree.branch.repository))
44
40
        self.assertEqual('Standalone branch',
45
 
                         info.describe_layout(tree.branch.repository, tree.branch,
46
 
                                              control=tree.controldir))
 
41
            info.describe_layout(tree.branch.repository, tree.branch))
47
42
        self.assertEqual('Standalone branchless tree',
48
 
                         info.describe_layout(tree.branch.repository, None, tree,
49
 
                                              control=tree.controldir))
 
43
            info.describe_layout(tree.branch.repository, None, tree))
50
44
        self.assertEqual('Standalone tree',
51
 
                         info.describe_layout(tree.branch.repository, tree.branch, tree,
52
 
                                              control=tree.controldir))
 
45
            info.describe_layout(tree.branch.repository, tree.branch, tree))
53
46
        tree.branch.bind(tree.branch)
54
47
        self.assertEqual('Bound branch',
55
 
                         info.describe_layout(tree.branch.repository, tree.branch,
56
 
                                              control=tree.controldir))
 
48
            info.describe_layout(tree.branch.repository, tree.branch))
57
49
        self.assertEqual('Checkout',
58
 
                         info.describe_layout(tree.branch.repository, tree.branch, tree,
59
 
                                              control=tree.controldir))
 
50
            info.describe_layout(tree.branch.repository, tree.branch, tree))
60
51
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
61
52
        self.assertEqual('Lightweight checkout',
62
 
                         info.describe_layout(checkout.branch.repository, checkout.branch,
63
 
                                              checkout, control=tree.controldir))
 
53
            info.describe_layout(checkout.branch.repository, checkout.branch,
 
54
                                 checkout))
64
55
 
65
56
    def test_describe_repository_layout(self):
66
57
        repository = self.make_repository('.', shared=True)
67
 
        tree = controldir.ControlDir.create_branch_convenience('tree',
68
 
                                                               force_new_tree=True).controldir.open_workingtree()
69
 
        self.assertEqual('Shared repository with trees and colocated branches',
70
 
                         info.describe_layout(tree.branch.repository, control=tree.controldir))
 
58
        tree = bzrdir.BzrDir.create_branch_convenience('tree',
 
59
            force_new_tree=True).bzrdir.open_workingtree()
 
60
        self.assertEqual('Shared repository with trees',
 
61
            info.describe_layout(tree.branch.repository))
71
62
        repository.set_make_working_trees(False)
72
 
        self.assertEqual('Shared repository with colocated branches',
73
 
                         info.describe_layout(tree.branch.repository, control=tree.controldir))
 
63
        self.assertEqual('Shared repository',
 
64
            info.describe_layout(tree.branch.repository))
74
65
        self.assertEqual('Repository branch',
75
 
                         info.describe_layout(tree.branch.repository, tree.branch,
76
 
                                              control=tree.controldir))
 
66
            info.describe_layout(tree.branch.repository, tree.branch))
77
67
        self.assertEqual('Repository branchless tree',
78
 
                         info.describe_layout(tree.branch.repository, None, tree,
79
 
                                              control=tree.controldir))
 
68
            info.describe_layout(tree.branch.repository, None, tree))
80
69
        self.assertEqual('Repository tree',
81
 
                         info.describe_layout(tree.branch.repository, tree.branch, tree,
82
 
                                              control=tree.controldir))
 
70
            info.describe_layout(tree.branch.repository, tree.branch, tree))
83
71
        tree.branch.bind(tree.branch)
84
72
        self.assertEqual('Repository checkout',
85
 
                         info.describe_layout(tree.branch.repository, tree.branch, tree,
86
 
                                              control=tree.controldir))
 
73
            info.describe_layout(tree.branch.repository, tree.branch, tree))
87
74
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
88
75
        self.assertEqual('Lightweight checkout',
89
 
                         info.describe_layout(checkout.branch.repository, checkout.branch,
90
 
                                              checkout, control=tree.controldir))
 
76
            info.describe_layout(checkout.branch.repository, checkout.branch,
 
77
                                 checkout))
91
78
 
92
79
    def assertTreeDescription(self, format):
93
80
        """Assert a tree's format description matches expectations"""
94
81
        self.make_branch_and_tree('%s_tree' % format, format=format)
95
82
        tree = workingtree.WorkingTree.open('%s_tree' % format)
96
 
        self.assertEqual(format, info.describe_format(tree.controldir,
97
 
                                                      tree.branch.repository, tree.branch, tree))
 
83
        self.assertEqual(format, info.describe_format(tree.bzrdir,
 
84
            tree.branch.repository, tree.branch, tree))
98
85
 
99
86
    def assertCheckoutDescription(self, format, expected=None):
100
87
        """Assert a checkout's format description matches expectations"""
103
90
        branch = self.make_branch('%s_cobranch' % format, format=format)
104
91
        # this ought to be easier...
105
92
        branch.create_checkout('%s_co' % format,
106
 
                               lightweight=True).controldir.destroy_workingtree()
107
 
        control = controldir.ControlDir.open('%s_co' % format)
 
93
            lightweight=True).bzrdir.destroy_workingtree()
 
94
        control = bzrdir.BzrDir.open('%s_co' % format)
108
95
        old_format = control._format.workingtree_format
109
96
        try:
110
97
            control._format.workingtree_format = \
111
 
                controldir.format_registry.make_controldir(
112
 
                    format).workingtree_format
 
98
                bzrdir.format_registry.make_bzrdir(format).workingtree_format
113
99
            control.create_workingtree()
114
100
            tree = workingtree.WorkingTree.open('%s_co' % format)
115
 
            format_description = info.describe_format(tree.controldir,
116
 
                                                      tree.branch.repository, tree.branch, tree)
 
101
            format_description = info.describe_format(tree.bzrdir,
 
102
                    tree.branch.repository, tree.branch, tree)
117
103
            self.assertEqual(expected, format_description,
118
 
                             "checkout of format called %r was described as %r" %
119
 
                             (expected, format_description))
 
104
                "checkout of format called %r was described as %r" %
 
105
                (expected, format_description))
120
106
        finally:
121
107
            control._format.workingtree_format = old_format
122
108
 
126
112
            expected = format
127
113
        self.make_branch('%s_branch' % format, format=format)
128
114
        branch = _mod_branch.Branch.open('%s_branch' % format)
129
 
        self.assertEqual(expected, info.describe_format(branch.controldir,
130
 
                                                        branch.repository, branch, None))
 
115
        self.assertEqual(expected, info.describe_format(branch.bzrdir,
 
116
            branch.repository, branch, None))
131
117
 
132
118
    def assertRepoDescription(self, format, expected=None):
133
119
        """Assert repository's format description matches expectations"""
135
121
            expected = format
136
122
        self.make_repository('%s_repo' % format, format=format)
137
123
        repo = _mod_repository.Repository.open('%s_repo' % format)
138
 
        self.assertEqual(expected, info.describe_format(repo.controldir,
139
 
                                                        repo, None, None))
 
124
        self.assertEqual(expected, info.describe_format(repo.bzrdir,
 
125
            repo, None, None))
140
126
 
141
127
    def test_describe_tree_format(self):
142
 
        for key, format in controldir.format_registry.iteritems():
143
 
            if key in controldir.format_registry.aliases():
144
 
                continue
145
 
            if not format().supports_workingtrees:
 
128
        for key in bzrdir.format_registry.keys():
 
129
            if key in bzrdir.format_registry.aliases():
146
130
                continue
147
131
            self.assertTreeDescription(key)
148
132
 
149
133
    def test_describe_checkout_format(self):
150
 
        for key in controldir.format_registry.keys():
151
 
            if key in controldir.format_registry.aliases():
 
134
        for key in bzrdir.format_registry.keys():
 
135
            if key in bzrdir.format_registry.aliases():
152
136
                # Aliases will not describe correctly in the UI because the
153
137
                # real format is found.
154
138
                continue
155
139
            # legacy: weave does not support checkouts
156
140
            if key == 'weave':
157
141
                continue
158
 
            # foreign: git checkouts can actually be bzr controldirs
159
 
            if key in ('git', 'git-bare'):
160
 
                continue
161
 
            if controldir.format_registry.get_info(key).experimental:
 
142
            if bzrdir.format_registry.get_info(key).experimental:
162
143
                # We don't require that experimental formats support checkouts
163
144
                # or describe correctly in the UI.
164
145
                continue
165
 
            if controldir.format_registry.get_info(key).hidden:
 
146
            if bzrdir.format_registry.get_info(key).hidden:
166
147
                continue
167
148
            expected = None
168
149
            if key in ('pack-0.92',):
169
150
                expected = 'pack-0.92'
170
151
            elif key in ('knit', 'metaweave'):
171
 
                if 'metaweave' in controldir.format_registry:
172
 
                    expected = 'knit or metaweave'
173
 
                else:
174
 
                    expected = 'knit'
 
152
                expected = 'knit or metaweave'
175
153
            elif key in ('1.14', '1.14-rich-root'):
176
154
                expected = '1.14 or 1.14-rich-root'
177
155
            self.assertCheckoutDescription(key, expected)
178
156
 
179
157
    def test_describe_branch_format(self):
180
 
        for key in controldir.format_registry.keys():
181
 
            if key in controldir.format_registry.aliases():
 
158
        for key in bzrdir.format_registry.keys():
 
159
            if key in bzrdir.format_registry.aliases():
182
160
                continue
183
 
            if controldir.format_registry.get_info(key).hidden:
 
161
            if bzrdir.format_registry.get_info(key).hidden:
184
162
                continue
185
163
            expected = None
186
164
            if key in ('dirstate', 'knit'):
192
170
            self.assertBranchDescription(key, expected)
193
171
 
194
172
    def test_describe_repo_format(self):
195
 
        for key in controldir.format_registry.keys():
196
 
            if key in controldir.format_registry.aliases():
 
173
        for key in bzrdir.format_registry.keys():
 
174
            if key in bzrdir.format_registry.aliases():
197
175
                continue
198
 
            if controldir.format_registry.get_info(key).hidden:
 
176
            if bzrdir.format_registry.get_info(key).hidden:
199
177
                continue
200
178
            expected = None
201
179
            if key in ('dirstate', 'knit', 'dirstate-tags'):
206
184
                expected = '1.14-rich-root'
207
185
            self.assertRepoDescription(key, expected)
208
186
 
209
 
        format = controldir.format_registry.make_controldir('knit')
210
 
        format.set_branch_format(_mod_bzrbranch.BzrBranchFormat6())
 
187
        format = bzrdir.format_registry.make_bzrdir('metaweave')
 
188
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
211
189
        tree = self.make_branch_and_tree('unknown', format=format)
212
 
        self.assertEqual('unnamed', info.describe_format(tree.controldir,
213
 
                                                         tree.branch.repository, tree.branch, tree))
214
 
 
215
 
    def test_gather_location_controldir_only(self):
216
 
        bzrdir = self.make_controldir('.')
217
 
        self.assertEqual([('control directory', bzrdir.user_url)],
218
 
                         info.gather_location_info(control=bzrdir))
 
190
        self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
 
191
            tree.branch.repository, tree.branch, tree))
219
192
 
220
193
    def test_gather_location_standalone(self):
221
194
        tree = self.make_branch_and_tree('tree')
222
 
        self.assertEqual([('branch root', tree.controldir.root_transport.base)],
223
 
                         info.gather_location_info(
224
 
            tree.branch.repository, tree.branch, tree, control=tree.controldir))
225
 
        self.assertEqual([('branch root', tree.controldir.root_transport.base)],
226
 
                         info.gather_location_info(
227
 
            tree.branch.repository, tree.branch, control=tree.controldir))
 
195
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
 
196
            info.gather_location_info(tree.branch.repository, tree.branch,
 
197
                                      tree))
 
198
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
 
199
            info.gather_location_info(tree.branch.repository, tree.branch))
228
200
        return tree
229
201
 
230
202
    def test_gather_location_repo(self):
231
203
        srepo = self.make_repository('shared', shared=True)
232
 
        self.assertEqual(
233
 
            [('shared repository', srepo.controldir.root_transport.base)],
234
 
            info.gather_location_info(srepo, control=srepo.controldir))
 
204
        self.assertEqual([('shared repository',
 
205
                          srepo.bzrdir.root_transport.base)],
 
206
                          info.gather_location_info(srepo))
235
207
        urepo = self.make_repository('unshared')
236
 
        self.assertEqual(
237
 
            [('repository', urepo.controldir.root_transport.base)],
238
 
            info.gather_location_info(urepo, control=urepo.controldir))
 
208
        self.assertEqual([('repository',
 
209
                          urepo.bzrdir.root_transport.base)],
 
210
                          info.gather_location_info(urepo))
239
211
 
240
212
    def test_gather_location_repo_branch(self):
241
213
        srepo = self.make_repository('shared', shared=True)
242
 
        self.assertEqual(
243
 
            [('shared repository', srepo.controldir.root_transport.base)],
244
 
            info.gather_location_info(srepo, control=srepo.controldir))
 
214
        self.assertEqual([('shared repository',
 
215
                          srepo.bzrdir.root_transport.base)],
 
216
                          info.gather_location_info(srepo))
245
217
        tree = self.make_branch_and_tree('shared/tree')
246
 
        self.assertEqual(
247
 
            [('shared repository', srepo.controldir.root_transport.base),
248
 
             ('repository branch', tree.branch.base)],
249
 
            info.gather_location_info(srepo, tree.branch, tree, srepo.controldir))
 
218
        self.assertEqual([('shared repository',
 
219
                          srepo.bzrdir.root_transport.base),
 
220
                          ('repository branch', tree.branch.base)],
 
221
                          info.gather_location_info(srepo, tree.branch, tree))
250
222
 
251
223
    def test_gather_location_light_checkout(self):
252
224
        tree = self.make_branch_and_tree('tree')
253
225
        lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
254
226
        self.assertEqual(
255
 
            [('light checkout root', lcheckout.controldir.root_transport.base),
256
 
             ('checkout of branch', tree.controldir.root_transport.base)],
 
227
            [('light checkout root', lcheckout.bzrdir.root_transport.base),
 
228
             ('checkout of branch', tree.bzrdir.root_transport.base)],
257
229
            self.gather_tree_location_info(lcheckout))
258
230
 
259
231
    def test_gather_location_heavy_checkout(self):
260
232
        tree = self.make_branch_and_tree('tree')
261
233
        checkout = tree.branch.create_checkout('checkout')
262
234
        self.assertEqual(
263
 
            [('checkout root', checkout.controldir.root_transport.base),
264
 
             ('checkout of branch', tree.controldir.root_transport.base)],
 
235
            [('checkout root', checkout.bzrdir.root_transport.base),
 
236
             ('checkout of branch', tree.bzrdir.root_transport.base)],
265
237
            self.gather_tree_location_info(checkout))
266
238
        light_checkout = checkout.branch.create_checkout('light_checkout',
267
239
                                                         lightweight=True)
268
240
        self.assertEqual(
269
241
            [('light checkout root',
270
 
              light_checkout.controldir.root_transport.base),
271
 
             ('checkout root', checkout.controldir.root_transport.base),
272
 
             ('checkout of branch', tree.controldir.root_transport.base)],
273
 
            self.gather_tree_location_info(light_checkout)
274
 
            )
 
242
              light_checkout.bzrdir.root_transport.base),
 
243
             ('checkout root', checkout.bzrdir.root_transport.base),
 
244
             ('checkout of branch', tree.bzrdir.root_transport.base)],
 
245
             self.gather_tree_location_info(light_checkout)
 
246
             )
275
247
 
276
248
    def test_gather_location_shared_repo_checkout(self):
277
249
        tree = self.make_branch_and_tree('tree')
279
251
        shared_checkout = tree.branch.create_checkout('shared/checkout')
280
252
        self.assertEqual(
281
253
            [('repository checkout root',
282
 
              shared_checkout.controldir.root_transport.base),
283
 
             ('checkout of branch', tree.controldir.root_transport.base),
284
 
             ('shared repository', srepo.controldir.root_transport.base)],
285
 
            self.gather_tree_location_info(shared_checkout))
 
254
              shared_checkout.bzrdir.root_transport.base),
 
255
             ('checkout of branch', tree.bzrdir.root_transport.base),
 
256
             ('shared repository', srepo.bzrdir.root_transport.base)],
 
257
             self.gather_tree_location_info(shared_checkout))
286
258
 
287
259
    def gather_tree_location_info(self, tree):
288
 
        return info.gather_location_info(
289
 
            tree.branch.repository, tree.branch, tree, tree.controldir)
 
260
        return info.gather_location_info(tree.branch.repository, tree.branch,
 
261
                                         tree)
290
262
 
291
263
    def test_gather_location_bound(self):
292
264
        branch = self.make_branch('branch')
293
265
        bound_branch = self.make_branch('bound_branch')
294
266
        bound_branch.bind(branch)
295
267
        self.assertEqual(
296
 
            [('branch root', bound_branch.controldir.root_transport.base),
297
 
             ('bound to branch', branch.controldir.root_transport.base)],
298
 
            info.gather_location_info(
299
 
                bound_branch.repository, bound_branch, control=bound_branch.controldir)
300
 
        )
301
 
 
302
 
    def test_gather_location_bound_in_repository(self):
303
 
        repo = self.make_repository('repo', shared=True)
304
 
        repo.set_make_working_trees(False)
305
 
        branch = self.make_branch('branch')
306
 
        bound_branch = controldir.ControlDir.create_branch_convenience(
307
 
            'repo/bound_branch')
308
 
        bound_branch.bind(branch)
309
 
        self.assertEqual(
310
 
            [('shared repository', bound_branch.repository.controldir.user_url),
311
 
             ('repository branch', bound_branch.controldir.user_url),
312
 
             ('bound to branch', branch.controldir.user_url)],
 
268
            [('branch root', bound_branch.bzrdir.root_transport.base),
 
269
             ('bound to branch', branch.bzrdir.root_transport.base)],
313
270
            info.gather_location_info(bound_branch.repository, bound_branch)
314
271
        )
315
272
 
332
289
 
333
290
    def test_gather_related_braches(self):
334
291
        branch = self.make_branch('.')
335
 
        branch.lock_write()
336
 
        try:
337
 
            branch.set_public_branch('baz')
338
 
            branch.set_push_location('bar')
339
 
            branch.set_parent('foo')
340
 
            branch.set_submit_branch('qux')
341
 
        finally:
342
 
            branch.unlock()
 
292
        branch.set_public_branch('baz')
 
293
        branch.set_push_location('bar')
 
294
        branch.set_parent('foo')
 
295
        branch.set_submit_branch('qux')
343
296
        self.assertEqual(
344
297
            [('public branch', 'baz'), ('push branch', 'bar'),
345
298
             ('parent branch', 'foo'), ('submit branch', 'qux')],