/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4593.4.2 by John Arbash Meinel
Removing the min(keys) and max(keys) calls saves 100ms in the inner loop
1
from bzrlib import branch
2
3
def get_gcindex(path):
4
    b = branch.Branch.open(path)
5
    b.lock_read()
6
    r = b.repository
7
    rev_id = b.last_revision()
8
    rev_key = (rev_id,)
9
    gcindex = r.revisions._index
10
    return b, rev_key, gcindex
11
12
13
def get_bindex(path):
14
    b = branch.Branch.open(path)
15
    b.lock_read()
16
    r = b.repository
17
    rev_id = b.last_revision()
18
    rev_key = (rev_id,)
19
    bindex = r.revisions._index._graph_index._indices[0]
20
    return b, rev_key, bindex
21
22
23
def ancestry_from_get_ancestry(path):
24
    b, rev_key, bindex = get_bindex(path)
25
    keys = set([rev_key])
26
    search_keys = set([rev_key])
27
    parent_map = {}
28
    generation = 0
29
    while search_keys:
30
        generation += 1
31
        missing_keys, search_keys = bindex.get_ancestry(search_keys, 0,
32
                                                        parent_map)
33
        # print '%4d\t%5d\t%5d' % (generation, len(search_keys),
34
        #                          len(parent_map))
35
    b.unlock()
36
37
def ancestry_from_get_parent_map(path):
38
    b, rev_key, gcindex = get_gcindex(path)
39
    search_keys = set([rev_key])
40
    parent_map = {}
41
    generation = 0
42
    while search_keys:
43
        next_parent_map = gcindex.get_parent_map(search_keys)
44
        next_parent_keys = set()
45
        map(next_parent_keys.update, next_parent_map.itervalues())
46
        parent_map.update(next_parent_map)
47
        next_parent_keys = next_parent_keys.difference(parent_map)
48
        generation += 1
49
        # print '%4d\t%5d\t%5d' % (generation, len(search_keys),
50
        #                          len(parent_map))
51
        search_keys = next_parent_keys
52
    b.unlock()
53