1
from bzrlib.revision import NULL_REVISION
2
from bzrlib.tests import TestCaseWithMemoryTransport
4
class TestGraphWalker(TestCaseWithMemoryTransport):
6
def test_distance_from_origin(self):
7
tree = self.make_branch_and_memory_tree('.')
10
self.build_ancestry(tree, {'rev1': [NULL_REVISION], 'rev2a': ['rev1'],
11
'rev2b': ['rev1'], 'rev3':['rev2a'],
12
'rev4': ['rev3', 'rev2b']})
14
graph_walker = tree.branch.repository.get_graph_walker()
15
self.assertEqual([1, 0, 2, 4],
16
graph_walker.distance_from_origin(['rev1', 'null:',
19
def build_ancestry(self, tree, ancestors):
20
pending = [NULL_REVISION]
22
for descendant, parents in ancestors.iteritems():
23
for parent in parents:
24
descendants.setdefault(parent, []).append(descendant)
25
while len(pending) > 0:
26
cur_node = pending.pop()
27
for descendant in descendants.get(cur_node, []):
28
parents = [p for p in ancestors[descendant] if p is not
30
if len([p for p in parents if not
31
tree.branch.repository.has_revision(p)]) > 0:
33
tree.set_parent_ids(parents)
34
tree.branch.set_last_revision_info(
35
len(tree.branch._lefthand_history(cur_node)),
37
tree.commit(descendant, rev_id=descendant)
38
pending.append(descendant)