~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository_vf/test_reconcile.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for reconciliation of repositories."""
18
18
 
19
19
import bzrlib
20
 
from bzrlib import errors
 
20
from bzrlib import (
 
21
    errors,
 
22
    )
 
23
from bzrlib.bzrdir import BzrDir
21
24
from bzrlib.inventory import Inventory
22
25
from bzrlib.reconcile import reconcile, Reconciler
23
26
from bzrlib.revision import Revision
135
138
        # a inventory with a ghost that can be corrected now.
136
139
        t.copy_tree('inventory_one_ghost', 'inventory_ghost_present')
137
140
        bzrdir_url = self.get_url('inventory_ghost_present')
138
 
        bzrdir = bzrlib.bzrdir.BzrDir.open(bzrdir_url)
 
141
        bzrdir = BzrDir.open(bzrdir_url)
139
142
        repo = bzrdir.open_repository()
140
143
        add_commit(repo, 'the_ghost', [])
141
144
 
142
145
    def checkEmptyReconcile(self, **kwargs):
143
146
        """Check a reconcile on an empty repository."""
144
147
        self.make_repository('empty')
145
 
        d = bzrlib.bzrdir.BzrDir.open(self.get_url('empty'))
 
148
        d = BzrDir.open(self.get_url('empty'))
146
149
        # calling on a empty repository should do nothing
147
150
        reconciler = d.find_repository().reconcile(**kwargs)
148
151
        # no inconsistent parents should have been found
167
170
    def test_convenience_reconcile_inventory_without_revision_reconcile(self):
168
171
        # smoke test for the all in one ui tool
169
172
        bzrdir_url = self.get_url('inventory_without_revision')
170
 
        bzrdir = bzrlib.bzrdir.BzrDir.open(bzrdir_url)
 
173
        bzrdir = BzrDir.open(bzrdir_url)
171
174
        repo = bzrdir.open_repository()
172
175
        if not repo._reconcile_does_inventory_gc:
173
176
            raise TestSkipped('Irrelevant test')
179
182
    def test_reweave_inventory_without_revision(self):
180
183
        # an excess inventory on its own is only reconciled by using thorough
181
184
        d_url = self.get_url('inventory_without_revision')
182
 
        d = bzrlib.bzrdir.BzrDir.open(d_url)
 
185
        d = BzrDir.open(d_url)
183
186
        repo = d.open_repository()
184
187
        if not repo._reconcile_does_inventory_gc:
185
188
            raise TestSkipped('Irrelevant test')
232
235
        # smoke test for the all in one Reconciler class,
233
236
        # other tests use the lower level repo.reconcile()
234
237
        d_url = self.get_url('inventory_without_revision_and_ghost')
235
 
        d = bzrlib.bzrdir.BzrDir.open(d_url)
 
238
        d = BzrDir.open(d_url)
236
239
        if not d.open_repository()._reconcile_does_inventory_gc:
237
240
            raise TestSkipped('Irrelevant test')
238
241
        def reconcile():
244
247
    def test_reweave_inventory_without_revision_and_ghost(self):
245
248
        # actual low level test.
246
249
        d_url = self.get_url('inventory_without_revision_and_ghost')
247
 
        d = bzrlib.bzrdir.BzrDir.open(d_url)
 
250
        d = BzrDir.open(d_url)
248
251
        repo = d.open_repository()
249
252
        if not repo._reconcile_does_inventory_gc:
250
253
            raise TestSkipped('Irrelevant test')
254
257
            thorough=True)
255
258
 
256
259
    def test_reweave_inventory_preserves_a_revision_with_ghosts(self):
257
 
        d = bzrlib.bzrdir.BzrDir.open(self.get_url('inventory_one_ghost'))
 
260
        d = BzrDir.open(self.get_url('inventory_one_ghost'))
258
261
        reconciler = d.open_repository().reconcile(thorough=True)
259
262
        # no inconsistent parents should have been found:
260
263
        # the lack of a parent for ghost is normal
267
270
        self.assertThat(['ghost', 'the_ghost'], MatchesAncestry(repo, 'ghost'))
268
271
 
269
272
    def test_reweave_inventory_fixes_ancestryfor_a_present_ghost(self):
270
 
        d = bzrlib.bzrdir.BzrDir.open(self.get_url('inventory_ghost_present'))
 
273
        d = BzrDir.open(self.get_url('inventory_ghost_present'))
271
274
        repo = d.open_repository()
272
275
        m = MatchesAncestry(repo, 'ghost')
273
276
        if m.match(['the_ghost', 'ghost']) is None:
349
352
        # we should add a lower level api to allow constructing such cases.
350
353
 
351
354
        # first off the common logic:
352
 
        tree = self.make_branch_and_tree('wrong-first-parent')
353
 
        second_tree = self.make_branch_and_tree('reversed-secondary-parents')
354
 
        for t in [tree, second_tree]:
 
355
        self.first_tree = self.make_branch_and_tree('wrong-first-parent')
 
356
        self.second_tree = self.make_branch_and_tree(
 
357
            'reversed-secondary-parents')
 
358
        for t in [self.first_tree, self.second_tree]:
355
359
            t.commit('1', rev_id='1')
356
360
            uncommit(t.branch, tree=t)
357
361
            t.commit('2', rev_id='2')
360
364
            uncommit(t.branch, tree=t)
361
365
        #second_tree = self.make_branch_and_tree('reversed-secondary-parents')
362
366
        #second_tree.pull(tree) # XXX won't copy the repo?
363
 
        repo_secondary = second_tree.branch.repository
 
367
        repo_secondary = self.second_tree.branch.repository
364
368
 
365
369
        # now setup the wrong-first parent case
366
 
        repo = tree.branch.repository
 
370
        repo = self.first_tree.branch.repository
367
371
        repo.lock_write()
368
372
        repo.start_write_group()
369
373
        inv = Inventory(revision_id='wrong-first-parent')
406
410
 
407
411
    def test_reconcile_wrong_order(self):
408
412
        # a wrong order in primary parents is optionally correctable
409
 
        t = self.get_transport().clone('wrong-first-parent')
410
 
        d = bzrlib.bzrdir.BzrDir.open_from_transport(t)
411
 
        repo = d.open_repository()
 
413
        repo = self.first_tree.branch.repository
412
414
        repo.lock_read()
413
415
        try:
414
416
            g = repo.get_graph()
417
419
                raise TestSkipped('wrong-first-parent is not setup for testing')
418
420
        finally:
419
421
            repo.unlock()
420
 
        self.checkUnreconciled(d, repo.reconcile())
 
422
        self.checkUnreconciled(repo.bzrdir, repo.reconcile())
421
423
        # nothing should have been altered yet : inventories without
422
424
        # revisions are not data loss incurring for current format
423
425
        reconciler = repo.reconcile(thorough=True)
435
437
 
436
438
    def test_reconcile_wrong_order_secondary_inventory(self):
437
439
        # a wrong order in the parents for inventories is ignored.
438
 
        t = self.get_transport().clone('reversed-secondary-parents')
439
 
        d = bzrlib.bzrdir.BzrDir.open_from_transport(t)
440
 
        repo = d.open_repository()
441
 
        self.checkUnreconciled(d, repo.reconcile())
442
 
        self.checkUnreconciled(d, repo.reconcile(thorough=True))
 
440
        repo = self.second_tree.branch.repository
 
441
        self.checkUnreconciled(repo.bzrdir, repo.reconcile())
 
442
        self.checkUnreconciled(repo.bzrdir, repo.reconcile(thorough=True))