~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository/test_fetch.py

  • Committer: Robert J. Tanner
  • Date: 2009-06-10 03:56:49 UTC
  • mfrom: (4423 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4425.
  • Revision ID: tanner@real-time.com-20090610035649-7rfx4cls4550zc3c
Merge 1.15.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    bzrdir,
21
21
    errors,
22
22
    gpg,
 
23
    graph,
23
24
    remote,
24
25
    repository,
 
26
    tests,
25
27
    )
26
28
from bzrlib.inventory import ROOT_ID
27
29
from bzrlib.tests import TestSkipped
144
146
            ])
145
147
 
146
148
    def test_fetch_to_rich_root_set_parent_1_parent(self):
147
 
        # 1 parent rev -> 1 parent 
 
149
        # 1 parent rev -> 1 parent
148
150
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
149
151
            ((ROOT_ID, 'base'),),
150
152
            [('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
298
300
        revision_id = tree.commit('test')
299
301
        repo.fetch(tree.branch.repository)
300
302
        repo.fetch(tree.branch.repository)
 
303
 
 
304
    def make_simple_branch_with_ghost(self):
 
305
        builder = self.make_branch_builder('source')
 
306
        builder.start_series()
 
307
        builder.build_snapshot('A-id', None, [
 
308
            ('add', ('', 'root-id', 'directory', None)),
 
309
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
310
        builder.build_snapshot('B-id', ['A-id', 'ghost-id'], [])
 
311
        builder.finish_series()
 
312
        source_b = builder.get_branch()
 
313
        source_b.lock_read()
 
314
        self.addCleanup(source_b.unlock)
 
315
        return source_b
 
316
 
 
317
    def test_fetch_with_ghost(self):
 
318
        source_b = self.make_simple_branch_with_ghost()
 
319
        target = self.make_repository('target')
 
320
        target.lock_write()
 
321
        self.addCleanup(target.unlock)
 
322
        target.fetch(source_b.repository, revision_id='B-id')
 
323
 
 
324
    def test_fetch_into_smart_with_ghost(self):
 
325
        trans = self.make_smart_server('target')
 
326
        source_b = self.make_simple_branch_with_ghost()
 
327
        target = self.make_repository('target')
 
328
        # Re-open the repository over the smart protocol
 
329
        target = repository.Repository.open(trans.base)
 
330
        target.lock_write()
 
331
        self.addCleanup(target.unlock)
 
332
        try:
 
333
            target.fetch(source_b.repository, revision_id='B-id')
 
334
        except errors.TokenLockingNotSupported:
 
335
            # The code inside fetch() that tries to lock and then fails, also
 
336
            # causes weird problems with 'lock_not_held' later on...
 
337
            target.lock_read()
 
338
            raise tests.KnownFailure('some repositories fail to fetch'
 
339
                ' via the smart server because of locking issues.')
 
340
 
 
341
    def test_fetch_from_smart_with_ghost(self):
 
342
        trans = self.make_smart_server('source')
 
343
        source_b = self.make_simple_branch_with_ghost()
 
344
        target = self.make_repository('target')
 
345
        target.lock_write()
 
346
        self.addCleanup(target.unlock)
 
347
        # Re-open the repository over the smart protocol
 
348
        source = repository.Repository.open(trans.base)
 
349
        source.lock_read()
 
350
        self.addCleanup(source.unlock)
 
351
        target.fetch(source, revision_id='B-id')
 
352
 
 
353
 
 
354
class TestSource(TestCaseWithRepository):
 
355
    """Tests for/about the results of Repository._get_source."""
 
356
 
 
357
    def test_no_absent_records_in_stream_with_ghosts(self):
 
358
        # XXX: Arguably should be in interrepository_implementations but
 
359
        # doesn't actually gain coverage there; need a specific set of
 
360
        # permutations to cover it.
 
361
        # bug lp:376255 was reported about this.
 
362
        builder = self.make_branch_builder('repo')
 
363
        builder.start_series()
 
364
        builder.build_snapshot('tip', ['ghost'],
 
365
            [('add', ('', 'ROOT_ID', 'directory', ''))],
 
366
            allow_leftmost_as_ghost=True)
 
367
        builder.finish_series()
 
368
        b = builder.get_branch()
 
369
        b.lock_read()
 
370
        self.addCleanup(b.unlock)
 
371
        repo = b.repository
 
372
        source = repo._get_source(repo._format)
 
373
        search = graph.PendingAncestryResult(['tip'], repo)
 
374
        stream = source.get_stream(search)
 
375
        for substream_type, substream in stream:
 
376
            for record in substream:
 
377
                self.assertNotEqual('absent', record.storage_kind,
 
378
                    "Absent record for %s" % (((substream_type,) + record.key),))