130
128
self.assertIs(self.wt.is_executable('my_pretties2'), False)
131
129
self.assertEqual('directory', file_kind(self.wt.abspath('oz')))
132
130
self.assertEqual(len(modified_paths), 3)
133
tree_mod_paths = [self.wt.id2abspath(f) for f in
131
tree_mod_paths = [self.wt.id2abspath(f) for f in
134
132
('ozzie', 'my_pretties', 'my_pretties2')]
135
133
self.assertSubset(tree_mod_paths, modified_paths)
136
134
# is it safe to finalize repeatedly?
137
135
transform.finalize()
138
136
transform.finalize()
140
def test_create_files_same_timestamp(self):
141
transform, root = self.get_transform()
142
self.wt.lock_tree_write()
143
self.addCleanup(self.wt.unlock)
144
# Roll back the clock, so that we know everything is being set to the
146
transform._creation_mtime = creation_mtime = time.time() - 20.0
147
transform.create_file('content-one',
148
transform.create_path('one', root))
149
time.sleep(1) # *ugly*
150
transform.create_file('content-two',
151
transform.create_path('two', root))
153
fo, st1 = self.wt.get_file_with_stat(None, path='one', filtered=False)
155
fo, st2 = self.wt.get_file_with_stat(None, path='two', filtered=False)
157
# We only guarantee 2s resolution
158
self.assertTrue(abs(creation_mtime - st1.st_mtime) < 2.0,
159
"%s != %s within 2 seconds" % (creation_mtime, st1.st_mtime))
160
# But if we have more than that, all files should get the same result
161
self.assertEqual(st1.st_mtime, st2.st_mtime)
163
def test_change_root_id(self):
164
transform, root = self.get_transform()
165
self.assertNotEqual('new-root-id', self.wt.get_root_id())
166
transform.new_directory('', ROOT_PARENT, 'new-root-id')
167
transform.delete_contents(root)
168
transform.unversion_file(root)
169
transform.fixup_new_roots()
171
self.assertEqual('new-root-id', self.wt.get_root_id())
173
def test_change_root_id_add_files(self):
174
transform, root = self.get_transform()
175
self.assertNotEqual('new-root-id', self.wt.get_root_id())
176
new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
177
transform.new_file('file', new_trans_id, ['new-contents\n'],
179
transform.delete_contents(root)
180
transform.unversion_file(root)
181
transform.fixup_new_roots()
183
self.assertEqual('new-root-id', self.wt.get_root_id())
184
self.assertEqual('new-file-id', self.wt.path2id('file'))
185
self.assertFileEqual('new-contents\n', self.wt.abspath('file'))
187
def test_add_two_roots(self):
188
transform, root = self.get_transform()
189
new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
190
new_trans_id = transform.new_directory('', ROOT_PARENT, 'alt-root-id')
191
self.assertRaises(ValueError, transform.fixup_new_roots)
193
138
def test_hardlink(self):
194
139
self.requireFeature(HardlinkFeature)
195
140
transform, root = self.get_transform()
244
189
def test_conflicts(self):
245
190
transform, root = self.get_transform()
246
trans_id = transform.new_file('name', root, 'contents',
191
trans_id = transform.new_file('name', root, 'contents',
248
193
self.assertEqual(len(transform.find_conflicts()), 0)
249
194
trans_id2 = transform.new_file('name', root, 'Crontents', 'toto')
250
self.assertEqual(transform.find_conflicts(),
195
self.assertEqual(transform.find_conflicts(),
251
196
[('duplicate', trans_id, trans_id2, 'name')])
252
197
self.assertRaises(MalformedTransform, transform.apply)
253
198
transform.adjust_path('name', trans_id, trans_id2)
254
self.assertEqual(transform.find_conflicts(),
199
self.assertEqual(transform.find_conflicts(),
255
200
[('non-directory parent', trans_id)])
256
201
tinman_id = transform.trans_id_tree_path('tinman')
257
202
transform.adjust_path('name', tinman_id, trans_id2)
258
self.assertEqual(transform.find_conflicts(),
259
[('unversioned parent', tinman_id),
203
self.assertEqual(transform.find_conflicts(),
204
[('unversioned parent', tinman_id),
260
205
('missing parent', tinman_id)])
261
206
lion_id = transform.create_path('lion', root)
262
self.assertEqual(transform.find_conflicts(),
263
[('unversioned parent', tinman_id),
207
self.assertEqual(transform.find_conflicts(),
208
[('unversioned parent', tinman_id),
264
209
('missing parent', tinman_id)])
265
210
transform.adjust_path('name', lion_id, trans_id2)
266
self.assertEqual(transform.find_conflicts(),
211
self.assertEqual(transform.find_conflicts(),
267
212
[('unversioned parent', lion_id),
268
213
('missing parent', lion_id)])
269
214
transform.version_file("Courage", lion_id)
270
self.assertEqual(transform.find_conflicts(),
271
[('missing parent', lion_id),
215
self.assertEqual(transform.find_conflicts(),
216
[('missing parent', lion_id),
272
217
('versioning no contents', lion_id)])
273
218
transform.adjust_path('name2', root, trans_id2)
274
self.assertEqual(transform.find_conflicts(),
219
self.assertEqual(transform.find_conflicts(),
275
220
[('versioning no contents', lion_id)])
276
221
transform.create_file('Contents, okay?', lion_id)
277
222
transform.adjust_path('name2', trans_id2, trans_id2)
278
self.assertEqual(transform.find_conflicts(),
279
[('parent loop', trans_id2),
223
self.assertEqual(transform.find_conflicts(),
224
[('parent loop', trans_id2),
280
225
('non-directory parent', trans_id2)])
281
226
transform.adjust_path('name2', root, trans_id2)
282
227
oz_id = transform.new_directory('oz', root)
283
228
transform.set_executability(True, oz_id)
284
self.assertEqual(transform.find_conflicts(),
229
self.assertEqual(transform.find_conflicts(),
285
230
[('unversioned executability', oz_id)])
286
231
transform.version_file('oz-id', oz_id)
287
self.assertEqual(transform.find_conflicts(),
232
self.assertEqual(transform.find_conflicts(),
288
233
[('non-file executability', oz_id)])
289
234
transform.set_executability(None, oz_id)
290
235
tip_id = transform.new_file('tip', oz_id, 'ozma', 'tip-id')
1320
1229
tt.version_file("bar-1", bar_trans_id)
1322
1231
self.failUnlessExists("foo/bar")
1325
self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1330
changes = wt.changes_from(wt.basis_tree())
1331
self.assertFalse(changes.has_changed(), changes)
1333
def test_file_to_symlink(self):
1334
self.requireFeature(SymlinkFeature)
1335
wt = self.make_branch_and_tree('.')
1336
self.build_tree(['foo'])
1339
tt = TreeTransform(wt)
1340
self.addCleanup(tt.finalize)
1341
foo_trans_id = tt.trans_id_tree_path("foo")
1342
tt.delete_contents(foo_trans_id)
1343
tt.create_symlink("bar", foo_trans_id)
1345
self.failUnlessExists("foo")
1347
self.addCleanup(wt.unlock)
1348
self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1351
def test_dir_to_file(self):
1352
wt = self.make_branch_and_tree('.')
1353
self.build_tree(['foo/', 'foo/bar'])
1354
wt.add(['foo', 'foo/bar'])
1356
tt = TreeTransform(wt)
1357
self.addCleanup(tt.finalize)
1358
foo_trans_id = tt.trans_id_tree_path("foo")
1359
bar_trans_id = tt.trans_id_tree_path("foo/bar")
1360
tt.delete_contents(foo_trans_id)
1361
tt.delete_versioned(bar_trans_id)
1362
tt.create_file(["aa\n"], foo_trans_id)
1364
self.failUnlessExists("foo")
1366
self.addCleanup(wt.unlock)
1367
self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1370
def test_dir_to_hardlink(self):
1371
self.requireFeature(HardlinkFeature)
1372
wt = self.make_branch_and_tree('.')
1373
self.build_tree(['foo/', 'foo/bar'])
1374
wt.add(['foo', 'foo/bar'])
1376
tt = TreeTransform(wt)
1377
self.addCleanup(tt.finalize)
1378
foo_trans_id = tt.trans_id_tree_path("foo")
1379
bar_trans_id = tt.trans_id_tree_path("foo/bar")
1380
tt.delete_contents(foo_trans_id)
1381
tt.delete_versioned(bar_trans_id)
1382
self.build_tree(['baz'])
1383
tt.create_hardlink("baz", foo_trans_id)
1385
self.failUnlessExists("foo")
1386
self.failUnlessExists("baz")
1388
self.addCleanup(wt.unlock)
1389
self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1392
def test_no_final_path(self):
1393
transform, root = self.get_transform()
1394
trans_id = transform.trans_id_file_id('foo')
1395
transform.create_file('bar', trans_id)
1396
transform.cancel_creation(trans_id)
1399
def test_create_from_tree(self):
1400
tree1 = self.make_branch_and_tree('tree1')
1401
self.build_tree_contents([('tree1/foo/',), ('tree1/bar', 'baz')])
1402
tree1.add(['foo', 'bar'], ['foo-id', 'bar-id'])
1403
tree2 = self.make_branch_and_tree('tree2')
1404
tt = TreeTransform(tree2)
1405
foo_trans_id = tt.create_path('foo', tt.root)
1406
create_from_tree(tt, foo_trans_id, tree1, 'foo-id')
1407
bar_trans_id = tt.create_path('bar', tt.root)
1408
create_from_tree(tt, bar_trans_id, tree1, 'bar-id')
1410
self.assertEqual('directory', osutils.file_kind('tree2/foo'))
1411
self.assertFileEqual('baz', 'tree2/bar')
1413
def test_create_from_tree_bytes(self):
1414
"""Provided lines are used instead of tree content."""
1415
tree1 = self.make_branch_and_tree('tree1')
1416
self.build_tree_contents([('tree1/foo', 'bar'),])
1417
tree1.add('foo', 'foo-id')
1418
tree2 = self.make_branch_and_tree('tree2')
1419
tt = TreeTransform(tree2)
1420
foo_trans_id = tt.create_path('foo', tt.root)
1421
create_from_tree(tt, foo_trans_id, tree1, 'foo-id', bytes='qux')
1423
self.assertFileEqual('qux', 'tree2/foo')
1425
def test_create_from_tree_symlink(self):
1426
self.requireFeature(SymlinkFeature)
1427
tree1 = self.make_branch_and_tree('tree1')
1428
os.symlink('bar', 'tree1/foo')
1429
tree1.add('foo', 'foo-id')
1430
tt = TreeTransform(self.make_branch_and_tree('tree2'))
1431
foo_trans_id = tt.create_path('foo', tt.root)
1432
create_from_tree(tt, foo_trans_id, tree1, 'foo-id')
1434
self.assertEqual('bar', os.readlink('tree2/foo'))
1437
1234
class TransformGroup(object):
1982
1733
self.assertEqual('FILE', target.id2path('upper-id'))
1985
class TestCommitTransform(tests.TestCaseWithTransport):
1987
def get_branch(self):
1988
tree = self.make_branch_and_tree('tree')
1990
self.addCleanup(tree.unlock)
1991
tree.commit('empty commit')
1994
def get_branch_and_transform(self):
1995
branch = self.get_branch()
1996
tt = TransformPreview(branch.basis_tree())
1997
self.addCleanup(tt.finalize)
2000
def test_commit_wrong_basis(self):
2001
branch = self.get_branch()
2002
basis = branch.repository.revision_tree(
2003
_mod_revision.NULL_REVISION)
2004
tt = TransformPreview(basis)
2005
self.addCleanup(tt.finalize)
2006
e = self.assertRaises(ValueError, tt.commit, branch, '')
2007
self.assertEqual('TreeTransform not based on branch basis: null:',
2010
def test_empy_commit(self):
2011
branch, tt = self.get_branch_and_transform()
2012
rev = tt.commit(branch, 'my message')
2013
self.assertEqual(2, branch.revno())
2014
repo = branch.repository
2015
self.assertEqual('my message', repo.get_revision(rev).message)
2017
def test_merge_parents(self):
2018
branch, tt = self.get_branch_and_transform()
2019
rev = tt.commit(branch, 'my message', ['rev1b', 'rev1c'])
2020
self.assertEqual(['rev1b', 'rev1c'],
2021
branch.basis_tree().get_parent_ids()[1:])
2023
def test_first_commit(self):
2024
branch = self.make_branch('branch')
2026
self.addCleanup(branch.unlock)
2027
tt = TransformPreview(branch.basis_tree())
2028
self.addCleanup(tt.finalize)
2029
tt.new_directory('', ROOT_PARENT, 'TREE_ROOT')
2030
rev = tt.commit(branch, 'my message')
2031
self.assertEqual([], branch.basis_tree().get_parent_ids())
2032
self.assertNotEqual(_mod_revision.NULL_REVISION,
2033
branch.last_revision())
2035
def test_first_commit_with_merge_parents(self):
2036
branch = self.make_branch('branch')
2038
self.addCleanup(branch.unlock)
2039
tt = TransformPreview(branch.basis_tree())
2040
self.addCleanup(tt.finalize)
2041
e = self.assertRaises(ValueError, tt.commit, branch,
2042
'my message', ['rev1b-id'])
2043
self.assertEqual('Cannot supply merge parents for first commit.',
2045
self.assertEqual(_mod_revision.NULL_REVISION, branch.last_revision())
2047
def test_add_files(self):
2048
branch, tt = self.get_branch_and_transform()
2049
tt.new_file('file', tt.root, 'contents', 'file-id')
2050
trans_id = tt.new_directory('dir', tt.root, 'dir-id')
2051
if SymlinkFeature.available():
2052
tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
2053
rev = tt.commit(branch, 'message')
2054
tree = branch.basis_tree()
2055
self.assertEqual('file', tree.id2path('file-id'))
2056
self.assertEqual('contents', tree.get_file_text('file-id'))
2057
self.assertEqual('dir', tree.id2path('dir-id'))
2058
if SymlinkFeature.available():
2059
self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
2060
self.assertEqual('target', tree.get_symlink_target('symlink-id'))
2062
def test_add_unversioned(self):
2063
branch, tt = self.get_branch_and_transform()
2064
tt.new_file('file', tt.root, 'contents')
2065
self.assertRaises(errors.StrictCommitFailed, tt.commit, branch,
2066
'message', strict=True)
2068
def test_modify_strict(self):
2069
branch, tt = self.get_branch_and_transform()
2070
tt.new_file('file', tt.root, 'contents', 'file-id')
2071
tt.commit(branch, 'message', strict=True)
2072
tt = TransformPreview(branch.basis_tree())
2073
self.addCleanup(tt.finalize)
2074
trans_id = tt.trans_id_file_id('file-id')
2075
tt.delete_contents(trans_id)
2076
tt.create_file('contents', trans_id)
2077
tt.commit(branch, 'message', strict=True)
2079
def test_commit_malformed(self):
2080
"""Committing a malformed transform should raise an exception.
2082
In this case, we are adding a file without adding its parent.
2084
branch, tt = self.get_branch_and_transform()
2085
parent_id = tt.trans_id_file_id('parent-id')
2086
tt.new_file('file', parent_id, 'contents', 'file-id')
2087
self.assertRaises(errors.MalformedTransform, tt.commit, branch,
2091
1736
class MockTransform(object):
2093
1738
def has_named_child(self, by_parent, parent_id, name):
2730
2366
('new-a', 'e\n'),
2731
2367
('new-b', 'f\n'),
2732
2368
], list(tree_a.plan_file_merge('file-id', tree_b)))
2734
def test_walkdirs(self):
2735
preview = self.get_empty_preview()
2736
root = preview.new_directory('', ROOT_PARENT, 'tree-root')
2737
# FIXME: new_directory should mark root.
2738
preview.fixup_new_roots()
2739
preview_tree = preview.get_preview_tree()
2740
file_trans_id = preview.new_file('a', preview.root, 'contents',
2742
expected = [(('', 'tree-root'),
2743
[('a', 'a', 'file', None, 'a-id', 'file')])]
2744
self.assertEqual(expected, list(preview_tree.walkdirs()))
2746
def test_extras(self):
2747
work_tree = self.make_branch_and_tree('tree')
2748
self.build_tree(['tree/removed-file', 'tree/existing-file',
2749
'tree/not-removed-file'])
2750
work_tree.add(['removed-file', 'not-removed-file'])
2751
preview = TransformPreview(work_tree)
2752
self.addCleanup(preview.finalize)
2753
preview.new_file('new-file', preview.root, 'contents')
2754
preview.new_file('new-versioned-file', preview.root, 'contents',
2756
tree = preview.get_preview_tree()
2757
preview.unversion_file(preview.trans_id_tree_path('removed-file'))
2758
self.assertEqual(set(['new-file', 'removed-file', 'existing-file']),
2761
def test_merge_into_preview(self):
2762
work_tree = self.make_branch_and_tree('tree')
2763
self.build_tree_contents([('tree/file','b\n')])
2764
work_tree.add('file', 'file-id')
2765
work_tree.commit('first commit')
2766
child_tree = work_tree.bzrdir.sprout('child').open_workingtree()
2767
self.build_tree_contents([('child/file','b\nc\n')])
2768
child_tree.commit('child commit')
2769
child_tree.lock_write()
2770
self.addCleanup(child_tree.unlock)
2771
work_tree.lock_write()
2772
self.addCleanup(work_tree.unlock)
2773
preview = TransformPreview(work_tree)
2774
self.addCleanup(preview.finalize)
2775
file_trans_id = preview.trans_id_file_id('file-id')
2776
preview.delete_contents(file_trans_id)
2777
preview.create_file('a\nb\n', file_trans_id)
2778
pb = progress.DummyProgress()
2779
preview_tree = preview.get_preview_tree()
2780
merger = Merger.from_revision_ids(pb, preview_tree,
2781
child_tree.branch.last_revision(),
2782
other_branch=child_tree.branch,
2783
tree_branch=work_tree.branch)
2784
merger.merge_type = Merge3Merger
2785
tt = merger.make_merger().make_preview_transform()
2786
self.addCleanup(tt.finalize)
2787
final_tree = tt.get_preview_tree()
2788
self.assertEqual('a\nb\nc\n', final_tree.get_file_text('file-id'))
2790
def test_merge_preview_into_workingtree(self):
2791
tree = self.make_branch_and_tree('tree')
2792
tree.set_root_id('TREE_ROOT')
2793
tt = TransformPreview(tree)
2794
self.addCleanup(tt.finalize)
2795
tt.new_file('name', tt.root, 'content', 'file-id')
2796
tree2 = self.make_branch_and_tree('tree2')
2797
tree2.set_root_id('TREE_ROOT')
2798
pb = progress.DummyProgress()
2799
merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2800
pb, tree.basis_tree())
2801
merger.merge_type = Merge3Merger
2804
def test_merge_preview_into_workingtree_handles_conflicts(self):
2805
tree = self.make_branch_and_tree('tree')
2806
self.build_tree_contents([('tree/foo', 'bar')])
2807
tree.add('foo', 'foo-id')
2809
tt = TransformPreview(tree)
2810
self.addCleanup(tt.finalize)
2811
trans_id = tt.trans_id_file_id('foo-id')
2812
tt.delete_contents(trans_id)
2813
tt.create_file('baz', trans_id)
2814
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
2815
self.build_tree_contents([('tree2/foo', 'qux')])
2816
pb = progress.DummyProgress()
2817
merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2818
pb, tree.basis_tree())
2819
merger.merge_type = Merge3Merger
2822
def test_is_executable(self):
2823
tree = self.make_branch_and_tree('tree')
2824
preview = TransformPreview(tree)
2825
self.addCleanup(preview.finalize)
2826
preview.new_file('foo', preview.root, 'bar', 'baz-id')
2827
preview_tree = preview.get_preview_tree()
2828
self.assertEqual(False, preview_tree.is_executable('baz-id',
2830
self.assertEqual(False, preview_tree.is_executable('baz-id'))
2832
def test_commit_preview_tree(self):
2833
tree = self.make_branch_and_tree('tree')
2834
rev_id = tree.commit('rev1')
2835
tree.branch.lock_write()
2836
self.addCleanup(tree.branch.unlock)
2837
tt = TransformPreview(tree)
2838
tt.new_file('file', tt.root, 'contents', 'file_id')
2839
self.addCleanup(tt.finalize)
2840
preview = tt.get_preview_tree()
2841
preview.set_parent_ids([rev_id])
2842
builder = tree.branch.get_commit_builder([rev_id])
2843
list(builder.record_iter_changes(preview, rev_id, tt.iter_changes()))
2844
builder.finish_inventory()
2845
rev2_id = builder.commit('rev2')
2846
rev2_tree = tree.branch.repository.revision_tree(rev2_id)
2847
self.assertEqual('contents', rev2_tree.get_file_text('file_id'))
2849
def test_ascii_limbo_paths(self):
2850
self.requireFeature(tests.UnicodeFilenameFeature)
2851
branch = self.make_branch('any')
2852
tree = branch.repository.revision_tree(_mod_revision.NULL_REVISION)
2853
tt = TransformPreview(tree)
2854
self.addCleanup(tt.finalize)
2855
foo_id = tt.new_directory('', ROOT_PARENT)
2856
bar_id = tt.new_file(u'\u1234bar', foo_id, 'contents')
2857
limbo_path = tt._limbo_name(bar_id)
2858
self.assertEqual(limbo_path.encode('ascii', 'replace'), limbo_path)
2861
class FakeSerializer(object):
2862
"""Serializer implementation that simply returns the input.
2864
The input is returned in the order used by pack.ContainerPushParser.
2867
def bytes_record(bytes, names):
2871
class TestSerializeTransform(tests.TestCaseWithTransport):
2873
_test_needs_features = [tests.UnicodeFilenameFeature]
2875
def get_preview(self, tree=None):
2877
tree = self.make_branch_and_tree('tree')
2878
tt = TransformPreview(tree)
2879
self.addCleanup(tt.finalize)
2882
def assertSerializesTo(self, expected, tt):
2883
records = list(tt.serialize(FakeSerializer()))
2884
self.assertEqual(expected, records)
2887
def default_attribs():
2892
'_new_executability': {},
2894
'_tree_path_ids': {'': 'new-0'},
2896
'_removed_contents': [],
2897
'_non_present_ids': {},
2900
def make_records(self, attribs, contents):
2902
(((('attribs'),),), bencode.bencode(attribs))]
2903
records.extend([(((n, k),), c) for n, k, c in contents])
2906
def creation_records(self):
2907
attribs = self.default_attribs()
2908
attribs['_id_number'] = 3
2909
attribs['_new_name'] = {
2910
'new-1': u'foo\u1234'.encode('utf-8'), 'new-2': 'qux'}
2911
attribs['_new_id'] = {'new-1': 'baz', 'new-2': 'quxx'}
2912
attribs['_new_parent'] = {'new-1': 'new-0', 'new-2': 'new-0'}
2913
attribs['_new_executability'] = {'new-1': 1}
2915
('new-1', 'file', 'i 1\nbar\n'),
2916
('new-2', 'directory', ''),
2918
return self.make_records(attribs, contents)
2920
def test_serialize_creation(self):
2921
tt = self.get_preview()
2922
tt.new_file(u'foo\u1234', tt.root, 'bar', 'baz', True)
2923
tt.new_directory('qux', tt.root, 'quxx')
2924
self.assertSerializesTo(self.creation_records(), tt)
2926
def test_deserialize_creation(self):
2927
tt = self.get_preview()
2928
tt.deserialize(iter(self.creation_records()))
2929
self.assertEqual(3, tt._id_number)
2930
self.assertEqual({'new-1': u'foo\u1234',
2931
'new-2': 'qux'}, tt._new_name)
2932
self.assertEqual({'new-1': 'baz', 'new-2': 'quxx'}, tt._new_id)
2933
self.assertEqual({'new-1': tt.root, 'new-2': tt.root}, tt._new_parent)
2934
self.assertEqual({'baz': 'new-1', 'quxx': 'new-2'}, tt._r_new_id)
2935
self.assertEqual({'new-1': True}, tt._new_executability)
2936
self.assertEqual({'new-1': 'file',
2937
'new-2': 'directory'}, tt._new_contents)
2938
foo_limbo = open(tt._limbo_name('new-1'), 'rb')
2940
foo_content = foo_limbo.read()
2943
self.assertEqual('bar', foo_content)
2945
def symlink_creation_records(self):
2946
attribs = self.default_attribs()
2947
attribs['_id_number'] = 2
2948
attribs['_new_name'] = {'new-1': u'foo\u1234'.encode('utf-8')}
2949
attribs['_new_parent'] = {'new-1': 'new-0'}
2950
contents = [('new-1', 'symlink', u'bar\u1234'.encode('utf-8'))]
2951
return self.make_records(attribs, contents)
2953
def test_serialize_symlink_creation(self):
2954
self.requireFeature(tests.SymlinkFeature)
2955
tt = self.get_preview()
2956
tt.new_symlink(u'foo\u1234', tt.root, u'bar\u1234')
2957
self.assertSerializesTo(self.symlink_creation_records(), tt)
2959
def test_deserialize_symlink_creation(self):
2960
self.requireFeature(tests.SymlinkFeature)
2961
tt = self.get_preview()
2962
tt.deserialize(iter(self.symlink_creation_records()))
2963
abspath = tt._limbo_name('new-1')
2964
foo_content = osutils.readlink(abspath)
2965
self.assertEqual(u'bar\u1234', foo_content)
2967
def make_destruction_preview(self):
2968
tree = self.make_branch_and_tree('.')
2969
self.build_tree([u'foo\u1234', 'bar'])
2970
tree.add([u'foo\u1234', 'bar'], ['foo-id', 'bar-id'])
2971
return self.get_preview(tree)
2973
def destruction_records(self):
2974
attribs = self.default_attribs()
2975
attribs['_id_number'] = 3
2976
attribs['_removed_id'] = ['new-1']
2977
attribs['_removed_contents'] = ['new-2']
2978
attribs['_tree_path_ids'] = {
2980
u'foo\u1234'.encode('utf-8'): 'new-1',
2983
return self.make_records(attribs, [])
2985
def test_serialize_destruction(self):
2986
tt = self.make_destruction_preview()
2987
foo_trans_id = tt.trans_id_tree_file_id('foo-id')
2988
tt.unversion_file(foo_trans_id)
2989
bar_trans_id = tt.trans_id_tree_file_id('bar-id')
2990
tt.delete_contents(bar_trans_id)
2991
self.assertSerializesTo(self.destruction_records(), tt)
2993
def test_deserialize_destruction(self):
2994
tt = self.make_destruction_preview()
2995
tt.deserialize(iter(self.destruction_records()))
2996
self.assertEqual({u'foo\u1234': 'new-1',
2998
'': tt.root}, tt._tree_path_ids)
2999
self.assertEqual({'new-1': u'foo\u1234',
3001
tt.root: ''}, tt._tree_id_paths)
3002
self.assertEqual(set(['new-1']), tt._removed_id)
3003
self.assertEqual(set(['new-2']), tt._removed_contents)
3005
def missing_records(self):
3006
attribs = self.default_attribs()
3007
attribs['_id_number'] = 2
3008
attribs['_non_present_ids'] = {
3010
return self.make_records(attribs, [])
3012
def test_serialize_missing(self):
3013
tt = self.get_preview()
3014
boo_trans_id = tt.trans_id_file_id('boo')
3015
self.assertSerializesTo(self.missing_records(), tt)
3017
def test_deserialize_missing(self):
3018
tt = self.get_preview()
3019
tt.deserialize(iter(self.missing_records()))
3020
self.assertEqual({'boo': 'new-1'}, tt._non_present_ids)
3022
def make_modification_preview(self):
3023
LINES_ONE = 'aa\nbb\ncc\ndd\n'
3024
LINES_TWO = 'z\nbb\nx\ndd\n'
3025
tree = self.make_branch_and_tree('tree')
3026
self.build_tree_contents([('tree/file', LINES_ONE)])
3027
tree.add('file', 'file-id')
3028
return self.get_preview(tree), LINES_TWO
3030
def modification_records(self):
3031
attribs = self.default_attribs()
3032
attribs['_id_number'] = 2
3033
attribs['_tree_path_ids'] = {
3036
attribs['_removed_contents'] = ['new-1']
3037
contents = [('new-1', 'file',
3038
'i 1\nz\n\nc 0 1 1 1\ni 1\nx\n\nc 0 3 3 1\n')]
3039
return self.make_records(attribs, contents)
3041
def test_serialize_modification(self):
3042
tt, LINES = self.make_modification_preview()
3043
trans_id = tt.trans_id_file_id('file-id')
3044
tt.delete_contents(trans_id)
3045
tt.create_file(LINES, trans_id)
3046
self.assertSerializesTo(self.modification_records(), tt)
3048
def test_deserialize_modification(self):
3049
tt, LINES = self.make_modification_preview()
3050
tt.deserialize(iter(self.modification_records()))
3051
self.assertFileEqual(LINES, tt._limbo_name('new-1'))
3053
def make_kind_change_preview(self):
3054
LINES = 'a\nb\nc\nd\n'
3055
tree = self.make_branch_and_tree('tree')
3056
self.build_tree(['tree/foo/'])
3057
tree.add('foo', 'foo-id')
3058
return self.get_preview(tree), LINES
3060
def kind_change_records(self):
3061
attribs = self.default_attribs()
3062
attribs['_id_number'] = 2
3063
attribs['_tree_path_ids'] = {
3066
attribs['_removed_contents'] = ['new-1']
3067
contents = [('new-1', 'file',
3068
'i 4\na\nb\nc\nd\n\n')]
3069
return self.make_records(attribs, contents)
3071
def test_serialize_kind_change(self):
3072
tt, LINES = self.make_kind_change_preview()
3073
trans_id = tt.trans_id_file_id('foo-id')
3074
tt.delete_contents(trans_id)
3075
tt.create_file(LINES, trans_id)
3076
self.assertSerializesTo(self.kind_change_records(), tt)
3078
def test_deserialize_kind_change(self):
3079
tt, LINES = self.make_kind_change_preview()
3080
tt.deserialize(iter(self.kind_change_records()))
3081
self.assertFileEqual(LINES, tt._limbo_name('new-1'))
3083
def make_add_contents_preview(self):
3084
LINES = 'a\nb\nc\nd\n'
3085
tree = self.make_branch_and_tree('tree')
3086
self.build_tree(['tree/foo'])
3088
os.unlink('tree/foo')
3089
return self.get_preview(tree), LINES
3091
def add_contents_records(self):
3092
attribs = self.default_attribs()
3093
attribs['_id_number'] = 2
3094
attribs['_tree_path_ids'] = {
3097
contents = [('new-1', 'file',
3098
'i 4\na\nb\nc\nd\n\n')]
3099
return self.make_records(attribs, contents)
3101
def test_serialize_add_contents(self):
3102
tt, LINES = self.make_add_contents_preview()
3103
trans_id = tt.trans_id_tree_path('foo')
3104
tt.create_file(LINES, trans_id)
3105
self.assertSerializesTo(self.add_contents_records(), tt)
3107
def test_deserialize_add_contents(self):
3108
tt, LINES = self.make_add_contents_preview()
3109
tt.deserialize(iter(self.add_contents_records()))
3110
self.assertFileEqual(LINES, tt._limbo_name('new-1'))
3112
def test_get_parents_lines(self):
3113
LINES_ONE = 'aa\nbb\ncc\ndd\n'
3114
LINES_TWO = 'z\nbb\nx\ndd\n'
3115
tree = self.make_branch_and_tree('tree')
3116
self.build_tree_contents([('tree/file', LINES_ONE)])
3117
tree.add('file', 'file-id')
3118
tt = self.get_preview(tree)
3119
trans_id = tt.trans_id_tree_path('file')
3120
self.assertEqual((['aa\n', 'bb\n', 'cc\n', 'dd\n'],),
3121
tt._get_parents_lines(trans_id))
3123
def test_get_parents_texts(self):
3124
LINES_ONE = 'aa\nbb\ncc\ndd\n'
3125
LINES_TWO = 'z\nbb\nx\ndd\n'
3126
tree = self.make_branch_and_tree('tree')
3127
self.build_tree_contents([('tree/file', LINES_ONE)])
3128
tree.add('file', 'file-id')
3129
tt = self.get_preview(tree)
3130
trans_id = tt.trans_id_tree_path('file')
3131
self.assertEqual((LINES_ONE,),
3132
tt._get_parents_texts(trans_id))