~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_upgrade.py

  • Committer: Vincent Ladeuil
  • Date: 2011-08-20 09:28:27 UTC
  • mfrom: (5050.78.2 2.2)
  • mto: (5609.48.8 2.3)
  • mto: This revision was merged to the branch mainline in revision 6090.
  • Revision ID: v.ladeuil+lp@free.fr-20110820092827-9dyakfslp0r3hb1k
Merge 2.2 into 2.3 (including fix for #614713, #609187 and #812928)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
22
22
# TODO queue for upgrade:
23
23
# test the error message when upgrading an unknown BzrDir format.
24
24
 
25
 
import base64
26
 
import os
27
 
import sys
28
 
 
29
25
from bzrlib import (
30
 
    branch as _mod_branch,
 
26
    branch,
31
27
    bzrdir,
32
 
    progress,
33
28
    repository,
 
29
    tests,
 
30
    upgrade,
34
31
    workingtree,
35
32
    workingtree_4,
36
33
    )
37
 
import bzrlib.branch
38
 
from bzrlib.branch import Branch
39
 
from bzrlib.tests import TestCaseWithTransport
40
 
from bzrlib.transport import get_transport
41
 
from bzrlib.upgrade import upgrade
42
 
 
43
 
 
44
 
class TestUpgrade(TestCaseWithTransport):
45
 
 
46
 
    def test_build_tree(self):
47
 
        """Test tree-building test helper"""
48
 
        self.build_tree_contents(_upgrade1_template)
49
 
        self.failUnlessExists('foo')
50
 
        self.failUnlessExists('.bzr/README')
 
34
 
 
35
 
 
36
class TestUpgrade(tests.TestCaseWithTransport):
51
37
 
52
38
    def test_upgrade_simple(self):
53
39
        """Upgrade simple v0.0.4 format to latest format"""
54
40
        eq = self.assertEquals
55
41
        self.build_tree_contents(_upgrade1_template)
56
 
        upgrade(u'.')
 
42
        upgrade.upgrade(u'.')
57
43
        control = bzrdir.BzrDir.open('.')
58
44
        b = control.open_branch()
59
45
        # tsk, peeking under the covers.
60
 
        self.failUnless(
61
 
            isinstance(
 
46
        self.assertIsInstance(
62
47
                control._format,
63
 
                bzrdir.BzrDirFormat.get_default_format().__class__))
 
48
                bzrdir.BzrDirFormat.get_default_format().__class__)
64
49
        rh = b.revision_history()
65
50
        eq(rh,
66
51
           ['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
79
64
        finally:
80
65
            rt.unlock()
81
66
        # check a backup was made:
82
 
        transport = get_transport(b.base)
83
 
        transport.stat('backup.bzr')
84
 
        transport.stat('backup.bzr/README')
85
 
        transport.stat('backup.bzr/branch-format')
86
 
        transport.stat('backup.bzr/revision-history')
87
 
        transport.stat('backup.bzr/merged-patches')
88
 
        transport.stat('backup.bzr/pending-merged-patches')
89
 
        transport.stat('backup.bzr/pending-merges')
90
 
        transport.stat('backup.bzr/branch-name')
91
 
        transport.stat('backup.bzr/branch-lock')
92
 
        transport.stat('backup.bzr/inventory')
93
 
        transport.stat('backup.bzr/stat-cache')
94
 
        transport.stat('backup.bzr/text-store')
95
 
        transport.stat('backup.bzr/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
96
 
        transport.stat('backup.bzr/text-store/foo-20051004035756-4081373d897c3453.gz')
97
 
        transport.stat('backup.bzr/inventory-store/')
98
 
        transport.stat('backup.bzr/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
99
 
        transport.stat('backup.bzr/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
100
 
        transport.stat('backup.bzr/revision-store/')
101
 
        transport.stat('backup.bzr/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
102
 
        transport.stat('backup.bzr/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
 
67
        backup_dir = 'backup.bzr.~1~'
 
68
        t = self.get_transport('.')
 
69
        t.stat(backup_dir)
 
70
        t.stat(backup_dir + '/README')
 
71
        t.stat(backup_dir + '/branch-format')
 
72
        t.stat(backup_dir + '/revision-history')
 
73
        t.stat(backup_dir + '/merged-patches')
 
74
        t.stat(backup_dir + '/pending-merged-patches')
 
75
        t.stat(backup_dir + '/pending-merges')
 
76
        t.stat(backup_dir + '/branch-name')
 
77
        t.stat(backup_dir + '/branch-lock')
 
78
        t.stat(backup_dir + '/inventory')
 
79
        t.stat(backup_dir + '/stat-cache')
 
80
        t.stat(backup_dir + '/text-store')
 
81
        t.stat(backup_dir + '/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
 
82
        t.stat(backup_dir + '/text-store/foo-20051004035756-4081373d897c3453.gz')
 
83
        t.stat(backup_dir + '/inventory-store/')
 
84
        t.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
 
85
        t.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
 
86
        t.stat(backup_dir + '/revision-store/')
 
87
        t.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
 
88
        t.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
103
89
 
104
90
    def test_upgrade_with_ghosts(self):
105
91
        """Upgrade v0.0.4 tree containing ghost references.
113
99
        its contents."""
114
100
        eq = self.assertEquals
115
101
        self.build_tree_contents(_ghost_template)
116
 
        upgrade(u'.')
117
 
        b = Branch.open(u'.')
 
102
        upgrade.upgrade(u'.')
 
103
        b = branch.Branch.open(u'.')
118
104
        revision_id = b.revision_history()[1]
119
105
        rev = b.repository.get_revision(revision_id)
120
106
        eq(len(rev.parent_ids), 2)
122
108
 
123
109
    def test_upgrade_makes_dir_weaves(self):
124
110
        self.build_tree_contents(_upgrade_dir_template)
125
 
        old_repodir = bzrlib.bzrdir.BzrDir.open_unsupported('.')
 
111
        old_repodir = bzrdir.BzrDir.open_unsupported('.')
126
112
        old_repo_format = old_repodir.open_repository()._format
127
 
        upgrade('.')
 
113
        upgrade.upgrade('.')
128
114
        # this is the path to the literal file. As format changes
129
115
        # occur it needs to be updated. FIXME: ask the store for the
130
116
        # path.
131
 
        repo = bzrlib.repository.Repository.open('.')
 
117
        repo = repository.Repository.open('.')
132
118
        # it should have changed the format
133
119
        self.assertNotEqual(old_repo_format.__class__, repo._format.__class__)
134
120
        # and we should be able to read the names for the file id
142
128
 
143
129
    def test_upgrade_to_meta_sets_workingtree_last_revision(self):
144
130
        self.build_tree_contents(_upgrade_dir_template)
145
 
        upgrade('.', bzrdir.BzrDirMetaFormat1())
 
131
        upgrade.upgrade('.', bzrdir.BzrDirMetaFormat1())
146
132
        tree = workingtree.WorkingTree.open('.')
147
133
        self.assertEqual([tree.branch.revision_history()[-1]],
148
134
            tree.get_parent_ids())
151
137
        # Some format6 branches do not have checkout files. Upgrading
152
138
        # such a branch to metadir must not setup a working tree.
153
139
        self.build_tree_contents(_upgrade1_template)
154
 
        upgrade('.', bzrdir.BzrDirFormat6())
155
 
        transport = get_transport('.')
156
 
        transport.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
157
 
        self.assertFalse(transport.has('.bzr/stat-cache'))
 
140
        upgrade.upgrade('.', bzrdir.BzrDirFormat6())
 
141
        t = self.get_transport('.')
 
142
        t.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
 
143
        self.assertFalse(t.has('.bzr/stat-cache'))
158
144
        # XXX: upgrade fails if a backup.bzr is already present
159
145
        # -- David Allouche 2006-08-11
160
 
        transport.delete_tree('backup.bzr')
 
146
        t.delete_tree('backup.bzr.~1~')
161
147
        # At this point, we have a format6 branch without checkout files.
162
 
        upgrade('.', bzrdir.BzrDirMetaFormat1())
 
148
        upgrade.upgrade('.', bzrdir.BzrDirMetaFormat1())
163
149
        # The upgrade should not have set up a working tree.
164
150
        control = bzrdir.BzrDir.open('.')
165
151
        self.assertFalse(control.has_workingtree())
166
152
        # We have covered the scope of this test, we may as well check that
167
153
        # upgrade has not eaten our data, even if it's a bit redundant with
168
154
        # other tests.
169
 
        self.failUnless(isinstance(control._format, bzrdir.BzrDirMetaFormat1))
170
 
        branch = control.open_branch()
171
 
        self.assertEquals(branch.revision_history(),
 
155
        self.assertIsInstance(control._format, bzrdir.BzrDirMetaFormat1)
 
156
        b = control.open_branch()
 
157
        self.assertEquals(b.revision_history(),
172
158
           ['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
173
159
            'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
174
160
 
175
161
    def test_upgrade_rich_root(self):
176
162
        tree = self.make_branch_and_tree('tree', format='rich-root')
177
163
        rev_id = tree.commit('first post')
178
 
        upgrade('tree')
 
164
        upgrade.upgrade('tree')
179
165
 
180
166
    def test_convert_branch5_branch6(self):
181
 
        branch = self.make_branch('branch', format='knit')
182
 
        branch.set_revision_history(['AB', 'CD'])
183
 
        branch.set_parent('file:///EF')
184
 
        branch.set_bound_location('file:///GH')
185
 
        branch.set_push_location('file:///IJ')
 
167
        b = self.make_branch('branch', format='knit')
 
168
        b.set_revision_history(['AB', 'CD'])
 
169
        b.set_parent('file:///EF')
 
170
        b.set_bound_location('file:///GH')
 
171
        b.set_push_location('file:///IJ')
186
172
        target = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
187
 
        converter = branch.bzrdir._format.get_converter(target)
188
 
        converter.convert(branch.bzrdir, progress.DummyProgress())
189
 
        new_branch = _mod_branch.Branch.open(self.get_url('branch'))
190
 
        self.assertIs(new_branch.__class__, _mod_branch.BzrBranch6)
 
173
        converter = b.bzrdir._format.get_converter(target)
 
174
        converter.convert(b.bzrdir, None)
 
175
        new_branch = branch.Branch.open(self.get_url('branch'))
 
176
        self.assertIs(new_branch.__class__, branch.BzrBranch6)
191
177
        self.assertEqual('CD', new_branch.last_revision())
192
178
        self.assertEqual('file:///EF', new_branch.get_parent())
193
179
        self.assertEqual('file:///GH', new_branch.get_bound_location())
195
181
        self.assertEqual('file:///IJ',
196
182
            branch_config.get_user_option('push_location'))
197
183
 
198
 
        branch2 = self.make_branch('branch2', format='knit')
199
 
        converter = branch2.bzrdir._format.get_converter(target)
200
 
        converter.convert(branch2.bzrdir, progress.DummyProgress())
201
 
        branch2 = _mod_branch.Branch.open(self.get_url('branch'))
202
 
        self.assertIs(branch2.__class__, _mod_branch.BzrBranch6)
 
184
        b2 = self.make_branch('branch2', format='knit')
 
185
        converter = b2.bzrdir._format.get_converter(target)
 
186
        converter.convert(b2.bzrdir, None)
 
187
        b2 = branch.Branch.open(self.get_url('branch'))
 
188
        self.assertIs(b2.__class__, branch.BzrBranch6)
203
189
 
204
190
    def test_convert_branch7_branch8(self):
205
 
        branch = self.make_branch('branch', format='1.9')
 
191
        b = self.make_branch('branch', format='1.9')
206
192
        target = bzrdir.format_registry.make_bzrdir('1.9')
207
 
        target.set_branch_format(_mod_branch.BzrBranchFormat8())
208
 
        converter = branch.bzrdir._format.get_converter(target)
209
 
        converter.convert(branch.bzrdir, progress.DummyProgress())
210
 
        branch = _mod_branch.Branch.open(self.get_url('branch'))
211
 
        self.assertIs(branch.__class__, _mod_branch.BzrBranch8)
212
 
        self.assertEqual({}, branch._get_all_reference_info())
 
193
        target.set_branch_format(branch.BzrBranchFormat8())
 
194
        converter = b.bzrdir._format.get_converter(target)
 
195
        converter.convert(b.bzrdir, None)
 
196
        b = branch.Branch.open(self.get_url('branch'))
 
197
        self.assertIs(b.__class__, branch.BzrBranch8)
 
198
        self.assertEqual({}, b._get_all_reference_info())
213
199
 
214
200
    def test_convert_knit_dirstate_empty(self):
215
201
        # test that asking for an upgrade from knit to dirstate works.
216
202
        tree = self.make_branch_and_tree('tree', format='knit')
217
203
        target = bzrdir.format_registry.make_bzrdir('dirstate')
218
204
        converter = tree.bzrdir._format.get_converter(target)
219
 
        converter.convert(tree.bzrdir, progress.DummyProgress())
 
205
        converter.convert(tree.bzrdir, None)
220
206
        new_tree = workingtree.WorkingTree.open('tree')
221
207
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
222
208
        self.assertEqual('null:', new_tree.last_revision())
229
215
        tree.add(['file'], ['file-id'])
230
216
        target = bzrdir.format_registry.make_bzrdir('dirstate')
231
217
        converter = tree.bzrdir._format.get_converter(target)
232
 
        converter.convert(tree.bzrdir, progress.DummyProgress())
 
218
        converter.convert(tree.bzrdir, None)
233
219
        new_tree = workingtree.WorkingTree.open('tree')
234
220
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
235
221
        self.assertEqual('null:', new_tree.last_revision())
240
226
        rev_id = tree.commit('first post')
241
227
        target = bzrdir.format_registry.make_bzrdir('dirstate')
242
228
        converter = tree.bzrdir._format.get_converter(target)
243
 
        converter.convert(tree.bzrdir, progress.DummyProgress())
 
229
        converter.convert(tree.bzrdir, None)
244
230
        new_tree = workingtree.WorkingTree.open('tree')
245
231
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
246
232
        self.assertEqual(rev_id, new_tree.last_revision())
247
233
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
248
234
            'pending-merges', 'stat-cache']:
249
 
            self.failIfExists('tree/.bzr/checkout/' + path)
 
235
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
250
236
 
251
237
    def test_convert_knit_merges_dirstate(self):
252
238
        tree = self.make_branch_and_tree('tree', format='knit')
257
243
        tree.merge_from_branch(merge_tree.branch)
258
244
        target = bzrdir.format_registry.make_bzrdir('dirstate')
259
245
        converter = tree.bzrdir._format.get_converter(target)
260
 
        converter.convert(tree.bzrdir, progress.DummyProgress())
 
246
        converter.convert(tree.bzrdir, None)
261
247
        new_tree = workingtree.WorkingTree.open('tree')
262
248
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
263
249
        self.assertEqual(rev_id2, new_tree.last_revision())
264
250
        self.assertEqual([rev_id2, rev_id3], new_tree.get_parent_ids())
265
251
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
266
252
            'pending-merges', 'stat-cache']:
267
 
            self.failIfExists('tree/.bzr/checkout/' + path)
 
253
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
268
254
 
269
255
 
270
256
_upgrade1_template = \
274
260
     ('.bzr/README',
275
261
      'This is a Bazaar control directory.\n'
276
262
      'Do not change any files in this directory.\n'
277
 
      'See http://bazaar-vcs.org/ for more information about Bazaar.\n'),
 
263
      'See http://bazaar.canonical.com/ for more information about Bazaar.\n'),
278
264
     ('.bzr/branch-format', 'Bazaar-NG branch, format 0.0.4\n'),
279
265
     ('.bzr/revision-history',
280
266
      'mbp@sourcefrog.net-20051004035611-176b16534b086b3c\n'
316
302
    ( './.bzr/README',
317
303
      'This is a Bazaar control directory.\n'
318
304
      'Do not change any files in this directory.\n'
319
 
      'See http://bazaar-vcs.org/ for more information about Bazaar.\n'
 
305
      'See http://bazaar.canonical.com/ for more information about Bazaar.\n'
320
306
    ),
321
307
    ( './.bzr/branch-format',
322
308
        'Bazaar-NG branch, format 0.0.4\n'
382
368
    ( './.bzr/README',
383
369
      'This is a Bazaar control directory.\n'
384
370
      'Do not change any files in this directory.\n'
385
 
      'See http://bazaar-vcs.org/ for more information about Bazaar.\n'
 
371
      'See http://bazaar.canonical.com/ for more information about Bazaar.\n'
386
372
    ),
387
373
    ( './.bzr/branch-format',
388
374
        'Bazaar-NG branch, format 0.0.4\n'
428
414
    ),
429
415
    ( './dir/', ),
430
416
]
 
417
 
 
418
 
 
419
class TestSmartUpgrade(tests.TestCaseWithTransport):
 
420
 
 
421
    from_format = bzrdir.format_registry.make_bzrdir("pack-0.92")
 
422
    to_format = bzrdir.format_registry.make_bzrdir("2a")
 
423
 
 
424
    def make_standalone_branch(self):
 
425
        wt = self.make_branch_and_tree("branch1", format=self.from_format)
 
426
        return wt.bzrdir
 
427
 
 
428
    def test_upgrade_standalone_branch(self):
 
429
        control = self.make_standalone_branch()
 
430
        tried, worked, issues = upgrade.smart_upgrade(
 
431
            [control], format=self.to_format)
 
432
        self.assertLength(1, tried)
 
433
        self.assertEqual(tried[0], control)
 
434
        self.assertLength(1, worked)
 
435
        self.assertEqual(worked[0], control)
 
436
        self.assertLength(0, issues)
 
437
        self.assertPathExists('branch1/backup.bzr.~1~')
 
438
        self.assertEqual(control.open_repository()._format,
 
439
                         self.to_format._repository_format)
 
440
 
 
441
    def test_upgrade_standalone_branch_cleanup(self):
 
442
        control = self.make_standalone_branch()
 
443
        tried, worked, issues = upgrade.smart_upgrade(
 
444
            [control], format=self.to_format, clean_up=True)
 
445
        self.assertLength(1, tried)
 
446
        self.assertEqual(tried[0], control)
 
447
        self.assertLength(1, worked)
 
448
        self.assertEqual(worked[0], control)
 
449
        self.assertLength(0, issues)
 
450
        self.assertPathExists('branch1')
 
451
        self.assertPathExists('branch1/.bzr')
 
452
        self.assertPathDoesNotExist('branch1/backup.bzr.~1~')
 
453
        self.assertEqual(control.open_repository()._format,
 
454
                         self.to_format._repository_format)
 
455
 
 
456
    def make_repo_with_branches(self):
 
457
        repo = self.make_repository('repo', shared=True,
 
458
            format=self.from_format)
 
459
        # Note: self.make_branch() always creates a new repo at the location
 
460
        # so we need to avoid using that here ...
 
461
        b1 = bzrdir.BzrDir.create_branch_convenience("repo/branch1",
 
462
            format=self.from_format)
 
463
        b2 = bzrdir.BzrDir.create_branch_convenience("repo/branch2",
 
464
            format=self.from_format)
 
465
        return repo.bzrdir
 
466
 
 
467
    def test_upgrade_repo_with_branches(self):
 
468
        control = self.make_repo_with_branches()
 
469
        tried, worked, issues = upgrade.smart_upgrade(
 
470
            [control], format=self.to_format)
 
471
        self.assertLength(3, tried)
 
472
        self.assertEqual(tried[0], control)
 
473
        self.assertLength(3, worked)
 
474
        self.assertEqual(worked[0], control)
 
475
        self.assertLength(0, issues)
 
476
        self.assertPathExists('repo/backup.bzr.~1~')
 
477
        self.assertPathExists('repo/branch1/backup.bzr.~1~')
 
478
        self.assertPathExists('repo/branch2/backup.bzr.~1~')
 
479
        self.assertEqual(control.open_repository()._format,
 
480
                         self.to_format._repository_format)
 
481
        b1 = branch.Branch.open('repo/branch1')
 
482
        self.assertEqual(b1._format, self.to_format._branch_format)
 
483
 
 
484
    def test_upgrade_repo_with_branches_cleanup(self):
 
485
        control = self.make_repo_with_branches()
 
486
        tried, worked, issues = upgrade.smart_upgrade(
 
487
            [control], format=self.to_format, clean_up=True)
 
488
        self.assertLength(3, tried)
 
489
        self.assertEqual(tried[0], control)
 
490
        self.assertLength(3, worked)
 
491
        self.assertEqual(worked[0], control)
 
492
        self.assertLength(0, issues)
 
493
        self.assertPathExists('repo')
 
494
        self.assertPathExists('repo/.bzr')
 
495
        self.assertPathDoesNotExist('repo/backup.bzr.~1~')
 
496
        self.assertPathDoesNotExist('repo/branch1/backup.bzr.~1~')
 
497
        self.assertPathDoesNotExist('repo/branch2/backup.bzr.~1~')
 
498
        self.assertEqual(control.open_repository()._format,
 
499
                         self.to_format._repository_format)
 
500
        b1 = branch.Branch.open('repo/branch1')
 
501
        self.assertEqual(b1._format, self.to_format._branch_format)