/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

Merge bzr.dev, update to use new hooks.

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
24
    osutils,
25
25
    revision as _mod_revision,
26
 
    symbol_versioning,
27
26
    tests,
28
27
    )
29
28
from bzrlib.inventory import (
32
31
    InventoryDirectory,
33
32
    InventoryLink,
34
33
    )
35
 
from bzrlib.revision import Revision
 
34
from bzrlib.revisiontree import InventoryRevisionTree
36
35
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
 
36
from bzrlib.tests import (
 
37
    features,
 
38
    )
37
39
from bzrlib.uncommit import uncommit
38
40
 
39
41
 
229
231
 
230
232
    def test_unicode_symlink(self):
231
233
        # this tests bug #272444
232
 
        self.requireFeature(tests.SymlinkFeature)
233
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
234
        self.requireFeature(features.SymlinkFeature)
 
235
        self.requireFeature(features.UnicodeFilenameFeature)
234
236
 
235
237
        tree = self.make_branch_and_tree('tree1')
236
238
 
240
242
        target = u'\u03a9'
241
243
        link_name = u'\N{Euro Sign}link'
242
244
        os.symlink(target, 'tree1/' + link_name)
243
 
        tree.add([link_name],['link-id'])
 
245
        tree.add([link_name], ['link-id'])
244
246
 
245
247
        revision1 = tree.commit('added a link to a Unicode target')
246
248
        revision2 = tree.commit('this revision will be discarded')
386
388
        return delta
387
389
 
388
390
    def fake_up_revision(self, tree, revid, shape):
 
391
 
 
392
        class ShapeTree(InventoryRevisionTree):
 
393
 
 
394
            def __init__(self, shape):
 
395
                self._repository = tree.branch.repository
 
396
                self._inventory = shape
 
397
 
 
398
            def get_file_text(self, file_id, path=None):
 
399
                ie = self.inventory[file_id]
 
400
                if ie.kind != "file":
 
401
                    return ""
 
402
                return 'a' * ie.text_size
 
403
 
 
404
            def get_file(self, file_id, path=None):
 
405
                return StringIO(self.get_file_text(file_id))
 
406
 
389
407
        tree.lock_write()
390
408
        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
 
409
            if shape.root.revision is None:
 
410
                shape.root.revision = revid
 
411
            builder = tree.branch.get_commit_builder(
 
412
                    parents=[],
 
413
                    timestamp=0,
 
414
                    timezone=None,
 
415
                    committer="Foo Bar <foo@example.com>",
 
416
                    revision_id=revid)
 
417
            shape_tree = ShapeTree(shape)
 
418
            base_tree = tree.branch.repository.revision_tree(
 
419
                    _mod_revision.NULL_REVISION)
 
420
            changes = shape_tree.iter_changes(
 
421
                base_tree)
 
422
            list(builder.record_iter_changes(shape_tree,
 
423
                base_tree.get_revision_id(), changes))
 
424
            builder.finish_inventory()
 
425
            builder.commit("Message")
415
426
        finally:
416
427
            tree.unlock()
417
428
 
468
479
 
469
480
    def test_no_parents_just_root(self):
470
481
        """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
 
482
        basis_shape = Inventory(root_id=None)  # empty tree
 
483
        new_shape = Inventory()  # tree with a root
473
484
        self.assertTransitionFromBasisToShape(basis_shape, None, new_shape,
474
485
            'new_parent')
475
486
 
520
531
        def do_file(inv, revid):
521
532
            self.add_file(inv, revid, 'path-id', 'root-id', 'path', '1' * 32,
522
533
                12)
 
534
 
523
535
        def do_link(inv, revid):
524
536
            self.add_link(inv, revid, 'path-id', 'root-id', 'path', 'target')
 
537
 
525
538
        def do_dir(inv, revid):
526
539
            self.add_dir(inv, revid, 'path-id', 'root-id', 'path')
 
540
 
527
541
        for old_factory in (do_file, do_link, do_dir):
528
542
            for new_factory in (do_file, do_link, do_dir):
529
543
                if old_factory == new_factory: