364
364
This is done by searching the ancestries of each key. Any key that is
365
365
reachable from another key is not returned; all the others are.
367
This operation scales with the relative depth between any two keys. It
368
uses gdfo to avoid walking all ancestry.
370
:param keys: An iterable of keys.
371
:return: A set of the heads. Note that as a set there is no ordering
372
information. Callers will need to filter their input to create
373
order if they need it.
375
cdef PyObject *maybe_node
376
cdef PyObject *maybe_heads
377
cdef PyObject *temp_node
378
cdef _KnownGraphNode node
380
heads_key = PyFrozenSet_New(keys)
381
maybe_heads = PyDict_GetItem(self._known_heads, heads_key)
382
if maybe_heads != NULL:
383
return <object>maybe_heads
384
# Not cached, compute it ourselves
388
maybe_node = PyDict_GetItem(nodes, key)
389
if maybe_node == NULL:
390
raise KeyError('key %s not in nodes' % (key,))
391
PyDict_SetItem(candidate_nodes, key, <object>maybe_node)
392
if revision.NULL_REVISION in candidate_nodes:
393
# NULL_REVISION is only a head if it is the only entry
394
candidate_nodes.pop(revision.NULL_REVISION)
395
if not candidate_nodes:
396
return set([revision.NULL_REVISION])
397
# The keys changed, so recalculate heads_key
398
heads_key = PyFrozenSet_New(candidate_nodes)
399
if len(candidate_nodes) < 2:
407
while PyDict_Next(candidate_nodes, &pos, NULL, &temp_node):
408
node = <_KnownGraphNode>temp_node
409
if node.parents is not None:
410
pending.extend(node.parents)
411
if min_gdfo is None or node.gdfo < min_gdfo:
417
# node already appears in some ancestry
420
if node.gdfo <= min_gdfo:
423
pending.extend(node.parents)
424
heads = heads_key.difference(seen)
426
self._known_heads[heads_key] = heads
429
def xheads(self, keys):
430
"""Return the heads from amongst keys.
432
This is done by searching the ancestries of each key. Any key that is
433
reachable from another key is not returned; all the others are.
367
435
This operation scales with the relative depth between any two keys. If
368
436
any two keys are completely disconnected all ancestry of both sides
369
437
will be retrieved.