~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: 2011-05-08 17:37:05 UTC
  • mfrom: (5809.4.4 avoid-add-lines)
  • Revision ID: pqm@pqm.ubuntu.com-20110508173705-uvxqfb8c0rtzqj2c
(jelmer) Avoid Repository.texts.add_lines in the testsuite as it is not
 available for some repository implementations. (Jelmer Vernooij)

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
20
import os
20
21
 
21
22
from bzrlib import (
30
31
    InventoryDirectory,
31
32
    InventoryLink,
32
33
    )
33
 
from bzrlib.revision import Revision
 
34
from bzrlib.revisiontree import InventoryRevisionTree
34
35
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
35
36
from bzrlib.uncommit import uncommit
36
37
 
384
385
        return delta
385
386
 
386
387
    def fake_up_revision(self, tree, revid, shape):
 
388
 
 
389
        class ShapeTree(InventoryRevisionTree):
 
390
 
 
391
            def __init__(self, shape):
 
392
                self._repository = tree.branch.repository
 
393
                self._inventory = shape
 
394
 
 
395
            def get_file_text(self, file_id, path=None):
 
396
                ie = self.inventory[file_id]
 
397
                if ie.kind != "file":
 
398
                    return ""
 
399
                return 'a' * ie.text_size
 
400
 
 
401
            def get_file(self, file_id, path=None):
 
402
                return StringIO(self.get_file_text(file_id))
 
403
 
387
404
        tree.lock_write()
388
405
        try:
389
 
            tree.branch.repository.start_write_group()
390
 
            try:
391
 
                if shape.root.revision is None:
392
 
                    shape.root.revision = revid
393
 
                # Create the text records for this inventory.
394
 
                for path, ie in shape.iter_entries():
395
 
                    if ie.text_size:
396
 
                        lines = ['a' * ie.text_size]
397
 
                    else:
398
 
                        lines = []
399
 
                    tree.branch.repository.texts.add_lines(
400
 
                        (ie.file_id, ie.revision), [], lines)
401
 
                sha1 = tree.branch.repository.add_inventory(revid, shape, [])
402
 
                rev = Revision(timestamp=0,
403
 
                               timezone=None,
404
 
                               committer="Foo Bar <foo@example.com>",
405
 
                               message="Message",
406
 
                               inventory_sha1=sha1,
407
 
                               revision_id=revid)
408
 
                tree.branch.repository.add_revision(revid, rev)
409
 
                tree.branch.repository.commit_write_group()
410
 
            except:
411
 
                tree.branch.repository.abort_write_group()
412
 
                raise
 
406
            if shape.root.revision is None:
 
407
                shape.root.revision = revid
 
408
            builder = tree.branch.get_commit_builder(
 
409
                    parents=[],
 
410
                    timestamp=0,
 
411
                    timezone=None,
 
412
                    committer="Foo Bar <foo@example.com>",
 
413
                    revision_id=revid)
 
414
            shape_tree = ShapeTree(shape)
 
415
            base_tree = tree.branch.repository.revision_tree(
 
416
                    _mod_revision.NULL_REVISION)
 
417
            changes = shape_tree.iter_changes(
 
418
                base_tree)
 
419
            list(builder.record_iter_changes(shape_tree,
 
420
                base_tree.get_revision_id(), changes))
 
421
            builder.finish_inventory()
 
422
            builder.commit("Message")
413
423
        finally:
414
424
            tree.unlock()
415
425