~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-12 00:16:49 UTC
  • mfrom: (4111.1.1 VersionedFiles.add_api)
  • Revision ID: pqm@pqm.ubuntu.com-20090312001649-6tvc2mmeyw992st3
(robertc) Add a groupcompress sort order for get_record_stream.
        (Robert Collins, John Arbash Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1555
1555
    record_content = record.get_bytes_as('fulltext')
1556
1556
    return "fulltext\n%s%s%s" % (
1557
1557
        _length_prefix(record_meta), record_meta, record_content)
 
1558
 
 
1559
 
 
1560
def sort_groupcompress(parent_map):
 
1561
    """Sort and group the keys in parent_map into groupcompress order.
 
1562
 
 
1563
    groupcompress is defined (currently) as reverse-topological order, grouped
 
1564
    by the key prefix.
 
1565
 
 
1566
    :return: A sorted-list of keys
 
1567
    """
 
1568
    # gc-optimal ordering is approximately reverse topological,
 
1569
    # properly grouped by file-id.
 
1570
    per_prefix_map = {}
 
1571
    for item in parent_map.iteritems():
 
1572
        key = item[0]
 
1573
        if isinstance(key, str) or len(key) == 1:
 
1574
            prefix = ''
 
1575
        else:
 
1576
            prefix = key[0]
 
1577
        try:
 
1578
            per_prefix_map[prefix].append(item)
 
1579
        except KeyError:
 
1580
            per_prefix_map[prefix] = [item]
 
1581
 
 
1582
    present_keys = []
 
1583
    for prefix in sorted(per_prefix_map):
 
1584
        present_keys.extend(reversed(tsort.topo_sort(per_prefix_map[prefix])))
 
1585
    return present_keys