80
81
reading it again, which leads to changed timestamps. This is ok though,
81
82
because the inventory.kndx file is not ignored, and the integrity of
82
83
knit joins is tested by test_knit and test_versionedfile.
85
:seealso: Additionally, assertRepositoryHasSameItems provides value
86
rather than representation checking of repositories for
85
90
directories = ['.']
101
106
target.get(path).read(),
102
107
"text for file %r differs:\n" % path)
109
def assertRepositoryHasSameItems(self, left_repo, right_repo):
110
"""require left_repo and right_repo to contain the same data."""
111
# XXX: TODO: Doesn't work yet, because we need to be able to compare
112
# local repositories to remote ones... but this is an as-yet unsolved
113
# aspect of format management and the Remote protocols...
114
# self.assertEqual(left_repo._format.__class__,
115
# right_repo._format.__class__)
116
left_repo.lock_read()
118
right_repo.lock_read()
121
all_revs = left_repo.all_revision_ids()
122
self.assertEqual(left_repo.all_revision_ids(),
123
right_repo.all_revision_ids())
124
for rev_id in left_repo.all_revision_ids():
125
self.assertEqual(left_repo.get_revision(rev_id),
126
right_repo.get_revision(rev_id))
128
left_inv_weave = left_repo.get_inventory_weave()
129
right_inv_weave = right_repo.get_inventory_weave()
130
self.assertEqual(set(left_inv_weave.versions()),
131
set(right_inv_weave.versions()))
132
# XXX: currently this does not handle indirectly referenced
133
# inventories (e.g. where the inventory is a delta basis for
134
# one that is fully present but that the revid for that
135
# inventory is not yet present.)
136
self.assertEqual(set(left_inv_weave.versions()), set(all_revs))
137
left_trees = left_repo.revision_trees(all_revs)
138
right_trees = right_repo.revision_trees(all_revs)
139
for left_tree, right_tree in izip(left_trees, right_trees):
140
self.assertEqual(left_tree.inventory, right_tree.inventory)
142
text_index = left_repo._generate_text_key_index()
143
self.assertEqual(text_index,
144
right_repo._generate_text_key_index())
145
for file_id, revision_id in text_index.iterkeys():
146
left_weave = left_repo.weave_store.get_weave(
147
file_id, left_repo.get_transaction())
148
right_weave = right_repo.weave_store.get_weave(
149
file_id, right_repo.get_transaction())
151
left_weave.get_text(revision_id),
152
right_weave.get_text(revision_id))
154
for rev_id in all_revs:
156
left_text = left_repo.get_signature_text(rev_id)
157
except NoSuchRevision:
159
right_text = right_repo.get_signature_text(rev_id)
160
self.assertEqual(left_text, right_text)
104
166
def skipIfNoWorkingTree(self, a_bzrdir):
105
167
"""Raises TestSkipped if a_bzrdir doesn't have a working tree.
229
291
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
231
293
'./.bzr/merge-hashes',
232
'./.bzr/repository/inventory.knit',
296
self.assertRepositoryHasSameItems(tree.branch.repository, repo)
236
298
def test_clone_bzrdir_repository_under_shared(self):
237
299
tree = self.make_branch_and_tree('commit_tree')
324
386
target = dir.clone(self.get_url('target/child'), force_new_repo=True)
325
387
self.assertNotEqual(dir.transport.base, target.transport.base)
326
388
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
327
['./.bzr/repository/inventory.knit',
389
['./.bzr/repository',
391
self.assertRepositoryHasSameItems(tree.branch.repository, repo)
330
393
def test_clone_bzrdir_repository_revision(self):
331
394
# test for revision limiting, [smoke test, not corner case checks].
361
424
'./.bzr/basis-inventory-cache',
362
425
'./.bzr/checkout/stat-cache',
363
426
'./.bzr/merge-hashes',
364
'./.bzr/repository/inventory.knit',
365
428
'./.bzr/stat-cache',
430
self.assertRepositoryHasSameItems(
431
tree.branch.repository, target.open_repository())
368
433
def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
369
434
# by default cloning into a shared repo uses the shared repo.
401
466
dir = source.bzrdir
402
467
target = dir.clone(self.get_url('target/child'), force_new_repo=True)
403
468
self.assertNotEqual(dir.transport.base, target.transport.base)
404
target.open_repository()
469
repo = target.open_repository()
405
470
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
406
['./.bzr/repository/inventory.knit',
471
['./.bzr/repository',
473
self.assertRepositoryHasSameItems(tree.branch.repository, repo)
409
475
def test_clone_bzrdir_branch_reference(self):
410
476
# cloning should preserve the reference status of the branch in a bzrdir
419
485
target = dir.clone(self.get_url('target'))
420
486
self.assertNotEqual(dir.transport.base, target.transport.base)
421
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
422
['./.bzr/repository/inventory.knit',
487
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
425
489
def test_clone_bzrdir_branch_revision(self):
426
490
# test for revision limiting, [smoke test, not corner case checks].
454
518
'./.bzr/checkout/stat-cache',
455
519
'./.bzr/checkout/merge-hashes',
456
520
'./.bzr/merge-hashes',
457
'./.bzr/repository/inventory.knit',
523
self.assertRepositoryHasSameItems(tree.branch.repository,
524
target.open_repository())
460
525
target.open_workingtree().revert()
462
527
def test_revert_inventory(self):
473
538
'./.bzr/checkout/stat-cache',
474
539
'./.bzr/checkout/merge-hashes',
475
540
'./.bzr/merge-hashes',
476
'./.bzr/repository/inventory.knit',
543
self.assertRepositoryHasSameItems(tree.branch.repository,
544
target.open_repository())
479
546
target.open_workingtree().revert()
480
547
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
483
550
'./.bzr/checkout/stat-cache',
484
551
'./.bzr/checkout/merge-hashes',
485
552
'./.bzr/merge-hashes',
486
'./.bzr/repository/inventory.knit',
555
self.assertRepositoryHasSameItems(tree.branch.repository,
556
target.open_repository())
489
558
def test_clone_bzrdir_tree_branch_reference(self):
490
559
# a tree with a branch reference (aka a checkout)
923
992
'./.bzr/checkout/inventory',
924
993
'./.bzr/inventory',
926
'./.bzr/repository/inventory.knit',
927
996
'./.bzr/stat-cache',
998
self.assertRepositoryHasSameItems(
999
tree.branch.repository, target.open_repository())
930
1001
def test_sprout_bzrdir_tree_branch_reference(self):
931
1002
# sprouting should create a repository if needed and a sprouted branch.
1427
1498
# break lock with just a repo should unlock the repo.
1428
1499
repo = self.make_repository('.')
1429
1500
repo.lock_write()
1501
lock_repo = repo.bzrdir.open_repository()
1502
if not lock_repo.get_physical_lock_status():
1503
# This bzrdir's default repository does not physically lock things
1504
# and thus this interaction cannot be tested at the interface
1430
1508
# only one yes needed here: it should only be unlocking
1432
1510
bzrlib.ui.ui_factory.stdin = StringIO("y\n")
1462
1539
# dir is inappropriately accessed, 3 will be needed, and
1463
1540
# we'll see that because the stream will be fully consumed
1464
1541
bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
1542
# determine if the repository will have been locked;
1543
this_repo_locked = \
1544
thisdir.open_repository().get_physical_lock_status()
1465
1545
master.bzrdir.break_lock()
1466
# only two ys should have been read
1467
self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1546
if this_repo_locked:
1547
# only two ys should have been read
1548
self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1550
# only one y should have been read
1551
self.assertEqual("y\ny\n", bzrlib.ui.ui_factory.stdin.read())
1468
1552
# we should be able to lock a newly opened branch now
1469
1553
branch = master.bzrdir.open_branch()
1470
1554
branch.lock_write()
1471
1555
branch.unlock()
1472
# we should not be able to lock the repository in thisdir as its still
1473
# held by the explicit lock we took, and the break lock should not have
1475
repo = thisdir.open_repository()
1476
orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
1478
lockdir._DEFAULT_TIMEOUT_SECONDS = 1
1479
self.assertRaises(errors.LockContention, repo.lock_write)
1481
lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
1556
if this_repo_locked:
1557
# we should not be able to lock the repository in thisdir as
1558
# its still held by the explicit lock we took, and the break
1559
# lock should not have touched it.
1560
repo = thisdir.open_repository()
1561
orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
1563
lockdir._DEFAULT_TIMEOUT_SECONDS = 1
1564
self.assertRaises(errors.LockContention, repo.lock_write)
1566
lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
1483
1568
unused_repo.unlock()
1484
1569
self.assertRaises(errors.LockBroken, master.unlock)