661
662
self.assertEqual((set(['e']), set(['f', 'g'])),
662
663
graph.find_difference('e', 'f'))
664
666
def test_stacked_parents_provider(self):
665
667
parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
666
668
parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
667
stacked = _mod_graph._StackedParentsProvider([parents1, parents2])
669
stacked = _mod_graph.StackedParentsProvider([parents1, parents2])
670
self.assertEqual({'rev1':['rev4'], 'rev2':['rev3']},
671
stacked.get_parent_map(['rev1', 'rev2']))
672
self.assertEqual({'rev2':['rev3'], 'rev1':['rev4']},
673
stacked.get_parent_map(['rev2', 'rev1']))
674
self.assertEqual({'rev2':['rev3']},
675
stacked.get_parent_map(['rev2', 'rev2']))
676
self.assertEqual({'rev1':['rev4']},
677
stacked.get_parent_map(['rev1', 'rev1']))
679
def test_stacked_parents_provider_overlapping(self):
680
# rev2 is availible in both providers.
684
parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev1']})
685
parents2 = _mod_graph.DictParentsProvider({'rev2': ['rev1']})
686
stacked = _mod_graph.StackedParentsProvider([parents1, parents2])
687
self.assertEqual({'rev2': ['rev1']},
688
stacked.get_parent_map(['rev2']))
690
def test__stacked_parents_provider_deprecated(self):
691
parents1 = _mod_graph.DictParentsProvider({'rev2': ['rev3']})
692
parents2 = _mod_graph.DictParentsProvider({'rev1': ['rev4']})
693
stacked = self.applyDeprecated(deprecated_in((1, 16, 0)),
694
_mod_graph._StackedParentsProvider, [parents1, parents2])
668
695
self.assertEqual({'rev1':['rev4'], 'rev2':['rev3']},
669
696
stacked.get_parent_map(['rev1', 'rev2']))
670
697
self.assertEqual({'rev2':['rev3'], 'rev1':['rev4']},
1524
1567
# 2 and 3 cannot be removed because 1 has 2 parents
1525
1568
d = {1:[2, 3], 2:[4], 4:[6], 3:[5], 5:[6], 6:[7], 7:[]}
1526
1569
self.assertCollapsed(d, d)
1572
class TestPendingAncestryResultGetKeys(TestCaseWithMemoryTransport):
1573
"""Tests for bzrlib.graph.PendingAncestryResult."""
1575
def test_get_keys(self):
1576
builder = self.make_branch_builder('b')
1577
builder.start_series()
1578
builder.build_snapshot('rev-1', None, [
1579
('add', ('', 'root-id', 'directory', ''))])
1580
builder.build_snapshot('rev-2', ['rev-1'], [])
1581
builder.finish_series()
1582
repo = builder.get_branch().repository
1584
self.addCleanup(repo.unlock)
1585
result = _mod_graph.PendingAncestryResult(['rev-2'], repo)
1586
self.assertEqual(set(['rev-1', 'rev-2']), set(result.get_keys()))
1588
def test_get_keys_excludes_ghosts(self):
1589
builder = self.make_branch_builder('b')
1590
builder.start_series()
1591
builder.build_snapshot('rev-1', None, [
1592
('add', ('', 'root-id', 'directory', ''))])
1593
builder.build_snapshot('rev-2', ['rev-1', 'ghost'], [])
1594
builder.finish_series()
1595
repo = builder.get_branch().repository
1597
self.addCleanup(repo.unlock)
1598
result = _mod_graph.PendingAncestryResult(['rev-2'], repo)
1599
self.assertEqual(sorted(['rev-1', 'rev-2']), sorted(result.get_keys()))
1601
def test_get_keys_excludes_null(self):
1602
# Make a 'graph' with an iter_ancestry that returns NULL_REVISION
1603
# somewhere other than the last element, which can happen in real
1605
class StubGraph(object):
1606
def iter_ancestry(self, keys):
1607
return [(NULL_REVISION, ()), ('foo', (NULL_REVISION,))]
1608
result = _mod_graph.PendingAncestryResult(['rev-3'], None)
1609
result_keys = result._get_keys(StubGraph())
1610
# Only the non-null keys from the ancestry appear.
1611
self.assertEqual(set(['foo']), set(result_keys))
1614
class TestPendingAncestryResultRefine(TestGraphBase):
1616
def test_refine(self):
1617
# Used when pulling from a stacked repository, so test some revisions
1618
# being satisfied from the stacking branch.
1619
g = self.make_graph(
1620
{"tip":["mid"], "mid":["base"], "tag":["base"],
1621
"base":[NULL_REVISION], NULL_REVISION:[]})
1622
result = _mod_graph.PendingAncestryResult(['tip', 'tag'], None)
1623
result = result.refine(set(['tip']), set(['mid']))
1624
self.assertEqual(set(['mid', 'tag']), result.heads)
1625
result = result.refine(set(['mid', 'tag', 'base']),
1626
set([NULL_REVISION]))
1627
self.assertEqual(set([NULL_REVISION]), result.heads)
1628
self.assertTrue(result.is_empty())
1631
class TestSearchResultRefine(TestGraphBase):
1633
def test_refine(self):
1634
# Used when pulling from a stacked repository, so test some revisions
1635
# being satisfied from the stacking branch.
1636
g = self.make_graph(
1637
{"tip":["mid"], "mid":["base"], "tag":["base"],
1638
"base":[NULL_REVISION], NULL_REVISION:[]})
1639
result = _mod_graph.SearchResult(set(['tip', 'tag']),
1640
set([NULL_REVISION]), 4, set(['tip', 'mid', 'tag', 'base']))
1641
result = result.refine(set(['tip']), set(['mid']))
1642
recipe = result.get_recipe()
1643
# We should be starting from tag (original head) and mid (seen ref)
1644
self.assertEqual(set(['mid', 'tag']), recipe[1])
1645
# We should be stopping at NULL (original stop) and tip (seen head)
1646
self.assertEqual(set([NULL_REVISION, 'tip']), recipe[2])
1647
self.assertEqual(3, recipe[3])
1648
result = result.refine(set(['mid', 'tag', 'base']),
1649
set([NULL_REVISION]))
1650
recipe = result.get_recipe()
1651
# We should be starting from nothing (NULL was known as a cut point)
1652
self.assertEqual(set([]), recipe[1])
1653
# We should be stopping at NULL (original stop) and tip (seen head) and
1654
# tag (seen head) and mid(seen mid-point head). We could come back and
1655
# define this as not including mid, for minimal results, but it is
1656
# still 'correct' to include mid, and simpler/easier.
1657
self.assertEqual(set([NULL_REVISION, 'tip', 'tag', 'mid']), recipe[2])
1658
self.assertEqual(0, recipe[3])
1659
self.assertTrue(result.is_empty())