~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_parents.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests of the parent related functions of WorkingTrees."""
18
18
 
19
 
from cStringIO import StringIO
 
19
from errno import EEXIST
20
20
import os
21
21
 
22
22
from bzrlib import (
23
23
    errors,
 
24
    osutils,
24
25
    revision as _mod_revision,
 
26
    symbol_versioning,
 
27
    tests,
25
28
    )
26
29
from bzrlib.inventory import (
27
30
    Inventory,
29
32
    InventoryDirectory,
30
33
    InventoryLink,
31
34
    )
32
 
from bzrlib.revisiontree import InventoryRevisionTree
 
35
from bzrlib.revision import Revision
33
36
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
34
 
from bzrlib.tests import (
35
 
    features,
36
 
    )
37
37
from bzrlib.uncommit import uncommit
38
38
 
39
39
 
229
229
 
230
230
    def test_unicode_symlink(self):
231
231
        # this tests bug #272444
232
 
        self.requireFeature(features.SymlinkFeature)
233
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
232
        self.requireFeature(tests.SymlinkFeature)
 
233
        self.requireFeature(tests.UnicodeFilenameFeature)
234
234
 
235
235
        tree = self.make_branch_and_tree('tree1')
236
236
 
240
240
        target = u'\u03a9'
241
241
        link_name = u'\N{Euro Sign}link'
242
242
        os.symlink(target, 'tree1/' + link_name)
243
 
        tree.add([link_name], ['link-id'])
 
243
        tree.add([link_name],['link-id'])
244
244
 
245
245
        revision1 = tree.commit('added a link to a Unicode target')
246
246
        revision2 = tree.commit('this revision will be discarded')
363
363
        result_basis = tree.basis_tree()
364
364
        result_basis.lock_read()
365
365
        try:
366
 
            self.assertEqual(expected_inventory, result_basis.root_inventory)
 
366
            self.assertEqual(expected_inventory, result_basis.inventory)
367
367
        finally:
368
368
            result_basis.unlock()
369
369
 
386
386
        return delta
387
387
 
388
388
    def fake_up_revision(self, tree, revid, shape):
389
 
 
390
 
        class ShapeTree(InventoryRevisionTree):
391
 
 
392
 
            def __init__(self, shape):
393
 
                self._repository = tree.branch.repository
394
 
                self._inventory = shape
395
 
 
396
 
            def get_file_text(self, file_id, path=None):
397
 
                ie = self.root_inventory[file_id]
398
 
                if ie.kind != "file":
399
 
                    return ""
400
 
                return 'a' * ie.text_size
401
 
 
402
 
            def get_file(self, file_id, path=None):
403
 
                return StringIO(self.get_file_text(file_id))
404
 
 
405
389
        tree.lock_write()
406
390
        try:
407
 
            if shape.root.revision is None:
408
 
                shape.root.revision = revid
409
 
            builder = tree.branch.get_commit_builder(
410
 
                    parents=[],
411
 
                    timestamp=0,
412
 
                    timezone=None,
413
 
                    committer="Foo Bar <foo@example.com>",
414
 
                    revision_id=revid)
415
 
            shape_tree = ShapeTree(shape)
416
 
            base_tree = tree.branch.repository.revision_tree(
417
 
                    _mod_revision.NULL_REVISION)
418
 
            changes = shape_tree.iter_changes(
419
 
                base_tree)
420
 
            list(builder.record_iter_changes(shape_tree,
421
 
                base_tree.get_revision_id(), changes))
422
 
            builder.finish_inventory()
423
 
            builder.commit("Message")
 
391
            tree.branch.repository.start_write_group()
 
392
            try:
 
393
                if shape.root.revision is None:
 
394
                    shape.root.revision = revid
 
395
                # Create the text records for this inventory.
 
396
                for path, ie in shape.iter_entries():
 
397
                    if ie.text_size:
 
398
                        lines = ['a' * ie.text_size]
 
399
                    else:
 
400
                        lines = []
 
401
                    tree.branch.repository.texts.add_lines(
 
402
                        (ie.file_id, ie.revision), [], lines)
 
403
                sha1 = tree.branch.repository.add_inventory(revid, shape, [])
 
404
                rev = Revision(timestamp=0,
 
405
                               timezone=None,
 
406
                               committer="Foo Bar <foo@example.com>",
 
407
                               message="Message",
 
408
                               inventory_sha1=sha1,
 
409
                               revision_id=revid)
 
410
                tree.branch.repository.add_revision(revid, rev)
 
411
                tree.branch.repository.commit_write_group()
 
412
            except:
 
413
                tree.branch.repository.abort_write_group()
 
414
                raise
424
415
        finally:
425
416
            tree.unlock()
426
417
 
450
441
            self.add_dir(new_shape, new_revid, 'root-id', None, '')
451
442
 
452
443
    def assertTransitionFromBasisToShape(self, basis_shape, basis_revid,
453
 
        new_shape, new_revid, extra_parent=None, set_current_inventory=True):
 
444
        new_shape, new_revid, extra_parent=None):
454
445
        # set the inventory revision ids.
455
446
        basis_shape.revision_id = basis_revid
456
447
        new_shape.revision_id = new_revid
465
456
                parents.append(extra_parent)
466
457
            tree.set_parent_ids(parents)
467
458
        self.fake_up_revision(tree, new_revid, new_shape)
468
 
        if set_current_inventory:
469
 
            # give tree an inventory of new_shape
470
 
            tree._write_inventory(new_shape)
 
459
        # give tree an inventory of new_shape
 
460
        tree._write_inventory(new_shape)
471
461
        self.assertDeltaApplicationResultsInExpectedBasis(tree, new_revid,
472
462
            delta, new_shape)
473
463
        # The tree should be internally consistent; while this is a moderately
474
464
        # large hammer, this is a particularly sensitive area of code, so the
475
465
        # extra assurance is well worth it.
476
466
        tree._validate()
477
 
        # If tree.branch is remote
478
 
        if tree.user_url != tree.branch.user_url:
479
 
            # We have a lightweight checkout, delete both locations
480
 
            tree.branch.bzrdir.root_transport.delete_tree('.')
481
 
        tree.bzrdir.root_transport.delete_tree('.')
 
467
        osutils.rmtree('tree')
482
468
 
483
469
    def test_no_parents_just_root(self):
484
470
        """Test doing an empty commit - no parent, set a root only."""
485
 
        basis_shape = Inventory(root_id=None)  # empty tree
486
 
        new_shape = Inventory()  # tree with a root
 
471
        basis_shape = Inventory(root_id=None) # empty tree
 
472
        new_shape = Inventory() # tree with a root
487
473
        self.assertTransitionFromBasisToShape(basis_shape, None, new_shape,
488
474
            'new_parent')
489
475
 
534
520
        def do_file(inv, revid):
535
521
            self.add_file(inv, revid, 'path-id', 'root-id', 'path', '1' * 32,
536
522
                12)
537
 
 
538
523
        def do_link(inv, revid):
539
524
            self.add_link(inv, revid, 'path-id', 'root-id', 'path', 'target')
540
 
 
541
525
        def do_dir(inv, revid):
542
526
            self.add_dir(inv, revid, 'path-id', 'root-id', 'path')
543
 
 
544
527
        for old_factory in (do_file, do_link, do_dir):
545
528
            for new_factory in (do_file, do_link, do_dir):
546
529
                if old_factory == new_factory:
765
748
        self.add_link(new_shape, old_revid, 'link-id-C', 'dir-id-B', 'C', 'D')
766
749
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
767
750
            new_shape, new_revid)
768
 
 
769
 
    def test_add_files_to_empty_directory(self):
770
 
        old_revid = 'old-parent'
771
 
        basis_shape = Inventory(root_id=None)
772
 
        self.add_dir(basis_shape, old_revid, 'root-id', None, '')
773
 
        self.add_dir(basis_shape, old_revid, 'dir-id-A', 'root-id', 'A')
774
 
        new_revid = 'new-parent'
775
 
        new_shape = Inventory(root_id=None)
776
 
        self.add_new_root(new_shape, old_revid, new_revid)
777
 
        self.add_dir(new_shape, old_revid, 'dir-id-A', 'root-id', 'A')
778
 
        self.add_file(new_shape, new_revid, 'file-id-B', 'dir-id-A', 'B',
779
 
            '1' * 32, 24)
780
 
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
781
 
                new_shape, new_revid, set_current_inventory=False)