~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_upgrade.py

  • Committer: Martin Packman
  • Date: 2011-12-23 19:38:22 UTC
  • mto: This revision was merged to the branch mainline in revision 6405.
  • Revision ID: martin.packman@canonical.com-20111223193822-hesheea4o8aqwexv
Accept and document passing the medium rather than transport for smart connections

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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for upgrade of old trees.
18
18
 
19
 
This file contains canned versions of some old trees, which are instantiated 
 
19
This file contains canned versions of some old trees, which are instantiated
20
20
and then upgraded to the new format."""
21
21
 
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
 
    repository,
 
28
    tests,
 
29
    upgrade,
34
30
    workingtree,
35
31
    workingtree_4,
36
32
    )
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')
51
 
 
52
 
    def test_upgrade_simple(self):
53
 
        """Upgrade simple v0.0.4 format to latest format"""
54
 
        eq = self.assertEquals
55
 
        self.build_tree_contents(_upgrade1_template)
56
 
        upgrade(u'.')
57
 
        control = bzrdir.BzrDir.open('.')
58
 
        b = control.open_branch()
59
 
        # tsk, peeking under the covers.
60
 
        self.failUnless(
61
 
            isinstance(
62
 
                control._format,
63
 
                bzrdir.BzrDirFormat.get_default_format().__class__))
64
 
        rh = b.revision_history()
65
 
        eq(rh,
66
 
           ['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
67
 
            'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
68
 
        rt = b.repository.revision_tree(rh[0])
69
 
        foo_id = 'foo-20051004035605-91e788d1875603ae'
70
 
        eq(rt.get_file_text(foo_id), 'initial contents\n')
71
 
        rt = b.repository.revision_tree(rh[1])
72
 
        eq(rt.get_file_text(foo_id), 'new contents\n')
73
 
        # check a backup was made:
74
 
        transport = get_transport(b.base)
75
 
        transport.stat('.bzr.backup')
76
 
        transport.stat('.bzr.backup/README')
77
 
        transport.stat('.bzr.backup/branch-format')
78
 
        transport.stat('.bzr.backup/revision-history')
79
 
        transport.stat('.bzr.backup/merged-patches')
80
 
        transport.stat('.bzr.backup/pending-merged-patches')
81
 
        transport.stat('.bzr.backup/pending-merges')
82
 
        transport.stat('.bzr.backup/branch-name')
83
 
        transport.stat('.bzr.backup/branch-lock')
84
 
        transport.stat('.bzr.backup/inventory')
85
 
        transport.stat('.bzr.backup/stat-cache')
86
 
        transport.stat('.bzr.backup/text-store')
87
 
        transport.stat('.bzr.backup/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
88
 
        transport.stat('.bzr.backup/text-store/foo-20051004035756-4081373d897c3453.gz')
89
 
        transport.stat('.bzr.backup/inventory-store/')
90
 
        transport.stat('.bzr.backup/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
91
 
        transport.stat('.bzr.backup/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
92
 
        transport.stat('.bzr.backup/revision-store/')
93
 
        transport.stat('.bzr.backup/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
94
 
        transport.stat('.bzr.backup/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
95
 
 
96
 
    def test_upgrade_with_ghosts(self):
97
 
        """Upgrade v0.0.4 tree containing ghost references.
98
 
 
99
 
        That is, some of the parents of revisions mentioned in the branch
100
 
        aren't present in the branch's storage. 
101
 
 
102
 
        This shouldn't normally happen in branches created entirely in 
103
 
        bzr, but can happen in branches imported from baz and arch, or from
104
 
        other systems, where the importer knows about a revision but not 
105
 
        its contents."""
106
 
        eq = self.assertEquals
107
 
        self.build_tree_contents(_ghost_template)
108
 
        upgrade(u'.')
109
 
        b = Branch.open(u'.')
110
 
        revision_id = b.revision_history()[1]
111
 
        rev = b.repository.get_revision(revision_id)
112
 
        eq(len(rev.parent_ids), 2)
113
 
        eq(rev.parent_ids[1], 'wibble@wobble-2')
114
 
 
115
 
    def test_upgrade_makes_dir_weaves(self):
116
 
        self.build_tree_contents(_upgrade_dir_template)
117
 
        old_repodir = bzrlib.bzrdir.BzrDir.open_unsupported('.')
118
 
        old_repo_format = old_repodir.open_repository()._format
119
 
        upgrade('.')
120
 
        # this is the path to the literal file. As format changes 
121
 
        # occur it needs to be updated. FIXME: ask the store for the
122
 
        # path.
123
 
        repo = bzrlib.repository.Repository.open('.')
124
 
        # it should have changed the format
125
 
        self.assertNotEqual(old_repo_format.__class__, repo._format.__class__)
126
 
        # and we should be able to read the names for the file id 
127
 
        # 'dir-20051005095101-da1441ea3fa6917a'
128
 
        self.assertNotEqual(
129
 
            [],
130
 
            repo.text_store.get_weave(
131
 
                'dir-20051005095101-da1441ea3fa6917a',
132
 
                repo.get_transaction()))
133
 
 
134
 
    def test_upgrade_to_meta_sets_workingtree_last_revision(self):
135
 
        self.build_tree_contents(_upgrade_dir_template)
136
 
        upgrade('.', bzrdir.BzrDirMetaFormat1())
137
 
        tree = workingtree.WorkingTree.open('.')
138
 
        self.assertEqual([tree.branch.revision_history()[-1]],
139
 
            tree.get_parent_ids())
140
 
 
141
 
    def test_upgrade_v6_to_meta_no_workingtree(self):
142
 
        # Some format6 branches do not have checkout files. Upgrading
143
 
        # such a branch to metadir must not setup a working tree.
144
 
        self.build_tree_contents(_upgrade1_template)
145
 
        upgrade('.', bzrdir.BzrDirFormat6())
146
 
        transport = get_transport('.')
147
 
        transport.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
148
 
        assert not transport.has('.bzr/stat-cache')
149
 
        # XXX: upgrade fails if a .bzr.backup is already present
150
 
        # -- David Allouche 2006-08-11
151
 
        transport.delete_tree('.bzr.backup')
152
 
        # At this point, we have a format6 branch without checkout files.
153
 
        upgrade('.', bzrdir.BzrDirMetaFormat1())
154
 
        # The upgrade should not have set up a working tree.
155
 
        control = bzrdir.BzrDir.open('.')
156
 
        self.assertFalse(control.has_workingtree())
157
 
        # We have covered the scope of this test, we may as well check that
158
 
        # upgrade has not eaten our data, even if it's a bit redundant with
159
 
        # other tests.
160
 
        self.failUnless(isinstance(control._format, bzrdir.BzrDirMetaFormat1))
161
 
        branch = control.open_branch()
162
 
        self.assertEquals(branch.revision_history(),
163
 
           ['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
164
 
            'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
 
33
 
 
34
 
 
35
class TestUpgrade(tests.TestCaseWithTransport):
 
36
 
 
37
    def test_upgrade_rich_root(self):
 
38
        tree = self.make_branch_and_tree('tree', format='rich-root')
 
39
        rev_id = tree.commit('first post')
 
40
        upgrade.upgrade('tree')
165
41
 
166
42
    def test_convert_branch5_branch6(self):
167
 
        branch = self.make_branch('branch', format='knit')
168
 
        branch.set_revision_history(['AB', 'CD'])
169
 
        branch.set_parent('file:///EF')
170
 
        branch.set_bound_location('file:///GH')
171
 
        branch.set_push_location('file:///IJ')
 
43
        b = self.make_branch('branch', format='knit')
 
44
        b._set_revision_history(['CD'])
 
45
        b.set_parent('file:///EF')
 
46
        b.set_bound_location('file:///GH')
 
47
        b.set_push_location('file:///IJ')
172
48
        target = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
173
 
        converter = branch.bzrdir._format.get_converter(target)
174
 
        converter.convert(branch.bzrdir, progress.DummyProgress())
175
 
        new_branch = _mod_branch.Branch.open(self.get_url('branch'))
176
 
        self.assertIs(new_branch.__class__, _mod_branch.BzrBranch6)
 
49
        converter = b.bzrdir._format.get_converter(target)
 
50
        converter.convert(b.bzrdir, None)
 
51
        new_branch = branch.Branch.open(self.get_url('branch'))
 
52
        self.assertIs(new_branch.__class__, branch.BzrBranch6)
177
53
        self.assertEqual('CD', new_branch.last_revision())
178
54
        self.assertEqual('file:///EF', new_branch.get_parent())
179
55
        self.assertEqual('file:///GH', new_branch.get_bound_location())
181
57
        self.assertEqual('file:///IJ',
182
58
            branch_config.get_user_option('push_location'))
183
59
 
184
 
        branch2 = self.make_branch('branch2', format='knit')
185
 
        converter = branch2.bzrdir._format.get_converter(target)
186
 
        converter.convert(branch2.bzrdir, progress.DummyProgress())
187
 
        branch2 = _mod_branch.Branch.open(self.get_url('branch'))
188
 
        self.assertIs(branch2.__class__, _mod_branch.BzrBranch6)
 
60
        b2 = self.make_branch('branch2', format='knit')
 
61
        converter = b2.bzrdir._format.get_converter(target)
 
62
        converter.convert(b2.bzrdir, None)
 
63
        b2 = branch.Branch.open(self.get_url('branch'))
 
64
        self.assertIs(b2.__class__, branch.BzrBranch6)
 
65
 
 
66
    def test_convert_branch7_branch8(self):
 
67
        b = self.make_branch('branch', format='1.9')
 
68
        target = bzrdir.format_registry.make_bzrdir('1.9')
 
69
        target.set_branch_format(branch.BzrBranchFormat8())
 
70
        converter = b.bzrdir._format.get_converter(target)
 
71
        converter.convert(b.bzrdir, None)
 
72
        b = branch.Branch.open(self.get_url('branch'))
 
73
        self.assertIs(b.__class__, branch.BzrBranch8)
 
74
        self.assertEqual({}, b._get_all_reference_info())
189
75
 
190
76
    def test_convert_knit_dirstate_empty(self):
191
77
        # test that asking for an upgrade from knit to dirstate works.
192
78
        tree = self.make_branch_and_tree('tree', format='knit')
193
79
        target = bzrdir.format_registry.make_bzrdir('dirstate')
194
80
        converter = tree.bzrdir._format.get_converter(target)
195
 
        converter.convert(tree.bzrdir, progress.DummyProgress())
 
81
        converter.convert(tree.bzrdir, None)
196
82
        new_tree = workingtree.WorkingTree.open('tree')
197
83
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
198
 
        self.assertEqual(None, new_tree.last_revision())
 
84
        self.assertEqual('null:', new_tree.last_revision())
199
85
 
200
86
    def test_convert_knit_dirstate_content(self):
201
87
        # smoke test for dirstate conversion: we call dirstate primitives,
205
91
        tree.add(['file'], ['file-id'])
206
92
        target = bzrdir.format_registry.make_bzrdir('dirstate')
207
93
        converter = tree.bzrdir._format.get_converter(target)
208
 
        converter.convert(tree.bzrdir, progress.DummyProgress())
 
94
        converter.convert(tree.bzrdir, None)
209
95
        new_tree = workingtree.WorkingTree.open('tree')
210
96
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
211
 
        self.assertEqual(None, new_tree.last_revision())
 
97
        self.assertEqual('null:', new_tree.last_revision())
212
98
 
213
99
    def test_convert_knit_one_parent_dirstate(self):
214
100
        # test that asking for an upgrade from knit to dirstate works.
216
102
        rev_id = tree.commit('first post')
217
103
        target = bzrdir.format_registry.make_bzrdir('dirstate')
218
104
        converter = tree.bzrdir._format.get_converter(target)
219
 
        converter.convert(tree.bzrdir, progress.DummyProgress())
 
105
        converter.convert(tree.bzrdir, None)
220
106
        new_tree = workingtree.WorkingTree.open('tree')
221
107
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
222
108
        self.assertEqual(rev_id, new_tree.last_revision())
223
109
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
224
110
            'pending-merges', 'stat-cache']:
225
 
            self.failIfExists('tree/.bzr/checkout/' + path)
 
111
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
226
112
 
227
113
    def test_convert_knit_merges_dirstate(self):
228
114
        tree = self.make_branch_and_tree('tree', format='knit')
233
119
        tree.merge_from_branch(merge_tree.branch)
234
120
        target = bzrdir.format_registry.make_bzrdir('dirstate')
235
121
        converter = tree.bzrdir._format.get_converter(target)
236
 
        converter.convert(tree.bzrdir, progress.DummyProgress())
 
122
        converter.convert(tree.bzrdir, None)
237
123
        new_tree = workingtree.WorkingTree.open('tree')
238
124
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
239
125
        self.assertEqual(rev_id2, new_tree.last_revision())
240
126
        self.assertEqual([rev_id2, rev_id3], new_tree.get_parent_ids())
241
127
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
242
128
            'pending-merges', 'stat-cache']:
243
 
            self.failIfExists('tree/.bzr/checkout/' + path)
244
 
 
245
 
 
246
 
_upgrade1_template = \
247
 
     [
248
 
     ('foo', 'new contents\n'),
249
 
     ('.bzr/',),
250
 
     ('.bzr/README',
251
 
      'This is a Bazaar-NG control directory.\nDo not change any files in this directory.\n'),
252
 
     ('.bzr/branch-format', 'Bazaar-NG branch, format 0.0.4\n'),
253
 
     ('.bzr/revision-history',
254
 
      'mbp@sourcefrog.net-20051004035611-176b16534b086b3c\n'
255
 
      'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd\n'),
256
 
     ('.bzr/merged-patches', ''),
257
 
     ('.bzr/pending-merged-patches', ''),
258
 
     ('.bzr/branch-name', ''),
259
 
     ('.bzr/branch-lock', ''),
260
 
     ('.bzr/pending-merges', ''),
261
 
     ('.bzr/inventory',
262
 
      '<inventory>\n'
263
 
      '<entry file_id="foo-20051004035605-91e788d1875603ae" kind="file" name="foo" />\n'
264
 
      '</inventory>\n'),
265
 
     ('.bzr/stat-cache',
266
 
      '### bzr hashcache v5\n'
267
 
      'foo// be9f309239729f69a6309e970ef24941d31e042c 13 1128398176 1128398176 303464 770\n'),
268
 
     ('.bzr/text-store/',),
269
 
     ('.bzr/text-store/foo-20051004035611-1591048e9dc7c2d4.gz',
270
 
      '\x1f\x8b\x08\x00[\xfdAC\x02\xff\xcb\xcc\xcb,\xc9L\xccQH\xce\xcf+I\xcd+)\xe6\x02\x00\xdd\xcc\xf90\x11\x00\x00\x00'),
271
 
     ('.bzr/text-store/foo-20051004035756-4081373d897c3453.gz',
272
 
      '\x1f\x8b\x08\x00\xc4\xfdAC\x02\xff\xcbK-WH\xce\xcf+I\xcd+)\xe6\x02\x00g\xc3\xdf\xc9\r\x00\x00\x00'),
273
 
     ('.bzr/inventory-store/',),
274
 
     ('.bzr/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz',
275
 
      '\x1f\x8b\x08\x00[\xfdAC\x02\xffm\x8f\xcd\n\xc20\x10\x84\xef>E\xc8\xbdt7?M\x02\xad\xaf"\xa1\x99`P[\xa8E\xacOo\x14\x05\x0f\xdef\xe1\xfbv\x98\xbeL7L\xeb\xbcl\xfb]_\xc3\xb2\x89\\\xce8\x944\xc8<\xcf\x8d"\xb2LdH\xdb\x8el\x13\x18\xce\xfb\xc4\xde\xd5SGHq*\xd3\x0b\xad\x8e\x14S\xbc\xe0\xadI\xb1\xe2\xbe\xfe}\xc2\xdc\xb0\rL\xc6#\xa4\xd1\x8d*\x99\x0f}=F\x1e$8G\x9d\xa0\x02\xa1rP9\x01c`FV\xda1qg\x98"\x02}\xa5\xf2\xa8\x95\xec\xa4h\xeb\x80\xf6g\xcd\x13\xb3\x01\xcc\x98\xda\x00\x00\x00'),
276
 
     ('.bzr/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz',
277
 
      '\x1f\x8b\x08\x00\xc4\xfdAC\x02\xffm\x8f\xc1\n\xc20\x10D\xef~E\xc8\xbd\xb8\x9bM\x9a,\xb4\xfe\x8a\xc4f\x83Am\xa1\x16\xb1~\xbdQ\x14<x\x9b\x81y3LW\xc6\x9b\x8c\xcb4\xaf\xbbMW\xc5\xbc\xaa\\\xce\xb2/\xa9\xd7y\x9a\x1a\x03\xe0\x10\xc0\x02\xb9\x16\\\xc3(>\x84\x84\xc1WKQ\xb4:\x95\xf1\x15\xad\x8cVc\xbc\xc8\x1b\xd3j\x91\xfb\xf2\xaf\xa4r\x8d\x85\x80\xe4)\x05\xf6\x03YG\x9f\xf4\xf5\x18\xb1\xd7\x07\xe1L\xc0\x86\xd8\x1b\xce-\xc7\xb6:a\x0f\x92\x8de\x8b\x89P\xc0\x9a\xe1\x0b\x95G\x9d\xc4\xda\xb1\xad\x07\xb6?o\x9e\xb5\xff\xf0\xf9\xda\x00\x00\x00'),
278
 
     ('.bzr/revision-store/',),
279
 
     ('.bzr/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz',
280
 
      '\x1f\x8b\x08\x00[\xfdAC\x02\xff\x9d\x8eKj\xc30\x14E\xe7^\x85\xd0 \xb3$\xefI\xd1\x8f\xd8\xa6\x1b(t\x07E?\xbb\x82H\n\xb2\x1ahW\xdfB1\x14:\xeb\xf4r\xee\xbdgl\xf1\x91\xb6T\x0b\xf15\xe7\xd4{l\x13}\xb6\xad\xa7B^j\xbd\x91\xc3\xad_\xb3\xbb?m\xf5\xbd\xf9\xb8\xb4\xba\x9eJ\xec\x87\xb5_)I\xe5\x11K\xaf\xed\xe35\x85\x89\xfe\xa5\x8e\x0c@ \xc0\x05\xb8\x90\x88GT\xd2\xa1\x14\xfc\xe2@K\xc7\xfd\xef\x85\xed\xcd\xe2D\x95\x8d\x1a\xa47<\x02c2\xb0 \xbc\xd0\x8ay\xa3\xbcp\x8a\x83\x12A3\xb7XJv\xef\x7f_\xf7\x94\xe3\xd6m\xbeO\x14\x91in4*<\x812\x88\xc60\xfc\x01>k\x89\x13\xe5\x12\x00\xe8<\x8c\xdf\x8d\xcd\xaeq\xb6!\x90\xa5\xd6\xf1\xbc\x07\xc3x\xde\x85\xe6\xe1\x0b\xc8\x8a\x98\x03T\x01\x00\x00'),
281
 
     ('.bzr/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz',
282
 
      '\x1f\x8b\x08\x00\xc4\xfdAC\x02\xff\x9d\x90Kj\x031\x0c\x86\xf79\xc5\xe0Ev\xe9\xc8o\x9b\xcc\x84^\xa0\xd0\x1b\x14\xbf&5d\xec`\xbb\x81\xf6\xf45\x84\xa4\x81\xaeZ\xa1\x85\x84^\xdf\xaf\xa9\x84K\xac1\xa7\xc1\xe5u\x8d\xad\x852\xa3\x17SZL\xc3k\xce\xa7a{j\xfb\xd5\x9e\x9fk\xfe(.,%\x1f\x9fRh\xdbc\xdb\xa3!\xa6KH-\x97\xcf\xb7\xe8g\xf4\xbbkG\x008\x06`@\xb9\xe4bG(_\x88\x95\xde\xf9n\xca\xfb\xc7\r\xf5\xdd\xe0\x19\xa9\x85)\x81\xf5"\xbd\x04j\xb8\x02b\xa8W\\\x0b\xc9\x14\xf4\xbc\xbb\xd7\xd6H4\xdc\xb8\xff}\xba\xc55\xd4f\xd6\xf3\x8c0&\x8ajE\xa4x\xe2@\xa5\xa6\x9a\xf3k\xc3WNaFT\x00\x00:l\xa6>Q\xcd1\x1cjp9\xf9;\xc34\xde\n\x9b\xe9lJWT{t\',a\xf9\x0b\xae\xc0x\x87\xa5\xb0Xp\xca,(a\xa9{\xd0{}\xd4\x12\x04(\xc5\xbb$\xc5$V\xceaI\x19\x01\xa2\x1dh\xed\x82d\x8c.\xccr@\xc3\xd8Q\xc6\x1f\xaa\xf1\xb6\xe8\xb0\xf9\x06QR\r\xf9\xfc\x01\x00\x00')]
283
 
 
284
 
 
285
 
_ghost_template = [
286
 
    ( './foo',
287
 
        'hello\n'
288
 
    ),
289
 
    ( './.bzr/', ),
290
 
    ( './.bzr/README',
291
 
        'This is a Bazaar-NG control directory.\n'
292
 
        'Do not change any files in this directory.\n'
293
 
    ),
294
 
    ( './.bzr/branch-format',
295
 
        'Bazaar-NG branch, format 0.0.4\n'
296
 
    ),
297
 
    ( './.bzr/branch-lock',
298
 
        ''
299
 
    ),
300
 
    ( './.bzr/branch-name',
301
 
        ''
302
 
    ),
303
 
    ( './.bzr/inventory',
304
 
        '<inventory>\n'
305
 
        '<entry file_id="foo-20051004104918-0379cb7c76354cde" kind="file" name="foo" />\n'
306
 
        '</inventory>\n'
307
 
    ),
308
 
    ( './.bzr/merged-patches',
309
 
        ''
310
 
    ),
311
 
    ( './.bzr/pending-merged-patches',
312
 
        ''
313
 
    ),
314
 
    ( './.bzr/pending-merges',
315
 
        ''
316
 
    ),
317
 
    ( './.bzr/revision-history',
318
 
        'mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b\n'
319
 
        'mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d\n'
320
 
    ),
321
 
    ( './.bzr/stat-cache',
322
 
        '### bzr hashcache v5\n'
323
 
        'foo// f572d396fae9206628714fb2ce00f72e94f2258f 6 1128422956 1128422956 306900 770\n'
324
 
    ),
325
 
    ( './.bzr/text-store/', ),
326
 
    ( './.bzr/text-store/foo-20051004104921-8de8118a71be45ba.gz',
327
 
        '\x1f\x8b\x08\x081^BC\x00\x03foo-20051004104921-8de8118a71be45ba\x00\xcbH\xcd\xc9\xc9\xe7\x02\x00 0:6\x06\x00\x00\x00'
328
 
    ),
329
 
    ( './.bzr/inventory-store/', ),
330
 
    ( './.bzr/inventory-store/mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b.gz',
331
 
        '\x1f\x8b\x08\x081^BC\x00\x03mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b\x00m\x8f\xcb\n'
332
 
        '\xc20\x10E\xf7~E\xc8\xbe83\xcd\x13\xaa\xbf"yL0\xa8-\xd4"\xd6\xaf7\x8a\x82\x0bw\xb38\xe7\xde;C\x1do<.\xd3\xbc\xee7C;\xe6U\x94z\xe6C\xcd;Y\xa6\xa9#\x00\x8d\x00\n'
333
 
        'Ayt\x1d\xf4\xd6\xa7h\x935\xbdV)\xb3\x14\xa7:\xbe\xd0\xe6H1\x86\x0b\xbf5)\x16\xbe/\x7fC\x08;\x97\xd9!\xba`1\xb2\xd21|\xe8\xeb1`\xe3\xb5\xa5\xdc{S\x02{\x02c\xc8YT%Rb\x80b\x89\xbd*D\xda\x95\xafT\x1f\xad\xd2H\xb1m\xfb\xb7?\xcf<\x01W}\xb5\x8b\xd9\x00\x00\x00'
334
 
    ),
335
 
    ( './.bzr/inventory-store/mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d.gz',
336
 
        '\x1f\x8b\x08\x08A^BC\x00\x03mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d\x00m\x8f\xcb\n'
337
 
        '\xc20\x10E\xf7~E\xc8\xbe83\xcd\x13\xaa\xbf"yL0\xa8-\xd4"\xd6\xaf7\x8a\x82\x0bw\xb38\xe7\xde;C\x1do<.\xd3\xbc\xee7C;\xe6U\x94z\xe6C\xcd;Y\xa6\xa9#\x00\x8d\x00\n'
338
 
        'Ayt\x1d\xf4\xd6\xa7h\x935\xbdV)\xb3\x14\xa7:\xbe\xd0\xe6H1\x86\x0b\xbf5)\x16\xbe/\x7fC\x08;\x97\xd9!\xba`1\xb2\xd21|\xe8\xeb1`\xe3\xb5\xa5\xdc{S\x02{\x02c\xc8YT%Rb\x80b\x89\xbd*D\xda\x95\xafT\x1f\xad\xd2H\xb1m\xfb\xb7?\xcf<\x01W}\xb5\x8b\xd9\x00\x00\x00'
339
 
    ),
340
 
    ( './.bzr/revision-store/', ),
341
 
    ( './.bzr/revision-store/mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b.gz',
342
 
        '\x1f\x8b\x08\x081^BC\x00\x03mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b\x00\x9d\x8eMj\xc30\x14\x84\xf7>\x85\xd0"\xbb$\xef\xc9\xb6,\x11\xdb\xf4\x02\x85\xde\xa0\xe8\xe7\xd9\x11\xc4R\x90\xd4@{\xfa\x06\x8a\xa1\xd0]\x97\x03\xdf\xcc|c\xa6G(!E\xe6\xd2\xb6\x85Z)O\xfc\xd5\xe4\x1a"{K\xe9\xc6\x0e\xb7z\xd9\xec\xfd\xa5\xa4\x8f\xech\xc9i=E\xaa\x87\xb5^8\x0b\xf1A\xb1\xa6\xfc\xf9\x1e\xfc\xc4\xffRG\x01\xd0#@\x87\xd0i\x81G\xa3\x95%!\x06\xe5}\x0bv\xb0\xbf\x17\xca\xd5\xe0\xc4-\xa0\xb1\x8b\xb6`\xc0I\xa4\xc5\xf4\x9el\xef\x95v [\x94\xcf\x8e\xd5\xcay\xe4l\xf7\xfe\xf7u\r'
343
 
        '\x1b\x95j\xb6\xfb\xc4\x11\x85\xea\x84\xd0\x12O\x03t\x83D\xad\xc4\x0f\xf0\x95"M\xbc\x95\x00\xc0\xe7f|6\x8aYi^B.u<\xef\xb1\x19\xcf\xbb\xce\xdc|\x038=\xc7\xe6R\x01\x00\x00'
344
 
    ),
345
 
    ( './.bzr/revision-store/mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d.gz',
346
 
        '\x1f\x8b\x08\x08A^BC\x00\x03mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d\x00\x9d\x90\xc1j\xc30\x0c\x86\xef}\n'
347
 
        "\xe3Coie'\xb1c\x9a\x94\xbe\xc0`o0,[N\x03M\\\x1c\xafe{\xfae\x94n\x85\xc1`;Y\x88O\xd2\xff\xb9Mt\x19\xe6!N\xcc\xc5q\x1cr\xa6\xd4\xf1'\x9b\xf20\xb1\xe7\x18Ol}\xca\xbb\x11\xcf\x879\xbe&G!\xc5~3Q^\xf7y\xc7\xd90]h\xca1\xbd\xbd\x0c\xbe\xe3?\xa9B\x02\xd4\x02\xa0\x12P\x99R\x17\xce\xa0\xb6\x1a\x83s\x80(\xa5\x7f\xdc0\x1f\xad\xe88\x82\xb0\x18\x0c\x82\x05\xa7\x04\x05[{\xc2\xda7\xc6\x81*\x85B\x8dh\x1a\xe7\x05g\xf7\xdc\xff>\x9d\x87\x91\xe6l\xc7s\xc7\x85\x90M%\xa5\xd1z#\x85\xa8\x9b\x1a\xaa\xfa\x06\xbc\xc7\x89:^*\x00\xe0\xfbU\xbbL\xcc\xb6\xa7\xfdH\xa9'\x16\x03\xeb\x8fq\xce\xed\xf6\xde_\xb5g\x9b\x16\xa1y\xa9\xbe\x02&\n"
348
 
        '\x7fJ+EaM\x83$\xa5n\xbc/a\x91~\xd0\xbd\xfd\x135\n'
349
 
        '\xd0\x9a`\x0c*W\x1aR\xc1\x94du\x08(\t\xb0\x91\xdeZ\xa3\x9cU\x9cm\x7f\x8dr\x1d\x10Ot\xb8\xc6\xcf\xa7\x907|\xfb-\xb1\xbd\xd3\xfb\xd5\x07\xeeD\xee\x08*\x02\x00\x00'
350
 
    ),
351
 
]
352
 
 
353
 
_upgrade_dir_template = [
354
 
    ( './.bzr/', ),
355
 
    ( './.bzr/README',
356
 
        'This is a Bazaar-NG control directory.\n'
357
 
        'Do not change any files in this directory.\n'
358
 
    ),
359
 
    ( './.bzr/branch-format',
360
 
        'Bazaar-NG branch, format 0.0.4\n'
361
 
    ),
362
 
    ( './.bzr/branch-lock',
363
 
        ''
364
 
    ),
365
 
    ( './.bzr/branch-name',
366
 
        ''
367
 
    ),
368
 
    ( './.bzr/inventory',
369
 
        '<inventory>\n'
370
 
        '<entry file_id="dir-20051005095101-da1441ea3fa6917a" kind="directory" name="dir" />\n'
371
 
        '</inventory>\n'
372
 
    ),
373
 
    ( './.bzr/merged-patches',
374
 
        ''
375
 
    ),
376
 
    ( './.bzr/pending-merged-patches',
377
 
        ''
378
 
    ),
379
 
    ( './.bzr/pending-merges',
380
 
        ''
381
 
    ),
382
 
    ( './.bzr/revision-history',
383
 
        'robertc@robertcollins.net-20051005095108-6065fbd8e7d8617e\n'
384
 
    ),
385
 
    ( './.bzr/stat-cache',
386
 
        '### bzr hashcache v5\n'
387
 
    ),
388
 
    ( './.bzr/text-store/', ),
389
 
    ( './.bzr/inventory-store/', ),
390
 
    ( './.bzr/inventory-store/robertc@robertcollins.net-20051005095108-6065fbd8e7d8617e.gz',
391
 
        '\x1f\x8b\x08\x00\x0c\xa2CC\x02\xff\xb3\xc9\xcc+K\xcd+\xc9/\xaa\xb4\xe3\xb2\x012\x8a*\x15\xd22sR\xe33Sl\x95R2\x8bt\x8d\x0c\x0cL\r'
392
 
        "\x81\xd8\xc0\x12H\x19\xea\xa6$\x1a\x9a\x98\x18\xa6&\x1a\xa7%\x9aY\x1a\x9a'*)dg\xe6A\x94\xa6&\x83LQR\xc8K\xccM\x05\x0b()\xe8\x03\xcd\xd4G\xb2\x00\x00\xc2<\x94\xb1m\x00\x00\x00"
393
 
    ),
394
 
    ( './.bzr/revision-store/', ),
395
 
    ( './.bzr/revision-store/robertc@robertcollins.net-20051005095108-6065fbd8e7d8617e.gz',
396
 
        '\x1f\x8b\x08\x00\x0c\xa2CC\x02\xff\xa5OKj\xc30\x14\xdc\xfb\x14B\x8b\xec\x92<I\xd6\xc7\xc42\x85\xde\xa0\x17(\xb6\xf4\x9c\n'
397
 
        'l\xa9H"\x90\x9c\xbe\xa6\xa9\xa1\x9b\xae\xbax\x0c\xcc\xe71\xd3g\xbc\x85\x12R$.\xadk\xa8\x15\xb3\xa5oi\xc2\\\xc9kZ\x96\x10\x0b9,\xf5\x92\xbf)\xf7\xf2\x83O\xe5\x14\xb1\x1e\xae\xf5BI\x887\x8c5\xe5\xfb{\xf0\x96\xfei>r\x00\xc9\xb6\x83n\x03sT\xa0\xe4<y\x83\xda\x1b\xc54\xfe~T>Ff\xe9\xcc:\xdd\x8e\xa6E\xc7@\xa2\x82I\xaaNL\xbas\\313)\x00\xb9\xe6\xe0(\xd9\x87\xfc\xb7A\r'
398
 
        "+\x96:\xae\x9f\x962\xc6\x8d\x04i\x949\x01\x97R\xb7\x1d\x17O\xc3#E\xb4T(\x00\xa0C\xd3o\x892^q\x18\xbd'>\xe4\xfe\xbc\x13M\x7f\xde{\r"
399
 
        '\xcd\x17\x85\xea\xba\x03l\x01\x00\x00'
400
 
    ),
401
 
    ( './dir/', ),
402
 
]
 
129
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
 
130
 
 
131
 
 
132
class TestSmartUpgrade(tests.TestCaseWithTransport):
 
133
 
 
134
    from_format = bzrdir.format_registry.make_bzrdir("pack-0.92")
 
135
    to_format = bzrdir.format_registry.make_bzrdir("2a")
 
136
 
 
137
    def make_standalone_branch(self):
 
138
        wt = self.make_branch_and_tree("branch1", format=self.from_format)
 
139
        return wt.bzrdir
 
140
 
 
141
    def test_upgrade_standalone_branch(self):
 
142
        control = self.make_standalone_branch()
 
143
        tried, worked, issues = upgrade.smart_upgrade(
 
144
            [control], format=self.to_format)
 
145
        self.assertLength(1, tried)
 
146
        self.assertEqual(tried[0], control)
 
147
        self.assertLength(1, worked)
 
148
        self.assertEqual(worked[0], control)
 
149
        self.assertLength(0, issues)
 
150
        self.assertPathExists('branch1/backup.bzr.~1~')
 
151
        self.assertEqual(control.open_repository()._format,
 
152
                         self.to_format._repository_format)
 
153
 
 
154
    def test_upgrade_standalone_branch_cleanup(self):
 
155
        control = self.make_standalone_branch()
 
156
        tried, worked, issues = upgrade.smart_upgrade(
 
157
            [control], format=self.to_format, clean_up=True)
 
158
        self.assertLength(1, tried)
 
159
        self.assertEqual(tried[0], control)
 
160
        self.assertLength(1, worked)
 
161
        self.assertEqual(worked[0], control)
 
162
        self.assertLength(0, issues)
 
163
        self.assertPathExists('branch1')
 
164
        self.assertPathExists('branch1/.bzr')
 
165
        self.assertPathDoesNotExist('branch1/backup.bzr.~1~')
 
166
        self.assertEqual(control.open_repository()._format,
 
167
                         self.to_format._repository_format)
 
168
 
 
169
    def make_repo_with_branches(self):
 
170
        repo = self.make_repository('repo', shared=True,
 
171
            format=self.from_format)
 
172
        # Note: self.make_branch() always creates a new repo at the location
 
173
        # so we need to avoid using that here ...
 
174
        b1 = bzrdir.BzrDir.create_branch_convenience("repo/branch1",
 
175
            format=self.from_format)
 
176
        b2 = bzrdir.BzrDir.create_branch_convenience("repo/branch2",
 
177
            format=self.from_format)
 
178
        return repo.bzrdir
 
179
 
 
180
    def test_upgrade_repo_with_branches(self):
 
181
        control = self.make_repo_with_branches()
 
182
        tried, worked, issues = upgrade.smart_upgrade(
 
183
            [control], format=self.to_format)
 
184
        self.assertLength(3, tried)
 
185
        self.assertEqual(tried[0], control)
 
186
        self.assertLength(3, worked)
 
187
        self.assertEqual(worked[0], control)
 
188
        self.assertLength(0, issues)
 
189
        self.assertPathExists('repo/backup.bzr.~1~')
 
190
        self.assertPathExists('repo/branch1/backup.bzr.~1~')
 
191
        self.assertPathExists('repo/branch2/backup.bzr.~1~')
 
192
        self.assertEqual(control.open_repository()._format,
 
193
                         self.to_format._repository_format)
 
194
        b1 = branch.Branch.open('repo/branch1')
 
195
        self.assertEqual(b1._format, self.to_format._branch_format)
 
196
 
 
197
    def test_upgrade_repo_with_branches_cleanup(self):
 
198
        control = self.make_repo_with_branches()
 
199
        tried, worked, issues = upgrade.smart_upgrade(
 
200
            [control], format=self.to_format, clean_up=True)
 
201
        self.assertLength(3, tried)
 
202
        self.assertEqual(tried[0], control)
 
203
        self.assertLength(3, worked)
 
204
        self.assertEqual(worked[0], control)
 
205
        self.assertLength(0, issues)
 
206
        self.assertPathExists('repo')
 
207
        self.assertPathExists('repo/.bzr')
 
208
        self.assertPathDoesNotExist('repo/backup.bzr.~1~')
 
209
        self.assertPathDoesNotExist('repo/branch1/backup.bzr.~1~')
 
210
        self.assertPathDoesNotExist('repo/branch2/backup.bzr.~1~')
 
211
        self.assertEqual(control.open_repository()._format,
 
212
                         self.to_format._repository_format)
 
213
        b1 = branch.Branch.open('repo/branch1')
 
214
        self.assertEqual(b1._format, self.to_format._branch_format)