/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/interrepository_implementations/test_fetch.py

  • Committer: Robert Collins
  • Date: 2009-03-10 07:47:23 UTC
  • mto: This revision was merged to the branch mainline in revision 4117.
  • Revision ID: robertc@robertcollins.net-20090310074723-jgctuly1ziw23r7e
Handle inconsistent inventory data more gracefully at a small performance cost during fetch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import bzrlib
21
21
from bzrlib import (
22
22
    errors,
 
23
    inventory,
 
24
    osutils,
23
25
    repository,
24
 
    osutils,
 
26
    versionedfile,
25
27
    )
26
28
from bzrlib.errors import (
27
29
    NoSuchRevision,
73
75
        repo_b = self.make_to_repository('b')
74
76
        check_push_rev1(repo_b)
75
77
 
 
78
    def test_fetch_inconsistent_last_changed_entries(self):
 
79
        """If an inventory has odd data we should still get what it references.
 
80
        
 
81
        This test tests that we do fetch a file text created in a revision not
 
82
        being fetched, but referenced from the revision we are fetching when the
 
83
        adjacent revisions to the one being fetched do not reference that text.
 
84
        """
 
85
        tree = self.make_branch_and_tree('source')
 
86
        revid = tree.commit('old')
 
87
        to_repo = self.make_to_repository('to_repo')
 
88
        to_repo.fetch(tree.branch.repository, revid)
 
89
        # Make a broken revision and fetch it.
 
90
        source = tree.branch.repository
 
91
        source.lock_write()
 
92
        self.addCleanup(source.unlock)
 
93
        source.start_write_group()
 
94
        try:
 
95
            # We need two revisions: OLD and NEW. NEW will claim to need a file
 
96
            # 'FOO' changed in 'OLD'. OLD will not have that file at all.
 
97
            source.texts.insert_record_stream([
 
98
                versionedfile.FulltextContentFactory(('foo', revid), (), None,
 
99
                'contents')])
 
100
            basis = source.revision_tree(revid)
 
101
            parent_id = basis.path2id('')
 
102
            entry = inventory.make_entry('file', 'foo-path', parent_id, 'foo')
 
103
            entry.revision = revid
 
104
            entry.text_size = len('contents')
 
105
            entry.text_sha1 = osutils.sha_string('contents')
 
106
            inv_sha1, _ = source.add_inventory_by_delta(revid, [
 
107
                (None, 'foo-path', 'foo', entry)], 'new', [revid])
 
108
            rev = Revision(timestamp=0,
 
109
                           timezone=None,
 
110
                           committer="Foo Bar <foo@example.com>",
 
111
                           message="Message",
 
112
                           inventory_sha1=inv_sha1,
 
113
                           revision_id='new',
 
114
                           parent_ids=[revid])
 
115
            source.add_revision(rev.revision_id, rev)
 
116
        except:
 
117
            source.abort_write_group()
 
118
            raise
 
119
        else:
 
120
            source.commit_write_group()
 
121
        to_repo.fetch(source, 'new')
 
122
        to_repo.lock_read()
 
123
        self.addCleanup(to_repo.unlock)
 
124
        self.assertEqual('contents',
 
125
            to_repo.texts.get_record_stream([('foo', revid)],
 
126
            'unordered', True).next().get_bytes_as('fulltext'))
 
127
 
76
128
    def test_fetch_missing_basis_text(self):
77
129
        """If fetching a delta, we should die if a basis is not present."""
78
130
        tree = self.make_branch_and_tree('tree')