13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Tests for reconciliation of repositories."""
47
47
def checkNoBackupInventory(self, aBzrDir):
48
48
"""Check that there is no backup inventory in aBzrDir."""
49
49
repo = aBzrDir.open_repository()
50
# Remote repository, and possibly others, do not have
50
# Remote repository, and possibly others, do not have
52
52
if getattr(repo, '_transport', None) is not None:
53
53
for path in repo._transport.list_dir('.'):
60
60
super(TestsNeedingReweave, self).setUp()
62
62
t = get_transport(self.get_url())
63
63
# an empty inventory with no revision for testing with.
64
64
repo = self.make_repository('inventory_without_revision')
105
105
repo = self.make_repository('inventory_one_ghost')
106
106
add_commit(repo, 'ghost', ['the_ghost'])
108
108
# a inventory with a ghost that can be corrected now.
109
109
t.copy_tree('inventory_one_ghost', 'inventory_ghost_present')
110
110
bzrdir_url = self.get_url('inventory_ghost_present')
231
231
def test_reweave_inventory_preserves_a_revision_with_ghosts(self):
232
232
d = bzrlib.bzrdir.BzrDir.open(self.get_url('inventory_one_ghost'))
233
233
reconciler = d.open_repository().reconcile(thorough=True)
234
# no inconsistent parents should have been found:
234
# no inconsistent parents should have been found:
235
235
# the lack of a parent for ghost is normal
236
236
self.assertEqual(0, reconciler.inconsistent_parents)
237
237
# and one garbage inventories
240
240
repo = d.open_repository()
241
241
repo.get_inventory('ghost')
242
242
self.assertEqual([None, 'ghost'], repo.get_ancestry('ghost'))
244
244
def test_reweave_inventory_fixes_ancestryfor_a_present_ghost(self):
245
245
d = bzrlib.bzrdir.BzrDir.open(self.get_url('inventory_ghost_present'))
246
246
repo = d.open_repository()
264
264
self.assertEqual([None, 'the_ghost', 'ghost'], repo.get_ancestry('ghost'))
265
265
self.assertEqual([None, 'the_ghost'], repo.get_ancestry('the_ghost'))
267
def test_text_from_ghost_revision(self):
268
repo = self.make_repository('text-from-ghost')
269
inv = Inventory(revision_id='final-revid')
270
inv.root.revision = 'root-revid'
271
ie = inv.add_path('bla', 'file', 'myfileid')
272
ie.revision = 'ghostrevid'
274
ie.text_sha1 = "bee68c8acd989f5f1765b4660695275948bf5c00"
275
rev = bzrlib.revision.Revision(timestamp=0,
277
committer="Foo Bar <foo@example.com>",
279
revision_id='final-revid')
282
repo.start_write_group()
284
repo.add_revision('final-revid', rev, inv)
286
repo.texts.add_lines(('myfileid', 'ghostrevid'),
287
(('myfileid', 'ghost-text-parent'),),
288
["line1\n", "line2\n"])
289
except errors.RevisionNotPresent:
290
raise TestSkipped("text ghost parents not supported")
291
if repo.supports_rich_root():
292
root_id = inv.root.file_id
293
repo.texts.add_lines((inv.root.file_id, inv.root.revision),
296
repo.commit_write_group()
299
repo.reconcile(thorough=True)
268
302
class TestReconcileWithIncorrectRevisionCache(TestReconcile):
269
303
"""Ancestry data gets cached in knits and weaves should be reconcilable.
276
310
self.reduceLockdirTimeout()
277
311
super(TestReconcileWithIncorrectRevisionCache, self).setUp()
279
313
t = get_transport(self.get_url())
280
314
# we need a revision with two parents in the wrong order
281
315
# which should trigger reinsertion.
286
320
# there is no api to construct a broken knit repository at
287
321
# this point. if we ever encounter a bad graph in a knit repo
288
322
# we should add a lower level api to allow constructing such cases.
290
324
# first off the common logic:
291
325
tree = self.make_branch_and_tree('wrong-first-parent')
292
326
second_tree = self.make_branch_and_tree('reversed-secondary-parents')
307
341
repo.start_write_group()
308
342
inv = Inventory(revision_id='wrong-first-parent')
309
343
inv.root.revision = 'wrong-first-parent'
344
if repo.supports_rich_root():
345
root_id = inv.root.file_id
346
repo.texts.add_lines((root_id, 'wrong-first-parent'), [], [])
310
347
sha1 = repo.add_inventory('wrong-first-parent', inv, ['2', '1'])
311
348
rev = Revision(timestamp=0,