218
222
# We started from the parents, so we don't need to do anymore work
219
223
return topo_order
226
"""Return a reverse topological ordering which is 'stable'.
228
There are a few constraints:
229
1) Reverse topological (all children before all parents)
231
3) 'stable' sorting, so that we get the same result, independent of
232
machine, or extra data.
233
To do this, we use the same basic algorithm as topo_sort, but when we
234
aren't sure what node to access next, we sort them lexicographically.
236
tips = self._find_tips()
237
# Split the tips based on prefix
240
if node.key.__class__ is str or len(node.key) == 1:
244
prefix_tips.setdefault(prefix, []).append(node)
246
num_seen_children = dict.fromkeys(self._nodes, 0)
249
for prefix in sorted(prefix_tips):
250
pending = sorted(prefix_tips[prefix], key=lambda n:n.key,
254
if node.parent_keys is None:
255
# Ghost node, skip it
257
result.append(node.key)
258
for parent_key in sorted(node.parent_keys, reverse=True):
259
parent_node = self._nodes[parent_key]
260
seen_children = num_seen_children[parent_key] + 1
261
if seen_children == len(parent_node.child_keys):
262
# All children have been processed, enqueue this parent
263
pending.append(parent_node)
264
# This has been queued up, stop tracking it
265
del num_seen_children[parent_key]
267
num_seen_children[parent_key] = seen_children
221
270
def merge_sort(self, tip_key):
222
271
"""Compute the merge sorted graph output."""
223
272
from bzrlib import tsort
232
281
in tsort.merge_sort(as_parent_map, tip_key,
233
282
mainline_revisions=None,
234
283
generate_revno=True)]
285
def get_parent_keys(self, key):
286
"""Get the parents for a key
288
Returns a list containg the parents keys. If the key is a ghost,
289
None is returned. A KeyError will be raised if the key is not in
292
:param keys: Key to check (eg revision_id)
293
:return: A list of parents
295
return self._nodes[key].parent_keys
297
def get_child_keys(self, key):
298
"""Get the children for a key
300
Returns a list containg the children keys. A KeyError will be raised
301
if the key is not in the graph.
303
:param keys: Key to check (eg revision_id)
304
:return: A list of children
306
return self._nodes[key].child_keys