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

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
    try:
45
45
        graph = branch.repository.get_graph()
46
46
        history = list(graph.iter_lefthand_ancestry(branch.last_revision(),
47
 
                                                    [_mod_revision.NULL_REVISION]))
 
47
            [_mod_revision.NULL_REVISION]))
48
48
    finally:
49
49
        branch.unlock()
50
50
    history.reverse()
111
111
    # construct.  One way would be to uncommit and gc the revision, but not
112
112
    # every branch supports that.  -- mbp 20070814
113
113
 
114
 
    # TODO: test that fetch correctly does reweaving when needed. RBC 20051008
 
114
    #TODO: test that fetch correctly does reweaving when needed. RBC 20051008
115
115
    # Note that this means - updating the weave when ghosts are filled in to
116
116
    # add the right parents.
117
117
 
119
119
class TestFetch(TestCaseWithTransport):
120
120
 
121
121
    def test_fetch(self):
122
 
        # highest indices a: 5, b: 7
 
122
        #highest indices a: 5, b: 7
123
123
        br_a, br_b = make_branches(self, format='dirstate-tags')
124
124
        fetch_steps(self, br_a, br_b, br_a)
125
125
 
149
149
        Convert(tree.basedir, knit2_format)
150
150
        tree = WorkingTree.open(tree.basedir)
151
151
        branch = self.make_branch('branch', format=knit2_format)
152
 
        branch.pull(tree.branch, stop_revision=b'rev1')
 
152
        branch.pull(tree.branch, stop_revision='rev1')
153
153
        repo = branch.repository
154
154
        repo.lock_read()
155
155
        try:
156
156
            # Make sure fetch retrieved only what we requested
157
 
            self.assertEqual({(b'tree-root', b'rev1'): ()},
158
 
                             repo.texts.get_parent_map(
159
 
                [(b'tree-root', b'rev1'), (b'tree-root', b'rev2')]))
 
157
            self.assertEqual({('tree-root', 'rev1'):()},
 
158
                repo.texts.get_parent_map(
 
159
                    [('tree-root', 'rev1'), ('tree-root', 'rev2')]))
160
160
        finally:
161
161
            repo.unlock()
162
162
        branch.pull(tree.branch)
165
165
        repo.lock_read()
166
166
        try:
167
167
            # Make sure fetch retrieved only what we requested
168
 
            self.assertEqual({(b'tree-root', b'rev2'): ((b'tree-root', b'rev1'),)},
169
 
                             repo.texts.get_parent_map([(b'tree-root', b'rev2')]))
 
168
            self.assertEqual({('tree-root', 'rev2'):(('tree-root', 'rev1'),)},
 
169
                repo.texts.get_parent_map([('tree-root', 'rev2')]))
170
170
        finally:
171
171
            repo.unlock()
172
172
 
173
173
    def test_fetch_incompatible(self):
174
174
        knit_tree = self.make_branch_and_tree('knit', format='knit')
175
175
        knit3_tree = self.make_branch_and_tree('knit3',
176
 
                                               format='dirstate-with-subtree')
 
176
            format='dirstate-with-subtree')
177
177
        knit3_tree.commit('blah')
178
178
        e = self.assertRaises(errors.IncompatibleRepositories,
179
179
                              knit_tree.branch.fetch, knit3_tree.branch)
180
180
        self.assertContainsRe(str(e),
181
 
                              r"(?m).*/knit.*\nis not compatible with\n.*/knit3/.*\n"
182
 
                              r"different rich-root support")
 
181
            r"(?m).*/knit.*\nis not compatible with\n.*/knit3/.*\n"
 
182
            r"different rich-root support")
183
183
 
184
184
 
185
185
class TestMergeFetch(TestCaseWithTransport):
193
193
        wt2 = self.make_branch_and_tree('br2')
194
194
        br2 = wt2.branch
195
195
        wt2.commit(message='rev 2-1', rev_id=b'2-1')
196
 
        wt2.merge_from_branch(br1, from_revision=b'null:')
 
196
        wt2.merge_from_branch(br1, from_revision='null:')
197
197
        self._check_revs_present(br2)
198
198
 
199
199
    def test_merge_fetches(self):
210
210
        self._check_revs_present(br2)
211
211
 
212
212
    def _check_revs_present(self, br2):
213
 
        for rev_id in [b'1-1', b'1-2', b'2-1']:
 
213
        for rev_id in '1-1', '1-2', '2-1':
214
214
            self.assertTrue(br2.repository.has_revision(rev_id))
215
215
            rev = br2.repository.get_revision(rev_id)
216
216
            self.assertEqual(rev.revision_id, rev_id)
245
245
        wt2 = WorkingTree.open('br2').merge_from_branch(br1)
246
246
        br2.lock_read()
247
247
        self.addCleanup(br2.unlock)
248
 
        for rev_id, text in [(b'1-2', b'original from 1\n'),
249
 
                             (b'1-3', b'agreement\n'),
250
 
                             (b'2-1', b'contents in 2\n'),
251
 
                             (b'2-2', b'agreement\n')]:
 
248
        for rev_id, text in [('1-2', 'original from 1\n'),
 
249
                             ('1-3', 'agreement\n'),
 
250
                             ('2-1', 'contents in 2\n'),
 
251
                             ('2-2', 'agreement\n')]:
252
252
            self.assertEqualDiff(
253
253
                br2.repository.revision_tree(
254
254
                    rev_id).get_file_text('file'), text)
280
280
        tree.commit('one', rev_id=b'rev-one')
281
281
        source = tree.branch.repository
282
282
        source.texts = versionedfile.RecordingVersionedFilesDecorator(
283
 
            source.texts)
 
283
                        source.texts)
284
284
        source.signatures = versionedfile.RecordingVersionedFilesDecorator(
285
 
            source.signatures)
 
285
                        source.signatures)
286
286
        source.revisions = versionedfile.RecordingVersionedFilesDecorator(
287
 
            source.revisions)
 
287
                        source.revisions)
288
288
        source.inventories = versionedfile.RecordingVersionedFilesDecorator(
289
 
            source.inventories)
 
289
                        source.inventories)
290
290
        # precondition
291
291
        self.assertTrue(target._format._fetch_uses_deltas)
292
 
        target.fetch(source, revision_id=b'rev-one')
293
 
        self.assertEqual(('get_record_stream', [(b'file-id', b'rev-one')],
 
292
        target.fetch(source, revision_id='rev-one')
 
293
        self.assertEqual(('get_record_stream', [('file-id', 'rev-one')],
294
294
                          target._format._fetch_order, False),
295
295
                         self.find_get_record_stream(source.texts.calls))
296
 
        self.assertEqual(('get_record_stream', [(b'rev-one',)],
297
 
                          target._format._fetch_order, False),
298
 
                         self.find_get_record_stream(source.inventories.calls, 2))
299
 
        self.assertEqual(('get_record_stream', [(b'rev-one',)],
 
296
        self.assertEqual(('get_record_stream', [('rev-one',)],
 
297
          target._format._fetch_order, False),
 
298
          self.find_get_record_stream(source.inventories.calls, 2))
 
299
        self.assertEqual(('get_record_stream', [('rev-one',)],
300
300
                          target._format._fetch_order, False),
301
301
                         self.find_get_record_stream(source.revisions.calls))
302
302
        # XXX: Signatures is special, and slightly broken. The
307
307
        # So we know there will be extra calls, but the *last* one is the one
308
308
        # we care about.
309
309
        signature_calls = source.signatures.calls[-1:]
310
 
        self.assertEqual(('get_record_stream', [(b'rev-one',)],
 
310
        self.assertEqual(('get_record_stream', [('rev-one',)],
311
311
                          target._format._fetch_order, False),
312
312
                         self.find_get_record_stream(signature_calls))
313
313
 
320
320
        tree.commit('one', rev_id=b'rev-one')
321
321
        source = tree.branch.repository
322
322
        source.texts = versionedfile.RecordingVersionedFilesDecorator(
323
 
            source.texts)
 
323
                        source.texts)
324
324
        source.signatures = versionedfile.RecordingVersionedFilesDecorator(
325
 
            source.signatures)
 
325
                        source.signatures)
326
326
        source.revisions = versionedfile.RecordingVersionedFilesDecorator(
327
 
            source.revisions)
 
327
                        source.revisions)
328
328
        source.inventories = versionedfile.RecordingVersionedFilesDecorator(
329
 
            source.inventories)
 
329
                        source.inventories)
330
330
        # XXX: This won't work in general, but for the dirstate format it does.
331
331
        self.overrideAttr(target._format, '_fetch_uses_deltas', False)
332
 
        target.fetch(source, revision_id=b'rev-one')
333
 
        self.assertEqual(('get_record_stream', [(b'file-id', b'rev-one')],
 
332
        target.fetch(source, revision_id='rev-one')
 
333
        self.assertEqual(('get_record_stream', [('file-id', 'rev-one')],
334
334
                          target._format._fetch_order, True),
335
335
                         self.find_get_record_stream(source.texts.calls))
336
 
        self.assertEqual(('get_record_stream', [(b'rev-one',)],
337
 
                          target._format._fetch_order, True),
338
 
                         self.find_get_record_stream(source.inventories.calls, 2))
339
 
        self.assertEqual(('get_record_stream', [(b'rev-one',)],
 
336
        self.assertEqual(('get_record_stream', [('rev-one',)],
 
337
            target._format._fetch_order, True),
 
338
            self.find_get_record_stream(source.inventories.calls, 2))
 
339
        self.assertEqual(('get_record_stream', [('rev-one',)],
340
340
                          target._format._fetch_order, True),
341
341
                         self.find_get_record_stream(source.revisions.calls))
342
342
        # XXX: Signatures is special, and slightly broken. The
347
347
        # So we know there will be extra calls, but the *last* one is the one
348
348
        # we care about.
349
349
        signature_calls = source.signatures.calls[-1:]
350
 
        self.assertEqual(('get_record_stream', [(b'rev-one',)],
 
350
        self.assertEqual(('get_record_stream', [('rev-one',)],
351
351
                          target._format._fetch_order, True),
352
352
                         self.find_get_record_stream(signature_calls))
353
353
 
370
370
        # Ensure that we stored a delta
371
371
        source.lock_read()
372
372
        self.addCleanup(source.unlock)
373
 
        record = next(source.revisions.get_record_stream([(b'rev-two',)],
374
 
                                                         'unordered', False))
 
373
        record = next(source.revisions.get_record_stream([('rev-two',)],
 
374
            'unordered', False))
375
375
        self.assertEqual('knit-delta-gz', record.storage_kind)
376
 
        target.fetch(tree.branch.repository, revision_id=b'rev-two')
 
376
        target.fetch(tree.branch.repository, revision_id='rev-two')
377
377
        # The record should get expanded back to a fulltext
378
378
        target.lock_read()
379
379
        self.addCleanup(target.unlock)
380
 
        record = next(target.revisions.get_record_stream([(b'rev-two',)],
381
 
                                                         'unordered', False))
 
380
        record = next(target.revisions.get_record_stream([('rev-two',)],
 
381
            'unordered', False))
382
382
        self.assertEqual('knit-ft-gz', record.storage_kind)
383
383
 
384
384
    def test_fetch_with_fallback_and_merge(self):
402
402
        # random ids because otherwise the inventory fulltext compresses too
403
403
        # well and the deltas get bigger.
404
404
        to_add = [
405
 
            ('add', ('', b'TREE_ROOT', 'directory', None))]
 
405
            ('add', ('', 'TREE_ROOT', 'directory', None))]
406
406
        for i in range(10):
407
407
            fname = 'file%03d' % (i,)
408
 
            fileid = ('%s-%s' %
409
 
                      (fname, osutils.rand_chars(64))).encode('ascii')
410
 
            to_add.append(('add', (fname, fileid, 'file', b'content\n')))
411
 
        builder.build_snapshot(None, to_add, revision_id=b'A')
412
 
        builder.build_snapshot([b'A'], [], revision_id=b'B')
413
 
        builder.build_snapshot([b'A'], [], revision_id=b'C')
414
 
        builder.build_snapshot([b'C'], [], revision_id=b'D')
415
 
        builder.build_snapshot([b'D'], [], revision_id=b'E')
416
 
        builder.build_snapshot([b'E', b'B'], [], revision_id=b'F')
 
408
            fileid = '%s-%s' % (fname, osutils.rand_chars(64))
 
409
            to_add.append(('add', (fname, fileid, 'file', 'content\n')))
 
410
        builder.build_snapshot(None, to_add, revision_id='A')
 
411
        builder.build_snapshot(['A'], [], revision_id='B')
 
412
        builder.build_snapshot(['A'], [], revision_id='C')
 
413
        builder.build_snapshot(['C'], [], revision_id='D')
 
414
        builder.build_snapshot(['D'], [], revision_id='E')
 
415
        builder.build_snapshot(['E', 'B'], [], revision_id='F')
417
416
        builder.finish_series()
418
417
        source_branch = builder.get_branch()
419
 
        source_branch.controldir.sprout('base', revision_id=b'B')
 
418
        source_branch.controldir.sprout('base', revision_id='B')
420
419
        target_branch = self.make_branch('target', format='1.6')
421
420
        target_branch.set_stacked_on_url('../base')
422
421
        source = source_branch.repository
423
422
        source.lock_read()
424
423
        self.addCleanup(source.unlock)
425
424
        source.inventories = versionedfile.OrderingVersionedFilesDecorator(
426
 
            source.inventories,
427
 
            key_priority={(b'E',): 1, (b'D',): 2, (b'C',): 4,
428
 
                          (b'F',): 3})
 
425
                        source.inventories,
 
426
                        key_priority={('E',): 1, ('D',): 2, ('C',): 4,
 
427
                                      ('F',): 3})
429
428
        # Ensure that the content is yielded in the proper order, and given as
430
429
        # the expected kinds
431
430
        records = [(record.key, record.storage_kind)
432
431
                   for record in source.inventories.get_record_stream(
433
 
            [(b'D',), (b'C',), (b'E',), (b'F',)], 'unordered', False)]
434
 
        self.assertEqual([((b'E',), 'knit-delta-gz'), ((b'D',), 'knit-delta-gz'),
435
 
                          ((b'F',), 'knit-delta-gz'), ((b'C',), 'knit-delta-gz')],
436
 
                         records)
 
432
                        [('D',), ('C',), ('E',), ('F',)], 'unordered', False)]
 
433
        self.assertEqual([(('E',), 'knit-delta-gz'), (('D',), 'knit-delta-gz'),
 
434
                          (('F',), 'knit-delta-gz'), (('C',), 'knit-delta-gz')],
 
435
                          records)
437
436
 
438
437
        target_branch.lock_write()
439
438
        self.addCleanup(target_branch.unlock)
440
439
        target = target_branch.repository
441
 
        target.fetch(source, revision_id=b'F')
 
440
        target.fetch(source, revision_id='F')
442
441
        # 'C' should be expanded to a fulltext, but D and E should still be
443
442
        # deltas
444
443
        stream = target.inventories.get_record_stream(
445
 
            [(b'C',), (b'D',), (b'E',), (b'F',)],
 
444
            [('C',), ('D',), ('E',), ('F',)],
446
445
            'unordered', False)
447
446
        kinds = dict((record.key, record.storage_kind) for record in stream)
448
 
        self.assertEqual({(b'C',): 'knit-ft-gz', (b'D',): 'knit-delta-gz',
449
 
                          (b'E',): 'knit-delta-gz', (b'F',): 'knit-delta-gz'},
 
447
        self.assertEqual({('C',): 'knit-ft-gz', ('D',): 'knit-delta-gz',
 
448
                          ('E',): 'knit-delta-gz', ('F',): 'knit-delta-gz'},
450
449
                         kinds)
451
450
 
452
451
 
472
471
 
473
472
    def test_fetch_order_AB(self):
474
473
        """See do_fetch_order_test"""
475
 
        self.do_fetch_order_test(b'A', b'B')
 
474
        self.do_fetch_order_test('A', 'B')
476
475
 
477
476
    def test_fetch_order_BA(self):
478
477
        """See do_fetch_order_test"""
479
 
        self.do_fetch_order_test(b'B', b'A')
 
478
        self.do_fetch_order_test('B', 'A')
480
479
 
481
480
    def get_parents(self, file_id, revision_id):
482
481
        self.repo.lock_read()
483
482
        try:
484
 
            parent_map = self.repo.texts.get_parent_map(
485
 
                [(file_id, revision_id)])
 
483
            parent_map = self.repo.texts.get_parent_map([(file_id, revision_id)])
486
484
            return parent_map[(file_id, revision_id)]
487
485
        finally:
488
486
            self.repo.unlock()
490
488
    def test_fetch_ghosts(self):
491
489
        self.make_tree_and_repo()
492
490
        self.tree.commit('first commit', rev_id=b'left-parent')
493
 
        self.tree.add_parent_tree_id(b'ghost-parent')
494
 
        fork = self.tree.controldir.sprout('fork', b'null:').open_workingtree()
 
491
        self.tree.add_parent_tree_id('ghost-parent')
 
492
        fork = self.tree.controldir.sprout('fork', 'null:').open_workingtree()
495
493
        fork.commit('not a ghost', rev_id=b'not-ghost-parent')
496
494
        self.tree.branch.repository.fetch(fork.branch.repository,
497
 
                                          b'not-ghost-parent')
498
 
        self.tree.add_parent_tree_id(b'not-ghost-parent')
 
495
                                     'not-ghost-parent')
 
496
        self.tree.add_parent_tree_id('not-ghost-parent')
499
497
        self.tree.commit('second commit', rev_id=b'second-id')
500
 
        self.repo.fetch(self.tree.branch.repository, b'second-id')
501
 
        root_id = self.tree.path2id('')
 
498
        self.repo.fetch(self.tree.branch.repository, 'second-id')
 
499
        root_id = self.tree.get_root_id()
502
500
        self.assertEqual(
503
 
            ((root_id, b'left-parent'), (root_id, b'not-ghost-parent')),
504
 
            self.get_parents(root_id, b'second-id'))
 
501
            ((root_id, 'left-parent'), (root_id, 'not-ghost-parent')),
 
502
            self.get_parents(root_id, 'second-id'))
505
503
 
506
504
    def make_two_commits(self, change_root, fetch_twice):
507
505
        self.make_tree_and_repo()
510
508
            self.tree.set_root_id(b'unique-id')
511
509
        self.tree.commit('second commit', rev_id=b'second-id')
512
510
        if fetch_twice:
513
 
            self.repo.fetch(self.tree.branch.repository, b'first-id')
514
 
        self.repo.fetch(self.tree.branch.repository, b'second-id')
 
511
            self.repo.fetch(self.tree.branch.repository, 'first-id')
 
512
        self.repo.fetch(self.tree.branch.repository, 'second-id')
515
513
 
516
514
    def test_fetch_changed_root(self):
517
515
        self.make_two_commits(change_root=True, fetch_twice=False)
518
 
        self.assertEqual((), self.get_parents(b'unique-id', b'second-id'))
 
516
        self.assertEqual((), self.get_parents('unique-id', 'second-id'))
519
517
 
520
518
    def test_two_fetch_changed_root(self):
521
519
        self.make_two_commits(change_root=True, fetch_twice=True)
522
 
        self.assertEqual((), self.get_parents(b'unique-id', b'second-id'))
 
520
        self.assertEqual((), self.get_parents('unique-id', 'second-id'))
523
521
 
524
522
    def test_two_fetches(self):
525
523
        self.make_two_commits(change_root=False, fetch_twice=True)
526
 
        self.assertEqual(((b'TREE_ROOT', b'first-id'),),
527
 
                         self.get_parents(b'TREE_ROOT', b'second-id'))
 
524
        self.assertEqual((('TREE_ROOT', 'first-id'),),
 
525
            self.get_parents('TREE_ROOT', 'second-id'))