1
from bzrlib import graph
2
from bzrlib.revision import NULL_REVISION
4
class GraphWalker(object):
5
"""Provide incremental access to revision graphs"""
7
def __init__(self, graph):
10
def distance_from_origin(self, revisions):
11
ancestors = self._graph.get_ancestors()
12
descendants = self._graph.get_descendants()
13
descendants[NULL_REVISION] = {}
14
ancestors[NULL_REVISION] = []
15
for root in self._graph.roots:
16
descendants[NULL_REVISION][root] = 1
17
ancestors[root].append(NULL_REVISION)
18
for ghost in self._graph.ghosts:
19
# ghosts act as roots for the purpose of finding
20
# the longest paths from the root: any ghost *might*
21
# be directly attached to the root, so we treat them
23
# ghost now descends from NULL
24
descendants[NULL_REVISION][ghost] = 1
25
# that is it has an ancestor of NULL
26
ancestors[ghost] = [NULL_REVISION]
27
distances = graph.node_distances(descendants, ancestors,
29
return [distances.get(r) for r in revisions]