/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to ancestry_test.py

  • Committer: John Arbash Meinel
  • Date: 2009-08-13 19:56:26 UTC
  • mto: This revision was merged to the branch mainline in revision 4613.
  • Revision ID: john@arbash-meinel.com-20090813195626-tlsu5cexc1q8lzmr
Name the specific index api _find_ancestors, and the public CombinedGraphIndex api find_ancestry()

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from bzrlib import branch
 
3
 
 
4
def get_gcindex(path):
 
5
    b = branch.Branch.open(path)
 
6
    b.lock_read()
 
7
    r = b.repository
 
8
    rev_id = b.last_revision()
 
9
    rev_key = (rev_id,)
 
10
    gcindex = r.revisions._index
 
11
    return b, rev_key, gcindex
 
12
 
 
13
 
 
14
def get_bindex(path):
 
15
    b = branch.Branch.open(path)
 
16
    b.lock_read()
 
17
    r = b.repository
 
18
    rev_id = b.last_revision()
 
19
    rev_key = (rev_id,)
 
20
    bindex = r.revisions._index._graph_index._indices[0]
 
21
    return b, rev_key, bindex
 
22
 
 
23
def get_cindex(path):
 
24
    b = branch.Branch.open(path)
 
25
    b.lock_read()
 
26
    r = b.repository
 
27
    rev_id = b.last_revision()
 
28
    rev_key = (rev_id,)
 
29
    cindex = r.revisions._index._graph_index
 
30
    return b, rev_key, cindex
 
31
 
 
32
 
 
33
 
 
34
def ancestry_from_get_ancestry(path):
 
35
    b, rev_key, cindex = get_cindex(path)
 
36
    parent_map, missing_keys = cindex.get_ancestry([rev_key])
 
37
    b.unlock()
 
38
 
 
39
 
 
40
def ancestry_from_get_parent_map(path):
 
41
    b, rev_key, gcindex = get_gcindex(path)
 
42
    search_keys = set([rev_key])
 
43
    parent_map = {}
 
44
    generation = 0
 
45
    while search_keys:
 
46
        next_parent_map = gcindex.get_parent_map(search_keys)
 
47
        next_parent_keys = set()
 
48
        map(next_parent_keys.update, next_parent_map.itervalues())
 
49
        parent_map.update(next_parent_map)
 
50
        next_parent_keys = next_parent_keys.difference(parent_map)
 
51
        generation += 1
 
52
        # print '%4d\t%5d\t%5d' % (generation, len(search_keys),
 
53
        #                          len(parent_map))
 
54
        search_keys = next_parent_keys
 
55
    b.unlock()