/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/repository_implementations/test_reconcile.py

  • Committer: Martin Pool
  • Date: 2007-09-14 06:31:28 UTC
  • mfrom: (2822 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2823.
  • Revision ID: mbp@sourcefrog.net-20070914063128-0p7mh6zfb4pzdg9p
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
        t = get_transport(self.get_url())
57
57
        # an empty inventory with no revision for testing with.
58
58
        repo = self.make_repository('inventory_without_revision')
 
59
        repo.lock_write()
 
60
        repo.start_write_group()
59
61
        inv = Inventory(revision_id='missing')
60
62
        inv.root.revision = 'missing'
61
63
        repo.add_inventory('missing', inv, [])
 
64
        repo.commit_write_group()
 
65
        repo.unlock()
62
66
 
63
67
        # an empty inventory with no revision for testing with.
64
68
        # this is referenced by 'references_missing' to let us test
65
69
        # that all the cached data is correctly converted into ghost links
66
70
        # and the referenced inventory still cleaned.
67
71
        repo = self.make_repository('inventory_without_revision_and_ghost')
 
72
        repo.lock_write()
 
73
        repo.start_write_group()
68
74
        repo.add_inventory('missing', inv, [])
69
75
        inv = Inventory(revision_id='references_missing')
70
76
        inv.root.revision = 'references_missing'
77
83
                       revision_id='references_missing')
78
84
        rev.parent_ids = ['missing']
79
85
        repo.add_revision('references_missing', rev)
 
86
        repo.commit_write_group()
 
87
        repo.unlock()
80
88
 
81
89
        # a inventory with no parents and the revision has parents..
82
90
        # i.e. a ghost.
83
91
        repo = self.make_repository('inventory_one_ghost')
 
92
        repo.lock_write()
 
93
        repo.start_write_group()
84
94
        inv = Inventory(revision_id='ghost')
85
95
        inv.root.revision = 'ghost'
86
96
        sha1 = repo.add_inventory('ghost', inv, [])
92
102
                       revision_id='ghost')
93
103
        rev.parent_ids = ['the_ghost']
94
104
        repo.add_revision('ghost', rev)
 
105
        repo.commit_write_group()
 
106
        repo.unlock()
95
107
         
96
108
        # a inventory with a ghost that can be corrected now.
97
109
        t.copy_tree('inventory_one_ghost', 'inventory_ghost_present')
98
110
        bzrdir_url = self.get_url('inventory_ghost_present')
99
111
        bzrdir = bzrlib.bzrdir.BzrDir.open(bzrdir_url)
100
112
        repo = bzrdir.open_repository()
 
113
        repo.lock_write()
 
114
        repo.start_write_group()
101
115
        inv = Inventory(revision_id='the_ghost')
102
116
        inv.root.revision = 'the_ghost'
103
117
        sha1 = repo.add_inventory('the_ghost', inv, [])
109
123
                       revision_id='the_ghost')
110
124
        rev.parent_ids = []
111
125
        repo.add_revision('the_ghost', rev)
 
126
        repo.commit_write_group()
 
127
        repo.unlock()
112
128
 
113
129
    def checkEmptyReconcile(self, **kwargs):
114
130
        """Check a reconcile on an empty repository."""
123
139
        # and no backup weave should have been needed/made.
124
140
        self.checkNoBackupInventory(d)
125
141
 
126
 
    def test_reconile_empty(self):
 
142
    def test_reconcile_empty(self):
127
143
        # in an empty repo, theres nothing to do.
128
144
        self.checkEmptyReconcile()
129
145
 
 
146
    def test_repo_has_reconcile_does_inventory_gc_attribute(self):
 
147
        repo = self.make_repository('repo')
 
148
        self.assertNotEqual(None, repo._reconcile_does_inventory_gc)
 
149
 
130
150
    def test_reconcile_empty_thorough(self):
131
151
        # reconcile should accept thorough=True
132
152
        self.checkEmptyReconcile(thorough=True)
135
155
        # smoke test for the all in one ui tool
136
156
        bzrdir_url = self.get_url('inventory_without_revision')
137
157
        bzrdir = bzrlib.bzrdir.BzrDir.open(bzrdir_url)
 
158
        repo = bzrdir.open_repository()
 
159
        if not repo._reconcile_does_inventory_gc:
 
160
            raise TestSkipped('Irrelevant test')
138
161
        reconcile(bzrdir)
139
162
        # now the backup should have it but not the current inventory
140
163
        repo = bzrdir.open_repository()
145
168
        d_url = self.get_url('inventory_without_revision')
146
169
        d = bzrlib.bzrdir.BzrDir.open(d_url)
147
170
        repo = d.open_repository()
 
171
        if not repo._reconcile_does_inventory_gc:
 
172
            raise TestSkipped('Irrelevant test')
148
173
        self.checkUnreconciled(d, repo.reconcile())
149
174
        reconciler = repo.reconcile(thorough=True)
150
175
        # no bad parents
151
176
        self.assertEqual(0, reconciler.inconsistent_parents)
152
 
        # and one garbage inventoriy
 
177
        # and one garbage inventory
153
178
        self.assertEqual(1, reconciler.garbage_inventories)
154
179
        self.check_missing_was_removed(repo)
155
180
 
157
182
            **kwargs):
158
183
        # actual low level test.
159
184
        repo = aBzrDir.open_repository()
160
 
        if ([None, 'missing', 'references_missing'] 
 
185
        if ([None, 'missing', 'references_missing']
161
186
            != repo.get_ancestry('references_missing')):
162
187
            # the repo handles ghosts without corruption, so reconcile has
163
 
            # nothing to do here
 
188
            # nothing to do here. Specifically, this test has the inventory
 
189
            # 'missing' present and the revision 'missing' missing, so clearly
 
190
            # 'missing' cannot be reported in the present ancestry -> missing
 
191
            # is something that can be filled as a ghost.
164
192
            expected_inconsistent_parents = 0
165
193
        else:
166
194
            expected_inconsistent_parents = 1
190
218
        # other tests use the lower level repo.reconcile()
191
219
        d_url = self.get_url('inventory_without_revision_and_ghost')
192
220
        d = bzrlib.bzrdir.BzrDir.open(d_url)
 
221
        if not d.open_repository()._reconcile_does_inventory_gc:
 
222
            raise TestSkipped('Irrelevant test')
193
223
        def reconcile():
194
224
            reconciler = Reconciler(d)
195
225
            reconciler.reconcile()
201
231
        d_url = self.get_url('inventory_without_revision_and_ghost')
202
232
        d = bzrlib.bzrdir.BzrDir.open(d_url)
203
233
        repo = d.open_repository()
 
234
        if not repo._reconcile_does_inventory_gc:
 
235
            raise TestSkipped('Irrelevant test')
204
236
        # nothing should have been altered yet : inventories without
205
237
        # revisions are not data loss incurring for current format
206
238
        self.check_thorough_reweave_missing_revision(d, repo.reconcile,
281
313
 
282
314
        # now setup the wrong-first parent case
283
315
        repo = tree.branch.repository
 
316
        repo.lock_write()
 
317
        repo.start_write_group()
284
318
        inv = Inventory(revision_id='wrong-first-parent')
285
319
        inv.root.revision = 'wrong-first-parent'
286
320
        sha1 = repo.add_inventory('wrong-first-parent', inv, ['2', '1'])
292
326
                       revision_id='wrong-first-parent')
293
327
        rev.parent_ids = ['1', '2']
294
328
        repo.add_revision('wrong-first-parent', rev)
 
329
        repo.commit_write_group()
 
330
        repo.unlock()
295
331
 
296
332
        # now setup the wrong-secondary parent case
297
333
        repo = repo_secondary
 
334
        repo.lock_write()
 
335
        repo.start_write_group()
298
336
        inv = Inventory(revision_id='wrong-secondary-parent')
299
337
        inv.root.revision = 'wrong-secondary-parent'
300
338
        sha1 = repo.add_inventory('wrong-secondary-parent', inv, ['1', '3', '2'])
306
344
                       revision_id='wrong-secondary-parent')
307
345
        rev.parent_ids = ['1', '2', '3']
308
346
        repo.add_revision('wrong-secondary-parent', rev)
 
347
        repo.commit_write_group()
 
348
        repo.unlock()
309
349
 
310
350
    def test_reconcile_wrong_order(self):
311
351
        # a wrong order in primary parents is optionally correctable
313
353
        d = bzrlib.bzrdir.BzrDir.open_from_transport(t)
314
354
        repo = d.open_repository()
315
355
        g = repo.get_revision_graph()
316
 
        if g['wrong-first-parent'] == ['1', '2']:
 
356
        if tuple(g['wrong-first-parent']) == ('1', '2'):
317
357
            raise TestSkipped('wrong-first-parent is not setup for testing')
318
358
        self.checkUnreconciled(d, repo.reconcile())
319
359
        # nothing should have been altered yet : inventories without
325
365
        self.assertEqual(0, reconciler.garbage_inventories)
326
366
        # and should have been fixed:
327
367
        g = repo.get_revision_graph()
328
 
        self.assertEqual(['1', '2'], g['wrong-first-parent'])
 
368
        self.assertEqual(('1', '2'), g['wrong-first-parent'])
329
369
 
330
 
    def test_reconcile_wrong_order_secondary(self):
331
 
        # a wrong order in secondary parents is ignored.
 
370
    def test_reconcile_wrong_order_secondary_inventory(self):
 
371
        # a wrong order in the parents for inventories is ignored.
332
372
        t = get_transport(self.get_url()).clone('reversed-secondary-parents')
333
373
        d = bzrlib.bzrdir.BzrDir.open_from_transport(t)
334
374
        repo = d.open_repository()