/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/repository_implementations/helpers.py

  • Committer: Robert Collins
  • Date: 2007-11-05 19:40:28 UTC
  • mfrom: (2963 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2967.
  • Revision ID: robertc@robertcollins.net-20071105194028-5gc6rdajk96maaq1
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Helper classes for repository implementation tests."""
18
18
 
 
19
from cStringIO import StringIO
19
20
 
20
21
from bzrlib import (
21
22
    inventory,
 
23
    osutils,
22
24
    revision as _mod_revision,
23
25
    )
24
26
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit
48
50
                "%s isn't a knit format" % self.repository_format)
49
51
 
50
52
        repo = self.make_repository('broken')
51
 
        inv = inventory.Inventory(revision_id='revision-id')
52
 
        inv.root.revision = 'revision-id'
53
 
        repo.add_inventory('revision-id', inv, [])
54
 
        revision = _mod_revision.Revision('revision-id',
55
 
            committer='jrandom@example.com', timestamp=0,
56
 
            inventory_sha1='', timezone=0, message='message', parent_ids=[])
57
 
        repo.add_revision('revision-id',revision, inv)
 
53
        repo.lock_write()
 
54
        repo.start_write_group()
 
55
        try:
 
56
            inv = inventory.Inventory(revision_id='revision-id')
 
57
            inv.root.revision = 'revision-id'
 
58
            inv_sha1 = repo.add_inventory('revision-id', inv, [])
 
59
            if repo.supports_rich_root():
 
60
                root_id = inv.root.file_id
 
61
                vf = repo.weave_store.get_weave_or_empty(root_id,
 
62
                    repo.get_transaction())
 
63
                vf.add_lines('revision-id', [], [])
 
64
            revision = _mod_revision.Revision('revision-id',
 
65
                committer='jrandom@example.com', timestamp=0,
 
66
                inventory_sha1=inv_sha1, timezone=0, message='message',
 
67
                parent_ids=[])
 
68
            # Manually add the revision text using the RevisionStore API, with
 
69
            # bad parents.
 
70
            rev_tmp = StringIO()
 
71
            repo._revision_store._serializer.write_revision(revision, rev_tmp)
 
72
            rev_tmp.seek(0)
 
73
            repo._revision_store.get_revision_file(repo.get_transaction()
 
74
                ).add_lines_with_ghosts(revision.revision_id,
 
75
                ['incorrect-parent'],
 
76
                osutils.split_lines(rev_tmp.read()))
 
77
        except:
 
78
            repo.abort_write_group()
 
79
            repo.unlock()
 
80
            raise
 
81
        else:
 
82
            repo.commit_write_group()
 
83
            repo.unlock()
58
84
 
59
 
        # Change the knit index's record of the parents for 'revision-id' to
60
 
        # claim it has a parent, 'incorrect-parent', that doesn't exist in this
61
 
        # knit at all.
62
85
        repo.lock_write()
63
86
        self.addCleanup(repo.unlock)
64
 
        rev_knit = repo._get_revision_vf()
65
 
        index_cache = rev_knit._index._cache
66
 
        cached_index_entry = list(index_cache['revision-id'])
67
 
        cached_index_entry[4] = ['incorrect-parent']
68
 
        index_cache['revision-id'] = tuple(cached_index_entry)
69
87
        return repo
70
88