~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Aaron Bentley
  • Date: 2005-09-20 19:42:18 UTC
  • Revision ID: abentley@panoramicfeedback.com-20050920194218-773950f5ddcd468f
Added ancestry collapsing to graphs

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
def can_skip(rev_id, descendants, ancestors):
44
44
    if rev_id not in descendants:
45
45
        return False
 
46
    elif rev_id not in ancestors:
 
47
        return False
46
48
    elif len(ancestors[rev_id]) != 1:
47
49
        return False
48
 
    elif len(descendants[ancestors[rev_id][0]]) != 1:
 
50
    elif len(descendants[list(ancestors[rev_id])[0]]) != 1:
49
51
        return False
50
52
    elif len(descendants[rev_id]) != 1:
51
53
        return False
52
54
    else:
53
55
        return True
54
56
 
 
57
def compact_ancestors(descendants, ancestors):
 
58
    new_ancestors={}
 
59
    skip = set()
 
60
    for me, my_parents in ancestors.iteritems():
 
61
        if me in skip:
 
62
            continue
 
63
        new_ancestors[me] = set()
 
64
        for parent in my_parents:
 
65
            new_parent = parent 
 
66
            while can_skip(new_parent, descendants, ancestors):
 
67
                skip.add(new_parent)
 
68
                if new_parent in new_ancestors:
 
69
                    del new_ancestors[new_parent]
 
70
                new_parent = list(ancestors[new_parent])[0]
 
71
            new_ancestors[me].add(new_parent)
 
72
    return new_ancestors    
 
73
 
55
74
def compact_descendants(descendants, ancestors):
56
75
    new_descendants={}
57
76
    skip = set()
145
164
    return committer
146
165
 
147
166
 
148
 
def graph_merge_pick(branch, other_branch):
 
167
def graph_merge_pick(branch, other_branch, collapse=False):
149
168
    greedy_fetch(branch, other_branch)
150
169
    revision_a = branch.last_patch()
151
170
    revision_b = other_branch.last_patch()
215
234
 
216
235
    node_relations = []
217
236
    num = 0
218
 
    for node, parents in ancestors.iteritems():
 
237
    if collapse:
 
238
        visible_ancestors = compact_ancestors(descendants, ancestors)
 
239
    else:
 
240
        visible_ancestors = ancestors
 
241
    for node, parents in visible_ancestors.iteritems():
219
242
        if node not in dot_nodes:
220
243
            dot_nodes[node] = dot_node(node, num)
221
244
            num += 1
234
257
        relations = graph_ancestry(b, collapse)
235
258
    else:
236
259
        m = Branch.open_containing(merge_branch)
237
 
        relations = graph_merge_pick(b, m)
 
260
        relations = graph_merge_pick(b, m, collapse)
238
261
 
239
262
    ext = filename.split('.')[-1]
240
263
    if antialias and ext in RSVG_OUTPUT_TYPES: