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

  • Committer: Martin Pool
  • Date: 2009-08-20 05:02:45 UTC
  • mfrom: (4615 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4632.
  • Revision ID: mbp@sourcefrog.net-20090820050245-o7cw6nxrzh1eah8h
News for apport feature

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib.errors import (
29
29
    NoSuchRevision,
30
30
    )
 
31
from bzrlib.graph import (
 
32
    SearchResult,
 
33
    )
31
34
from bzrlib.revision import (
32
35
    NULL_REVISION,
33
36
    Revision,
124
127
            to_repo.texts.get_record_stream([('foo', revid)],
125
128
            'unordered', True).next().get_bytes_as('fulltext'))
126
129
 
 
130
    def test_fetch_parent_inventories_at_stacking_boundary_smart(self):
 
131
        self.setup_smart_server_with_call_log()
 
132
        self.test_fetch_parent_inventories_at_stacking_boundary()
 
133
 
 
134
    def test_fetch_parent_inventories_at_stacking_boundary_smart_old(self):
 
135
        self.setup_smart_server_with_call_log()
 
136
        self.disable_verb('Repository.insert_stream_1.19')
 
137
        self.test_fetch_parent_inventories_at_stacking_boundary()
 
138
 
127
139
    def test_fetch_parent_inventories_at_stacking_boundary(self):
128
140
        """Fetch to a stacked branch copies inventories for parents of
129
141
        revisions at the stacking boundary.
132
144
        altered by all revisions it contains, which means that it needs both
133
145
        the inventory for any revision it has, and the inventories of all that
134
146
        revision's parents.
 
147
 
 
148
        However, we should also skip any revisions which are ghosts in the
 
149
        parents.
135
150
        """
136
 
        to_repo = self.make_to_repository('to')
137
 
        if not to_repo._format.supports_external_lookups:
 
151
        if not self.repository_format_to.supports_external_lookups:
138
152
            raise TestNotApplicable("Need stacking support in the target.")
139
153
        builder = self.make_branch_builder('branch')
140
154
        builder.start_series()
141
155
        builder.build_snapshot('base', None, [
142
 
            ('add', ('', 'root-id', 'directory', ''))])
143
 
        builder.build_snapshot('left', ['base'], [])
144
 
        builder.build_snapshot('right', ['base'], [])
145
 
        builder.build_snapshot('merge', ['left', 'right'], [])
 
156
            ('add', ('', 'root-id', 'directory', '')),
 
157
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
158
        builder.build_snapshot('left', ['base'], [
 
159
            ('modify', ('file-id', 'left content\n'))])
 
160
        builder.build_snapshot('right', ['base'], [
 
161
            ('modify', ('file-id', 'right content\n'))])
 
162
        builder.build_snapshot('merge', ['left', 'right'], [
 
163
            ('modify', ('file-id', 'left and right content\n'))])
146
164
        builder.finish_series()
147
165
        branch = builder.get_branch()
148
166
        repo = self.make_to_repository('trunk')
161
179
        self.assertEqual(
162
180
            set([('left',), ('right',), ('merge',)]),
163
181
            unstacked_repo.inventories.keys())
 
182
        # And the basis inventories have been copied correctly
 
183
        trunk.lock_read()
 
184
        self.addCleanup(trunk.unlock)
 
185
        left_tree, right_tree = trunk.repository.revision_trees(
 
186
            ['left', 'right'])
 
187
        stacked_branch.lock_read()
 
188
        self.addCleanup(stacked_branch.unlock)
 
189
        (stacked_left_tree,
 
190
         stacked_right_tree) = stacked_branch.repository.revision_trees(
 
191
            ['left', 'right'])
 
192
        self.assertEqual(left_tree.inventory, stacked_left_tree.inventory)
 
193
        self.assertEqual(right_tree.inventory, stacked_right_tree.inventory)
 
194
 
 
195
        # Finally, it's not enough to see that the basis inventories are
 
196
        # present.  The texts introduced in merge (and only those) should be
 
197
        # present, and also generating a stream should succeed without blowing
 
198
        # up.
 
199
        self.assertTrue(unstacked_repo.has_revision('merge'))
 
200
        expected_texts = set([('file-id', 'merge')])
 
201
        if stacked_branch.repository.texts.get_parent_map([('root-id',
 
202
            'merge')]):
 
203
            # If a (root-id,merge) text exists, it should be in the stacked
 
204
            # repo.
 
205
            expected_texts.add(('root-id', 'merge'))
 
206
        self.assertEqual(expected_texts, unstacked_repo.texts.keys())
 
207
        self.assertCanStreamRevision(unstacked_repo, 'merge')
 
208
 
 
209
    def assertCanStreamRevision(self, repo, revision_id):
 
210
        exclude_keys = set(repo.all_revision_ids()) - set([revision_id])
 
211
        search = SearchResult([revision_id], exclude_keys, 1, [revision_id])
 
212
        source = repo._get_source(repo._format)
 
213
        for substream_kind, substream in source.get_stream(search):
 
214
            # Consume the substream
 
215
            list(substream)
 
216
 
 
217
    def test_fetch_across_stacking_boundary_ignores_ghost(self):
 
218
        if not self.repository_format_to.supports_external_lookups:
 
219
            raise TestNotApplicable("Need stacking support in the target.")
 
220
        to_repo = self.make_to_repository('to')
 
221
        builder = self.make_branch_builder('branch')
 
222
        builder.start_series()
 
223
        builder.build_snapshot('base', None, [
 
224
            ('add', ('', 'root-id', 'directory', '')),
 
225
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
226
        builder.build_snapshot('second', ['base'], [
 
227
            ('modify', ('file-id', 'second content\n'))])
 
228
        builder.build_snapshot('third', ['second', 'ghost'], [
 
229
            ('modify', ('file-id', 'third content\n'))])
 
230
        builder.finish_series()
 
231
        branch = builder.get_branch()
 
232
        repo = self.make_to_repository('trunk')
 
233
        trunk = repo.bzrdir.create_branch()
 
234
        trunk.repository.fetch(branch.repository, 'second')
 
235
        repo = self.make_to_repository('stacked')
 
236
        stacked_branch = repo.bzrdir.create_branch()
 
237
        stacked_branch.set_stacked_on_url(trunk.base)
 
238
        stacked_branch.repository.fetch(branch.repository, 'third')
 
239
        unstacked_repo = stacked_branch.bzrdir.open_repository()
 
240
        unstacked_repo.lock_read()
 
241
        self.addCleanup(unstacked_repo.unlock)
 
242
        self.assertFalse(unstacked_repo.has_revision('second'))
 
243
        self.assertFalse(unstacked_repo.has_revision('ghost'))
 
244
        self.assertEqual(
 
245
            set([('second',), ('third',)]),
 
246
            unstacked_repo.inventories.keys())
 
247
        # And the basis inventories have been copied correctly
 
248
        trunk.lock_read()
 
249
        self.addCleanup(trunk.unlock)
 
250
        second_tree = trunk.repository.revision_tree('second')
 
251
        stacked_branch.lock_read()
 
252
        self.addCleanup(stacked_branch.unlock)
 
253
        stacked_second_tree = stacked_branch.repository.revision_tree('second')
 
254
        self.assertEqual(second_tree.inventory, stacked_second_tree.inventory)
 
255
        # Finally, it's not enough to see that the basis inventories are
 
256
        # present.  The texts introduced in merge (and only those) should be
 
257
        # present, and also generating a stream should succeed without blowing
 
258
        # up.
 
259
        self.assertTrue(unstacked_repo.has_revision('third'))
 
260
        expected_texts = set([('file-id', 'third')])
 
261
        if stacked_branch.repository.texts.get_parent_map([('root-id',
 
262
            'third')]):
 
263
            # If a (root-id,third) text exists, it should be in the stacked
 
264
            # repo.
 
265
            expected_texts.add(('root-id', 'third'))
 
266
        self.assertEqual(expected_texts, unstacked_repo.texts.keys())
 
267
        self.assertCanStreamRevision(unstacked_repo, 'third')
164
268
 
165
269
    def test_fetch_missing_basis_text(self):
166
270
        """If fetching a delta, we should die if a basis is not present."""
276
380
        to_repo = self.make_to_repository('to')
277
381
        to_repo.fetch(from_tree.branch.repository)
278
382
        recorded_inv_sha1 = to_repo.get_inventory_sha1('foo-id')
279
 
        xml = to_repo.get_inventory_xml('foo-id')
280
 
        computed_inv_sha1 = osutils.sha_string(xml)
 
383
        to_repo.lock_read()
 
384
        self.addCleanup(to_repo.unlock)
 
385
        stream = to_repo.inventories.get_record_stream([('foo-id',)],
 
386
                                                       'unordered', True)
 
387
        bytes = stream.next().get_bytes_as('fulltext')
 
388
        computed_inv_sha1 = osutils.sha_string(bytes)
281
389
        self.assertEqual(computed_inv_sha1, recorded_inv_sha1)
282
390
 
283
391