~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_inv.py

  • Committer: Martin Pool
  • Date: 2006-01-30 06:23:50 UTC
  • mfrom: (1534.1.17 integration)
  • Revision ID: mbp@sourcefrog.net-20060130062350-d6f25277ddcdfd79
[merge] robert's integration of much recent work

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
 
20
20
from bzrlib.branch import Branch
21
 
from bzrlib.clone import copy_branch
22
21
import bzrlib.errors as errors
23
22
from bzrlib.diff import internal_diff
24
23
from bzrlib.inventory import Inventory, ROOT_ID
149
148
        if has_symlinks():
150
149
            os.unlink('symlink')
151
150
            os.symlink('target2', 'symlink')
152
 
        self.tree_1 = self.branch.revision_tree('1')
153
 
        self.inv_1 = self.branch.get_inventory('1')
 
151
        self.tree_1 = self.branch.repository.revision_tree('1')
 
152
        self.inv_1 = self.branch.repository.get_inventory('1')
154
153
        self.file_1 = self.inv_1['fileid']
155
154
        self.tree_2 = self.branch.working_tree()
156
155
        self.inv_2 = self.tree_2.read_working_inventory()
248
247
            pass
249
248
        self.wt = self.branch.working_tree()
250
249
        self.wt.commit('message_1', rev_id = '1')
251
 
        self.tree_1 = self.branch.revision_tree('1')
252
 
        self.inv_1 = self.branch.get_inventory('1')
 
250
        self.tree_1 = self.branch.repository.revision_tree('1')
 
251
        self.inv_1 = self.branch.repository.get_inventory('1')
253
252
        self.file_1 = self.inv_1['fileid']
254
253
        self.work_tree = self.branch.working_tree()
255
254
        self.file_active = self.work_tree.inventory['fileid']
258
257
        # This tests that a simple commit with no parents makes a new
259
258
        # revision value in the inventory entry
260
259
        self.file_active.snapshot('2', 'subdir/file', {}, self.work_tree, 
261
 
                                  self.branch.weave_store,
 
260
                                  self.branch.repository.weave_store,
262
261
                                  self.branch.get_transaction())
263
262
        # expected outcome - file_1 has a revision id of '2', and we can get
264
263
        # its text of 'file contents' out of the weave.
265
264
        self.assertEqual(self.file_1.revision, '1')
266
265
        self.assertEqual(self.file_active.revision, '2')
267
266
        # this should be a separate test probably, but lets check it once..
268
 
        lines = self.branch.weave_store.get_lines('fileid','2',
 
267
        lines = self.branch.repository.weave_store.get_lines('fileid','2',
269
268
            self.branch.get_transaction())
270
269
        self.assertEqual(lines, ['contents of subdir/file\n'])
271
270
 
273
272
        #This tests that a simple commit does not make a new entry for
274
273
        # an unchanged inventory entry
275
274
        self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
276
 
                                  self.work_tree, self.branch.weave_store,
 
275
                                  self.work_tree, 
 
276
                                  self.branch.repository.weave_store,
277
277
                                  self.branch.get_transaction())
278
278
        self.assertEqual(self.file_1.revision, '1')
279
279
        self.assertEqual(self.file_active.revision, '1')
280
280
        self.assertRaises(errors.WeaveError,
281
 
                          self.branch.weave_store.get_lines, 'fileid', '2',
282
 
                          self.branch.get_transaction())
 
281
                          self.branch.repository.weave_store.get_lines, 
 
282
                          'fileid', '2', self.branch.get_transaction())
283
283
 
284
284
    def test_snapshot_merge_identical_different_revid(self):
285
285
        # This tests that a commit with two identical parents, one of which has
293
293
        self.assertEqual(self.file_1, other_ie)
294
294
        other_ie.revision = 'other'
295
295
        self.assertNotEqual(self.file_1, other_ie)
296
 
        self.branch.weave_store.add_identical_text('fileid', '1', 'other', ['1'],
297
 
            self.branch.get_transaction())
 
296
        self.branch.repository.weave_store.add_identical_text('fileid', '1', 
 
297
            'other', ['1'], self.branch.get_transaction())
298
298
        self.file_active.snapshot('2', 'subdir/file', 
299
299
                                  {'1':self.file_1, 'other':other_ie},
300
 
                                  self.work_tree, self.branch.weave_store,
 
300
                                  self.work_tree, 
 
301
                                  self.branch.repository.weave_store,
301
302
                                  self.branch.get_transaction())
302
303
        self.assertEqual(self.file_active.revision, '2')
303
304
 
308
309
        rename('subdir/file', 'subdir/newname')
309
310
        self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1}, 
310
311
                                  self.work_tree, 
311
 
                                  self.branch.weave_store,
 
312
                                  self.branch.repository.weave_store,
312
313
                                  self.branch.get_transaction())
313
314
        # expected outcome - file_1 has a revision id of '2'
314
315
        self.assertEqual(self.file_active.revision, '2')
330
331
        self.branch = Branch.initialize(u'.')
331
332
        self.wt = self.branch.working_tree()
332
333
        self.wt.commit('new branch', allow_pointless=True, rev_id='A')
333
 
        self.inv_A = self.branch.get_inventory('A')
334
 
        self.branch.working_tree().add(['file'], ['fileid'])
 
334
        self.inv_A = self.branch.repository.get_inventory('A')
 
335
        self.wt.add(['file'], ['fileid'])
335
336
        self.wt.commit('add file', rev_id='B')
336
 
        self.inv_B = self.branch.get_inventory('B')
337
 
        self.branch.put_controlfile('revision-history', 'A\n')
 
337
        self.inv_B = self.branch.repository.get_inventory('B')
 
338
        self.branch.lock_write()
 
339
        try:
 
340
            self.branch.control_files.put_utf8('revision-history', 'A\n')
 
341
        finally:
 
342
            self.branch.unlock()
338
343
        self.assertEqual(self.branch.revision_history(), ['A'])
339
344
        self.wt.commit('another add of file', rev_id='C')
340
 
        self.inv_C = self.branch.get_inventory('C')
 
345
        self.inv_C = self.branch.repository.get_inventory('C')
341
346
        self.wt.add_pending_merge('B')
342
347
        self.wt.commit('merge in B', rev_id='D')
343
 
        self.inv_D = self.branch.get_inventory('D')
344
 
        self.file_active = self.wt.inventory['fileid']
345
 
        self.weave = self.branch.weave_store.get_weave('fileid',
 
348
        self.inv_D = self.branch.repository.get_inventory('D')
 
349
        self.file_active = self.branch.working_tree().inventory['fileid']
 
350
        self.weave = self.branch.repository.weave_store.get_weave('fileid',
346
351
            self.branch.get_transaction())
347
352
        
348
353
    def get_previous_heads(self, inventories):
404
409
 
405
410
        t.commit('adding a,b', rev_id='r1')
406
411
 
407
 
        rev_tree = b.revision_tree('r1')
 
412
        rev_tree = b.repository.revision_tree('r1')
408
413
        self.failUnless(rev_tree.is_executable(a_id), "'a' lost the execute bit")
409
414
        self.failIf(rev_tree.is_executable(b_id), "'b' gained an execute bit")
410
415
 
422
427
        # Make sure that revert is able to bring them back,
423
428
        # and sets 'a' back to being executable
424
429
 
425
 
        t.revert(['b1/a', 'b1/b'], rev_tree, backups=False)
 
430
        t.revert(['a', 'b'], rev_tree, backups=False)
426
431
        self.assertEqual(['a', 'b'], [cn for cn,ie in t.inventory.iter_entries()])
427
432
 
428
433
        self.failUnless(t.is_executable(a_id), "'a' lost the execute bit")
458
463
        # Now make sure that 'bzr branch' also preserves the
459
464
        # executable bit
460
465
        # TODO: Maybe this should be a blackbox test
461
 
        from bzrlib.clone import copy_branch
462
 
        copy_branch(b, 'b2', revision='r1')
 
466
        b.clone('b2', revision='r1')
463
467
        b2 = Branch.open('b2')
464
468
        self.assertEquals('r1', b2.last_revision())
465
469
        t2 = b2.working_tree()