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 Knit data structure"""
369
369
tree = self.make_branch_and_memory_tree('tree')
370
370
tree.lock_write()
372
tree.add([''], ['root-id'])
373
tree.commit('one', rev_id='rev-1')
374
tree.commit('two', rev_id='rev-2')
375
tree.commit('three', rev_id='rev-3')
376
# Pack these two revisions into another pack file, but don't remove
378
repo = tree.branch.repository
379
collection = repo._pack_collection
380
collection.ensure_loaded()
381
orig_packs = collection.packs
382
packer = pack_repo.Packer(collection, orig_packs, '.testpack')
383
new_pack = packer.pack()
385
vf = tree.branch.repository.revisions
388
tree.branch.repository.lock_read()
389
self.addCleanup(tree.branch.repository.unlock)
371
self.addCleanup(tree.unlock)
372
tree.add([''], ['root-id'])
373
tree.commit('one', rev_id='rev-1')
374
tree.commit('two', rev_id='rev-2')
375
tree.commit('three', rev_id='rev-3')
376
# Pack these three revisions into another pack file, but don't remove
378
repo = tree.branch.repository
379
collection = repo._pack_collection
380
collection.ensure_loaded()
381
orig_packs = collection.packs
382
packer = pack_repo.Packer(collection, orig_packs, '.testpack')
383
new_pack = packer.pack()
384
# forget about the new pack
387
vf = tree.branch.repository.revisions
391
388
# Set up a reload() function that switches to using the new pack file
392
389
new_index = new_pack.revision_index
393
390
access_tuple = new_pack.access_tuple()
1639
1636
([('missing-parent', ), ('ghost', )], [('missing-parent', )]))])
1640
1637
return graph_index
1639
def make_g_index_missing_parent(self):
1640
graph_index = self.make_g_index('missing_parent', 2,
1641
[(('parent', ), ' 100 78', ([], [])),
1642
(('tip', ), ' 100 78',
1643
([('parent', ), ('missing-parent', )], [('parent', )])),
1642
1647
def make_g_index_no_external_refs(self):
1643
1648
graph_index = self.make_g_index('no_external_refs', 2,
1644
1649
[(('rev', ), ' 100 78',
1652
1657
index.scan_unvalidated_index(unvalidated)
1653
1658
self.assertEqual(frozenset(), index.get_missing_compression_parents())
1655
def test_add_incomplete_unvalidated_index(self):
1660
def test_add_missing_compression_parent_unvalidated_index(self):
1656
1661
unvalidated = self.make_g_index_missing_compression_parent()
1657
1662
combined = CombinedGraphIndex([unvalidated])
1658
1663
index = _KnitGraphIndex(combined, lambda: True, deltas=True)
1664
1669
frozenset([('missing-parent',)]),
1665
1670
index.get_missing_compression_parents())
1672
def test_add_missing_noncompression_parent_unvalidated_index(self):
1673
unvalidated = self.make_g_index_missing_parent()
1674
combined = CombinedGraphIndex([unvalidated])
1675
index = _KnitGraphIndex(combined, lambda: True, deltas=True,
1676
track_external_parent_refs=True)
1677
index.scan_unvalidated_index(unvalidated)
1679
frozenset([('missing-parent',)]), index.get_missing_parents())
1681
def test_track_external_parent_refs(self):
1682
g_index = self.make_g_index('empty', 2, [])
1683
combined = CombinedGraphIndex([g_index])
1684
index = _KnitGraphIndex(combined, lambda: True, deltas=True,
1685
add_callback=self.catch_add, track_external_parent_refs=True)
1686
self.caught_entries = []
1688
(('new-key',), 'fulltext,no-eol', (None, 50, 60),
1689
[('parent-1',), ('parent-2',)])])
1691
frozenset([('parent-1',), ('parent-2',)]),
1692
index.get_missing_parents())
1667
1694
def test_add_unvalidated_index_with_present_external_references(self):
1668
1695
index = self.two_graph_index(deltas=True)
1669
1696
# Ugly hack to get at one of the underlying GraphIndex objects that