19
19
This file contains canned versions of some old trees, which are instantiated
20
20
and then upgraded to the new format."""
22
# TODO queue for upgrade:
23
# test the error message when upgrading an unknown BzrDir format.
26
from bzrlib.selftest import TestCase, TestCaseInTempDir
30
27
from bzrlib.branch import Branch
31
import bzrlib.bzrdir as bzrdir
32
import bzrlib.repository as repository
33
28
from bzrlib.revision import is_ancestor
34
from bzrlib.tests import TestCase, TestCaseInTempDir
35
from bzrlib.transport import get_transport
36
29
from bzrlib.upgrade import upgrade
37
import bzrlib.workingtree as workingtree
30
from bzrlib.selftest.treeshape import build_tree_contents
40
32
class TestUpgrade(TestCaseInTempDir):
42
33
def test_build_tree(self):
43
34
"""Test tree-building test helper"""
44
self.build_tree_contents(_upgrade1_template)
45
self.failUnlessExists('foo')
46
self.failUnlessExists('.bzr/README')
35
build_tree_contents(_upgrade1_template)
36
self.assertTrue(os.path.exists('foo'))
37
self.assertTrue(os.path.exists('.bzr/README'))
48
39
def test_upgrade_simple(self):
49
"""Upgrade simple v0.0.4 format to v6"""
40
"""Upgrade simple v0.0.4 format to v5"""
50
41
eq = self.assertEquals
51
self.build_tree_contents(_upgrade1_template)
53
control = bzrdir.BzrDir.open('.')
54
b = control.open_branch()
55
# tsk, peeking under the covers.
59
bzrdir.BzrDirFormat.get_default_format().__class__))
42
build_tree_contents(_upgrade1_template)
45
eq(b._branch_format, 5)
60
46
rh = b.revision_history()
62
48
['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
63
49
'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
64
rt = b.repository.revision_tree(rh[0])
50
t = b.revision_tree(rh[0])
65
51
foo_id = 'foo-20051004035605-91e788d1875603ae'
66
eq(rt.get_file_text(foo_id), 'initial contents\n')
67
rt = b.repository.revision_tree(rh[1])
68
eq(rt.get_file_text(foo_id), 'new contents\n')
69
# check a backup was made:
70
transport = get_transport(b.base)
71
transport.stat('.bzr.backup')
72
transport.stat('.bzr.backup/README')
73
transport.stat('.bzr.backup/branch-format')
74
transport.stat('.bzr.backup/revision-history')
75
transport.stat('.bzr.backup/merged-patches')
76
transport.stat('.bzr.backup/pending-merged-patches')
77
transport.stat('.bzr.backup/pending-merges')
78
transport.stat('.bzr.backup/branch-name')
79
transport.stat('.bzr.backup/branch-lock')
80
transport.stat('.bzr.backup/inventory')
81
transport.stat('.bzr.backup/stat-cache')
82
transport.stat('.bzr.backup/text-store')
83
transport.stat('.bzr.backup/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
84
transport.stat('.bzr.backup/text-store/foo-20051004035756-4081373d897c3453.gz')
85
transport.stat('.bzr.backup/inventory-store/')
86
transport.stat('.bzr.backup/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
87
transport.stat('.bzr.backup/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
88
transport.stat('.bzr.backup/revision-store/')
89
transport.stat('.bzr.backup/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
90
transport.stat('.bzr.backup/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
52
eq(t.get_file_text(foo_id), 'initial contents\n')
53
t = b.revision_tree(rh[1])
54
eq(t.get_file_text(foo_id), 'new contents\n')
92
56
def test_upgrade_with_ghosts(self):
93
57
"""Upgrade v0.0.4 tree containing ghost references.
95
59
That is, some of the parents of revisions mentioned in the branch
96
aren't present in the branch's storage.
60
aren't present in the branches storage.
98
62
This shouldn't normally happen in branches created entirely in
99
bzr, but can happen in branches imported from baz and arch, or from
100
other systems, where the importer knows about a revision but not
63
bzr but can happen in imports from baz and arch, or from other
64
systems, where the importer knows about a revision but not
102
66
eq = self.assertEquals
103
self.build_tree_contents(_ghost_template)
105
b = Branch.open(u'.')
106
revision_id = b.revision_history()[1]
107
rev = b.repository.get_revision(revision_id)
108
eq(len(rev.parent_ids), 2)
109
eq(rev.parent_ids[1], 'wibble@wobble-2')
111
def test_upgrade_makes_dir_weaves(self):
112
self.build_tree_contents(_upgrade_dir_template)
113
old_repodir = bzrlib.bzrdir.BzrDir.open_unsupported('.')
114
old_repo_format = old_repodir.open_repository()._format
67
build_tree_contents(_ghost_template)
116
# this is the path to the literal file. As format changes
117
# occur it needs to be updated. FIXME: ask the store for the
119
repo = bzrlib.repository.Repository.open('.')
120
# it should have changed the format
121
self.assertNotEqual(old_repo_format.__class__, repo._format.__class__)
122
# and we should be able to read the names for the file id
123
# 'dir-20051005095101-da1441ea3fa6917a'
126
repo.text_store.get_weave(
127
'dir-20051005095101-da1441ea3fa6917a',
128
repo.get_transaction()))
130
def test_upgrade_to_meta_sets_workingtree_last_revision(self):
131
self.build_tree_contents(_upgrade_dir_template)
132
upgrade('.', bzrdir.BzrDirMetaFormat1())
133
tree = workingtree.WorkingTree.open('.')
134
self.assertEqual(tree.last_revision(),
135
tree.branch.revision_history()[-1])
138
73
_upgrade1_template = \
177
112
_ghost_template = [
183
'This is a Bazaar-NG control directory.\n'
184
'Do not change any files in this directory.\n'
186
( './.bzr/branch-format',
187
'Bazaar-NG branch, format 0.0.4\n'
189
( './.bzr/branch-lock',
192
( './.bzr/branch-name',
195
( './.bzr/inventory',
197
'<entry file_id="foo-20051004104918-0379cb7c76354cde" kind="file" name="foo" />\n'
200
( './.bzr/merged-patches',
203
( './.bzr/pending-merged-patches',
206
( './.bzr/pending-merges',
209
( './.bzr/revision-history',
210
'mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b\n'
211
'mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d\n'
213
( './.bzr/stat-cache',
214
'### bzr hashcache v5\n'
215
'foo// f572d396fae9206628714fb2ce00f72e94f2258f 6 1128422956 1128422956 306900 770\n'
217
( './.bzr/text-store/', ),
218
( './.bzr/text-store/foo-20051004104921-8de8118a71be45ba.gz',
219
'\x1f\x8b\x08\x081^BC\x00\x03foo-20051004104921-8de8118a71be45ba\x00\xcbH\xcd\xc9\xc9\xe7\x02\x00 0:6\x06\x00\x00\x00'
221
( './.bzr/inventory-store/', ),
222
( './.bzr/inventory-store/mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b.gz',
223
'\x1f\x8b\x08\x081^BC\x00\x03mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b\x00m\x8f\xcb\n'
224
'\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'
225
'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'
227
( './.bzr/inventory-store/mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d.gz',
228
'\x1f\x8b\x08\x08A^BC\x00\x03mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d\x00m\x8f\xcb\n'
229
'\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'
230
'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'
232
( './.bzr/revision-store/', ),
233
( './.bzr/revision-store/mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b.gz',
234
'\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'
235
'\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'
237
( './.bzr/revision-store/mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d.gz',
238
'\x1f\x8b\x08\x08A^BC\x00\x03mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d\x00\x9d\x90\xc1j\xc30\x0c\x86\xef}\n'
239
"\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"
240
'\x7fJ+EaM\x83$\xa5n\xbc/a\x91~\xd0\xbd\xfd\x135\n'
241
'\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'
245
_upgrade_dir_template = [
248
'This is a Bazaar-NG control directory.\n'
249
'Do not change any files in this directory.\n'
251
( './.bzr/branch-format',
252
'Bazaar-NG branch, format 0.0.4\n'
254
( './.bzr/branch-lock',
257
( './.bzr/branch-name',
260
( './.bzr/inventory',
262
'<entry file_id="dir-20051005095101-da1441ea3fa6917a" kind="directory" name="dir" />\n'
265
( './.bzr/merged-patches',
268
( './.bzr/pending-merged-patches',
271
( './.bzr/pending-merges',
274
( './.bzr/revision-history',
275
'robertc@robertcollins.net-20051005095108-6065fbd8e7d8617e\n'
277
( './.bzr/stat-cache',
278
'### bzr hashcache v5\n'
280
( './.bzr/text-store/', ),
281
( './.bzr/inventory-store/', ),
282
( './.bzr/inventory-store/robertc@robertcollins.net-20051005095108-6065fbd8e7d8617e.gz',
283
'\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'
284
"\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"
286
( './.bzr/revision-store/', ),
287
( './.bzr/revision-store/robertc@robertcollins.net-20051005095108-6065fbd8e7d8617e.gz',
288
'\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'
289
'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'
290
"+\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"
291
'\xcd\x17\x85\xea\xba\x03l\x01\x00\x00'
126
'This is a Bazaar-NG control directory.\n'
127
'Do not change any files in this directory.\n'
131
'./.bzr/branch-format'
133
'Bazaar-NG branch, format 0.0.4\n'
152
'<entry file_id="foo-20051004104918-0379cb7c76354cde" kind="file" name="foo" />\n'
157
'./.bzr/merged-patches'
163
'./.bzr/pending-merged-patches'
169
'./.bzr/pending-merges'
175
'./.bzr/revision-history'
177
'mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b\n'
178
'mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d\n'
184
'### bzr hashcache v5\n'
185
'foo// f572d396fae9206628714fb2ce00f72e94f2258f 6 1128422956 1128422956 306900 770\n'
193
'./.bzr/text-store/foo-20051004104921-8de8118a71be45ba'
199
'./.bzr/inventory-store/'
203
'./.bzr/inventory-store/mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b'
206
'<entry file_id="foo-20051004104918-0379cb7c76354cde" kind="file" name="foo" text_id="foo-20051004104921-8de8118a71be45ba" text_sha1="f572d396fae9206628714fb2ce00f72e94f2258f" text_size="6" />\n'
211
'./.bzr/inventory-store/mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d'
214
'<entry file_id="foo-20051004104918-0379cb7c76354cde" kind="file" name="foo" text_id="foo-20051004104921-8de8118a71be45ba" text_sha1="f572d396fae9206628714fb2ce00f72e94f2258f" text_size="6" />\n'
219
'./.bzr/revision-store/'
223
'./.bzr/revision-store/mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b'
225
'<revision committer="Martin Pool <mbp@sourcefrog.net>" inventory_id="mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b" inventory_sha1="b01abf9b0a0c61efa5deb5d89c06316b7bb98cd1" revision_id="mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b" timestamp="1128422961.704761982" timezone="36000">\n'
226
'<message>first</message>\n'
231
'./.bzr/revision-store/mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d'
233
'<revision committer="Martin Pool <mbp@sourcefrog.net>" inventory_id="mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d" inventory_sha1="b01abf9b0a0c61efa5deb5d89c06316b7bb98cd1" revision_id="mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d" timestamp="1128422977.211585045" timezone="36000">\n'
234
'<message>merge of ghost</message>\n'
236
'<revision_ref revision_id="mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b" revision_sha1="e860ba9f99b6c39e6f93ea7ffb2e0b82daa96ca6" />\n'
237
'<revision_ref revision_id="wibble@wobble-2" />\n'