21
21
import bzrlib.errors as errors
22
from bzrlib.reconcile import reconcile, Reconciler
22
from bzrlib.reconcile import reconcile, Reconciler, RepoReconciler
23
23
from bzrlib.revision import Revision
24
24
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
25
25
from bzrlib.transport import get_transport
35
35
t = get_transport(self.get_url())
36
36
# an empty inventory with no revision for testing with.
37
repo = self.make_repository('inventory_no_revision')
37
# this is referenced by 'references_missing' to let us test
38
# that all the cached data is correctly converted into ghost links
39
# and the referenced inventory still cleaned.
40
repo = self.make_repository('inventory_without_revision')
38
41
inv = EmptyTree().inventory
39
42
repo.add_inventory('missing', inv, [])
43
sha1 = repo.add_inventory('references_missing', inv, ['missing'])
44
rev = Revision(timestamp=0,
46
committer="Foo Bar <foo@example.com>",
49
revision_id='references_missing')
50
rev.parent_ids = ['missing']
51
repo.add_revision('references_missing', rev)
41
53
# a inventory with no parents and the revision has parents..
67
79
def test_reweave_empty(self):
68
80
self.make_repository('empty')
69
81
d = bzrlib.bzrdir.BzrDir.open('empty')
70
reconciler = Reconciler(d)
82
# calling on a empty repository should do nothing
83
reconciler = RepoReconciler(d.find_repository())
71
84
reconciler.reconcile()
72
# smoke test for reconcile appears to work too.
74
85
# no inconsistent parents should have been found
75
86
self.assertEqual(0, reconciler.inconsistent_parents)
76
87
# and no garbage inventories
82
93
'inventory.backup',
83
94
repo.get_transaction())
96
def test_reweave_inventory_without_revision_reconcile(self):
97
# smoke test for the all in one ui tool
98
d = bzrlib.bzrdir.BzrDir.open('inventory_without_revision')
100
# now the backup should have it but not the current inventory
101
repo = d.open_repository()
102
backup = repo.control_weaves.get_weave('inventory.backup',
103
repo.get_transaction())
104
self.assertTrue('missing' in backup.names())
105
self.assertRaises(errors.WeaveRevisionNotPresent,
106
repo.get_inventory, 'missing')
108
def test_reweave_inventory_without_revision_reconciler(self):
109
# smoke test for the all in one Reconciler class,
110
# other tests use the lower level RepoReconciler.
111
d = bzrlib.bzrdir.BzrDir.open('inventory_without_revision')
112
reconciler = Reconciler(d)
113
reconciler.reconcile()
114
# no inconsistent parents should have been found
115
self.assertEqual(1, reconciler.inconsistent_parents)
116
# and one garbage inventories
117
self.assertEqual(1, reconciler.garbage_inventories)
118
# now the backup should have it but not the current inventory
119
repo = d.open_repository()
120
backup = repo.control_weaves.get_weave('inventory.backup',
121
repo.get_transaction())
122
self.assertTrue('missing' in backup.names())
123
self.assertRaises(errors.WeaveRevisionNotPresent,
124
repo.get_inventory, 'missing')
85
126
def test_reweave_inventory_without_revision(self):
86
d = bzrlib.bzrdir.BzrDir.open('inventory_no_revision')
87
reconciler = Reconciler(d)
127
# actual low level test.
128
d = bzrlib.bzrdir.BzrDir.open('inventory_without_revision')
129
reconciler = RepoReconciler(d.open_repository())
88
130
reconciler.reconcile()
89
131
# no inconsistent parents should have been found
90
self.assertEqual(0, reconciler.inconsistent_parents)
132
self.assertEqual(1, reconciler.inconsistent_parents)
91
133
# and one garbage inventories
92
134
self.assertEqual(1, reconciler.garbage_inventories)
93
135
# now the backup should have it but not the current inventory
97
139
self.assertTrue('missing' in backup.names())
98
140
self.assertRaises(errors.WeaveRevisionNotPresent,
99
141
repo.get_inventory, 'missing')
142
# and the parent list for 'references_missing' should have that
143
# revision a ghost now.
144
self.assertEqual([None, 'references_missing'],
145
repo.get_ancestry('references_missing'))
101
147
def test_reweave_inventory_preserves_a_revision_with_ghosts(self):
102
148
d = bzrlib.bzrdir.BzrDir.open('inventory_one_ghost')
103
reconciler = Reconciler(d)
149
reconciler = RepoReconciler(d.open_repository())
104
150
reconciler.reconcile()
105
151
# no inconsistent parents should have been found:
106
152
# the lack of a parent for ghost is normal
116
162
d = bzrlib.bzrdir.BzrDir.open('inventory_ghost_present')
117
163
repo = d.open_repository()
118
164
self.assertEqual([None, 'ghost'], repo.get_ancestry('ghost'))
119
reconciler = Reconciler(d)
165
reconciler = RepoReconciler(repo)
120
166
reconciler.reconcile()
121
167
# one inconsistent parents should have been found : the
122
168
# available but not reference parent for ghost.