30
31
def make_broken_repository(self):
31
32
repo = self.make_repository('.')
33
# make rev1a: A well-formed revision, containing 'file1'
34
inv = inventory.Inventory(revision_id='rev1a')
35
inv.root.revision = 'rev1a'
36
self.add_file(repo, inv, 'file1', 'rev1a', [])
37
repo.add_inventory('rev1a', inv, [])
38
revision = _mod_revision.Revision('rev1a',
39
committer='jrandom@example.com', timestamp=0, inventory_sha1='',
40
timezone=0, message='foo', parent_ids=[])
41
repo.add_revision('rev1a',revision, inv)
43
# make rev1b, which has no Revision, but has an Inventory, and file1
44
inv = inventory.Inventory(revision_id='rev1b')
45
inv.root.revision = 'rev1b'
46
self.add_file(repo, inv, 'file1', 'rev1b', [])
47
repo.add_inventory('rev1b', inv, [])
49
# make rev2, with file1 and file2
51
# file1 has 'rev1b' as an ancestor, even though this is not
52
# mentioned by 'rev1a', making it an unreferenced ancestor
53
inv = inventory.Inventory()
54
self.add_file(repo, inv, 'file1', 'rev2', ['rev1a', 'rev1b'])
55
self.add_file(repo, inv, 'file2', 'rev2', [])
56
self.add_revision(repo, 'rev2', inv, ['rev1a'])
58
# make ghost revision rev1c
59
inv = inventory.Inventory()
60
self.add_file(repo, inv, 'file2', 'rev1c', [])
62
# make rev3 with file2
63
# file2 refers to 'rev1c', which is a ghost in this repository, so
64
# file2 cannot have rev1c as its ancestor.
65
inv = inventory.Inventory()
66
self.add_file(repo, inv, 'file2', 'rev3', ['rev1c'])
67
self.add_revision(repo, 'rev3', inv, ['rev1c'])
36
cleanups.append(repo.unlock)
37
repo.start_write_group()
38
cleanups.append(repo.commit_write_group)
39
# make rev1a: A well-formed revision, containing 'file1'
40
inv = inventory.Inventory(revision_id='rev1a')
41
inv.root.revision = 'rev1a'
42
self.add_file(repo, inv, 'file1', 'rev1a', [])
43
repo.add_inventory('rev1a', inv, [])
44
revision = _mod_revision.Revision('rev1a',
45
committer='jrandom@example.com', timestamp=0,
46
inventory_sha1='', timezone=0, message='foo', parent_ids=[])
47
repo.add_revision('rev1a',revision, inv)
49
# make rev1b, which has no Revision, but has an Inventory, and
51
inv = inventory.Inventory(revision_id='rev1b')
52
inv.root.revision = 'rev1b'
53
self.add_file(repo, inv, 'file1', 'rev1b', [])
54
repo.add_inventory('rev1b', inv, [])
56
# make rev2, with file1 and file2
58
# file1 has 'rev1b' as an ancestor, even though this is not
59
# mentioned by 'rev1a', making it an unreferenced ancestor
60
inv = inventory.Inventory()
61
self.add_file(repo, inv, 'file1', 'rev2', ['rev1a', 'rev1b'])
62
self.add_file(repo, inv, 'file2', 'rev2', [])
63
self.add_revision(repo, 'rev2', inv, ['rev1a'])
65
# make ghost revision rev1c
66
inv = inventory.Inventory()
67
self.add_file(repo, inv, 'file2', 'rev1c', [])
69
# make rev3 with file2
70
# file2 refers to 'rev1c', which is a ghost in this repository, so
71
# file2 cannot have rev1c as its ancestor.
72
inv = inventory.Inventory()
73
self.add_file(repo, inv, 'file2', 'rev3', ['rev1c'])
74
self.add_revision(repo, 'rev3', inv, ['rev1c'])
77
for cleanup in reversed(cleanups):
70
80
def add_revision(self, repo, revision_id, inv, parent_ids):
71
81
inv.revision_id = revision_id
88
98
def find_bad_ancestors(self, file_id, revision_ids):
89
99
repo = self.make_broken_repository()
90
100
vf = repo.weave_store.get_weave(file_id, repo.get_transaction())
91
return repo.find_bad_ancestors(revision_ids, file_id, vf, {})
101
return repo.find_bad_ancestors(revision_ids, file_id, vf,
102
_RevisionTextVersionCache(repo))
93
104
def test_normal_first_revision(self):
94
105
repo = self.make_broken_repository()
95
106
vf = repo.weave_store.get_weave('file1-id', repo.get_transaction())
96
inventory_versions = {}
107
inventory_versions =_RevisionTextVersionCache(repo)
97
108
result = repo.find_bad_ancestors(['rev1a'], 'file1-id', vf,
98
109
inventory_versions)
99
self.assertSubset(['rev1a'], inventory_versions.keys())
100
self.assertEqual('rev1a', inventory_versions['rev1a']['file1-id'])
110
self.assertSubset(['rev1a'],
111
inventory_versions.revision_versions.keys())
112
self.assertEqual('rev1a',
113
inventory_versions.get_text_version('file1-id',
101
115
self.assertEqual({}, result)
103
117
def test_not_present_in_revision(self):