~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil, Patch Queue Manager, Jelmer Vernooij
  • Date: 2017-01-17 16:20:41 UTC
  • mfrom: (6619.1.2 trunk)
  • Revision ID: tarmac-20170117162041-oo62uk1qsmgc9j31
Merge 2.7 into trunk including fixes for bugs #1622039, #1644003, #1579093 and #1645017. [r=vila]

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 errno import EEXIST
 
19
from cStringIO import StringIO
20
20
import os
21
21
 
22
22
from bzrlib import (
23
23
    errors,
24
 
    osutils,
25
24
    revision as _mod_revision,
26
 
    symbol_versioning,
27
 
    tests,
28
25
    )
29
26
from bzrlib.inventory import (
30
27
    Inventory,
32
29
    InventoryDirectory,
33
30
    InventoryLink,
34
31
    )
35
 
from bzrlib.revision import Revision
 
32
from bzrlib.revisiontree import InventoryRevisionTree
36
33
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(tests.SymlinkFeature)
233
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
232
        self.requireFeature(features.SymlinkFeature)
 
233
        self.requireFeature(features.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.inventory)
 
366
            self.assertEqual(expected_inventory, result_basis.root_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
 
389
405
        tree.lock_write()
390
406
        try:
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
 
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")
415
424
        finally:
416
425
            tree.unlock()
417
426
 
441
450
            self.add_dir(new_shape, new_revid, 'root-id', None, '')
442
451
 
443
452
    def assertTransitionFromBasisToShape(self, basis_shape, basis_revid,
444
 
        new_shape, new_revid, extra_parent=None):
 
453
        new_shape, new_revid, extra_parent=None, set_current_inventory=True):
445
454
        # set the inventory revision ids.
446
455
        basis_shape.revision_id = basis_revid
447
456
        new_shape.revision_id = new_revid
456
465
                parents.append(extra_parent)
457
466
            tree.set_parent_ids(parents)
458
467
        self.fake_up_revision(tree, new_revid, new_shape)
459
 
        # give tree an inventory of new_shape
460
 
        tree._write_inventory(new_shape)
 
468
        if set_current_inventory:
 
469
            # give tree an inventory of new_shape
 
470
            tree._write_inventory(new_shape)
461
471
        self.assertDeltaApplicationResultsInExpectedBasis(tree, new_revid,
462
472
            delta, new_shape)
463
473
        # The tree should be internally consistent; while this is a moderately
464
474
        # large hammer, this is a particularly sensitive area of code, so the
465
475
        # extra assurance is well worth it.
466
476
        tree._validate()
467
 
        osutils.rmtree('tree')
 
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('.')
468
482
 
469
483
    def test_no_parents_just_root(self):
470
484
        """Test doing an empty commit - no parent, set a root only."""
471
 
        basis_shape = Inventory(root_id=None) # empty tree
472
 
        new_shape = Inventory() # tree with a root
 
485
        basis_shape = Inventory(root_id=None)  # empty tree
 
486
        new_shape = Inventory()  # tree with a root
473
487
        self.assertTransitionFromBasisToShape(basis_shape, None, new_shape,
474
488
            'new_parent')
475
489
 
520
534
        def do_file(inv, revid):
521
535
            self.add_file(inv, revid, 'path-id', 'root-id', 'path', '1' * 32,
522
536
                12)
 
537
 
523
538
        def do_link(inv, revid):
524
539
            self.add_link(inv, revid, 'path-id', 'root-id', 'path', 'target')
 
540
 
525
541
        def do_dir(inv, revid):
526
542
            self.add_dir(inv, revid, 'path-id', 'root-id', 'path')
 
543
 
527
544
        for old_factory in (do_file, do_link, do_dir):
528
545
            for new_factory in (do_file, do_link, do_dir):
529
546
                if old_factory == new_factory:
748
765
        self.add_link(new_shape, old_revid, 'link-id-C', 'dir-id-B', 'C', 'D')
749
766
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
750
767
            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)