Esempio n. 1
0
 def merge_sort(self, tip_key):
     """Compute the merge sorted graph output."""
     from breezy import tsort
     as_parent_map = dict((node.key, node.parent_keys)
                          for node in self._nodes.values()
                          if node.parent_keys is not None)
     # We intentionally always generate revnos and never force the
     # mainline_revisions
     # Strip the sequence_number that merge_sort generates
     return [_MergeSortNode(key, merge_depth, revno, end_of_merge)
             for _, key, merge_depth, revno, end_of_merge
             in tsort.merge_sort(as_parent_map, tip_key,
                                 mainline_revisions=None,
                                 generate_revno=True)]
Esempio n. 2
0
def compute_whole_history_data(branch):
    """Compute _rev_info and _rev_indices for a branch.

    See History.__doc__ for what these data structures mean.
    """
    z = time.time()

    last_revid = branch.last_revision()

    log = logging.getLogger('loggerhead.%s' %
                            (branch.get_config().get_nickname(), ))

    graph = branch.repository.get_graph()
    parent_map = dict((key, value)
                      for key, value in graph.iter_ancestry([last_revid])
                      if value is not None)

    _revision_graph = _strip_NULL_ghosts(parent_map)

    _rev_info = []
    _rev_indices = {}

    if is_null(last_revid):
        _merge_sort = []
    else:
        _merge_sort = merge_sort(_revision_graph,
                                 last_revid,
                                 generate_revno=True)

    for info in _merge_sort:
        seq, revid, merge_depth, revno, end_of_merge = info
        revno_str = '.'.join(str(n) for n in revno)
        parents = _revision_graph[revid]
        _rev_indices[revid] = len(_rev_info)
        _rev_info.append([(seq, revid, merge_depth, revno_str, end_of_merge),
                          (), parents])

    for revid in _revision_graph.keys():
        if _rev_info[_rev_indices[revid]][0][2] == 0:
            continue
        for parent in _revision_graph[revid]:
            c = _rev_info[_rev_indices[parent]]
            if revid not in c[1]:
                c[1] = c[1] + (revid, )

    log.info('built revision graph cache: %.3f secs' % (time.time() - z, ))

    return (_rev_info, _rev_indices)
Esempio n. 3
0
 def assertSortAndIterate(self, graph, branch_tip, result_list,
                          generate_revno, mainline_revisions=None):
     """Check that merge based sort and iter_topo_order on graph works."""
     value = merge_sort(graph, branch_tip,
                        mainline_revisions=mainline_revisions,
                        generate_revno=generate_revno)
     if result_list != value:
         self.assertEqualDiff(pprint.pformat(result_list),
                              pprint.pformat(value))
     self.assertEqual(result_list,
                      list(MergeSorter(
                          graph,
                          branch_tip,
                          mainline_revisions=mainline_revisions,
                          generate_revno=generate_revno,
                          ).iter_topo_order()))