76
76
rev.parent_ids = []
77
77
repo.add_revision('the_ghost', rev)
79
def test_reweave_empty(self):
79
def checkNoBackupInventory(self, aBzrDir):
80
"""Check that there is no backup inventory in aBzrDir."""
81
repo = aBzrDir.open_repository()
82
self.assertRaises(errors.NoSuchFile,
83
repo.control_weaves.get_weave,
85
repo.get_transaction())
87
def checkEmptyReconcile(self, **kwargs):
88
"""Check a reconcile on an empty repository."""
80
89
self.make_repository('empty')
81
90
d = bzrlib.bzrdir.BzrDir.open('empty')
82
91
# calling on a empty repository should do nothing
83
reconciler = d.find_repository().reconcile()
92
reconciler = d.find_repository().reconcile(**kwargs)
84
93
# no inconsistent parents should have been found
85
94
self.assertEqual(0, reconciler.inconsistent_parents)
86
95
# and no garbage inventories
87
96
self.assertEqual(0, reconciler.garbage_inventories)
88
97
# and no backup weave should have been needed/made.
89
repo = d.open_repository()
90
self.assertRaises(errors.NoSuchFile,
91
repo.control_weaves.get_weave,
93
repo.get_transaction())
98
self.checkNoBackupInventory(d)
100
def test_reconile_empty(self):
101
# in an empty repo, theres nothing to do.
102
self.checkEmptyReconcile()
104
def test_reconcile_empty_thorough(self):
105
# reconcile should accept thorough=True
106
self.checkEmptyReconcile(thorough=True)
95
108
def test_reweave_inventory_without_revision_reconcile(self):
96
109
# smoke test for the all in one ui tool
104
117
self.assertRaises(errors.RevisionNotPresent,
105
118
repo.get_inventory, 'missing')
107
def test_reweave_inventory_without_revision_reconciler(self):
108
# smoke test for the all in one Reconciler class,
109
# other tests use the lower level repo.reconcile()
110
d = bzrlib.bzrdir.BzrDir.open('inventory_without_revision')
111
reconciler = Reconciler(d)
112
reconciler.reconcile()
113
# no inconsistent parents should have been found
114
self.assertEqual(1, reconciler.inconsistent_parents)
115
# and one garbage inventories
116
self.assertEqual(1, reconciler.garbage_inventories)
117
# now the backup should have it but not the current inventory
118
repo = d.open_repository()
119
backup = repo.control_weaves.get_weave('inventory.backup',
120
repo.get_transaction())
121
self.assertTrue('missing' in backup.versions())
122
self.assertRaises(errors.RevisionNotPresent,
123
repo.get_inventory, 'missing')
125
def test_reweave_inventory_without_revision(self):
120
def check_thorough_reweave_missing_revision(self, aBzrDir, reconcile,
126
122
# actual low level test.
127
123
d = bzrlib.bzrdir.BzrDir.open('inventory_without_revision')
128
repo = d.open_repository()
124
repo = aBzrDir.open_repository()
129
125
if ([None, 'missing', 'references_missing']
130
126
!= repo.get_ancestry('references_missing')):
131
127
# the repo handles ghosts without corruption, so reconcile has
133
129
expected_inconsistent_parents = 0
135
131
expected_inconsistent_parents = 1
136
reconciler = repo.reconcile()
132
reconciler = reconcile(**kwargs)
137
133
# some number of inconsistent parents should have been found
138
134
self.assertEqual(expected_inconsistent_parents,
139
135
reconciler.inconsistent_parents)
140
136
# and one garbage inventories
141
137
self.assertEqual(1, reconciler.garbage_inventories)
142
138
# now the backup should have it but not the current inventory
143
repo = d.open_repository()
139
repo = aBzrDir.open_repository()
144
140
backup = repo.control_weaves.get_weave('inventory.backup',
145
141
repo.get_transaction())
146
142
self.assertTrue('missing' in backup.versions())
151
147
self.assertEqual([None, 'references_missing'],
152
148
repo.get_ancestry('references_missing'))
150
def test_reweave_inventory_without_revision_reconciler(self):
151
# smoke test for the all in one Reconciler class,
152
# other tests use the lower level repo.reconcile()
153
d = bzrlib.bzrdir.BzrDir.open('inventory_without_revision')
155
reconciler = Reconciler(d)
156
reconciler.reconcile()
158
self.check_thorough_reweave_missing_revision(d, reconcile)
160
def test_reweave_inventory_without_revision(self):
161
# actual low level test.
162
d = bzrlib.bzrdir.BzrDir.open('inventory_without_revision')
163
repo = d.open_repository()
165
self.checkUnreconciled(d, repo.reconcile())
166
# nothing should have been altered yet : inventories without
167
# revisions are not data loss incurring for current format
168
self.check_thorough_reweave_missing_revision(d, repo.reconcile,
154
171
def test_reweave_inventory_preserves_a_revision_with_ghosts(self):
155
172
d = bzrlib.bzrdir.BzrDir.open('inventory_one_ghost')
156
reconciler = d.open_repository().reconcile()
173
reconciler = d.open_repository().reconcile(thorough=True)
157
174
# no inconsistent parents should have been found:
158
175
# the lack of a parent for ghost is normal
159
176
self.assertEqual(0, reconciler.inconsistent_parents)
175
192
self.assertEqual([None, 'ghost'], ghost_ancestry)
176
193
reconciler = repo.reconcile()
194
self.checkUnreconciled(d, reconciler)
196
reconciler = repo.reconcile(thorough=True)
177
197
# one inconsistent parents should have been found : the
178
198
# available but not reference parent for ghost.
179
199
self.assertEqual(1, reconciler.inconsistent_parents)
185
205
repo.get_inventory('the_ghost')
186
206
self.assertEqual([None, 'the_ghost', 'ghost'], repo.get_ancestry('ghost'))
187
207
self.assertEqual([None, 'the_ghost'], repo.get_ancestry('the_ghost'))
209
def checkUnreconciled(self, d, reconciler):
210
"""Check that d did not get reconciled."""
211
# nothing should have been fixed yet:
212
self.assertEqual(0, reconciler.inconsistent_parents)
213
# and no garbage inventories
214
self.assertEqual(0, reconciler.garbage_inventories)
215
self.checkNoBackupInventory(d)