~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Aaron Bentley
  • Date: 2005-09-20 21:10:11 UTC
  • Revision ID: abentley@panoramicfeedback.com-20050920211011-418e92aa03c57fc8
Added skip labels to edges

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from dotgraph import Node, dot_output, invoke_dot, invoke_dot_aa, NoDot, NoRsvg
2
 
from dotgraph import mail_map, RSVG_OUTPUT_TYPES, DOT_OUTPUT_TYPES
 
2
from dotgraph import mail_map, RSVG_OUTPUT_TYPES, DOT_OUTPUT_TYPES, Edge
3
3
from bzrlib.branch import Branch
4
4
from bzrlib.errors import BzrCommandError, NoCommonRoot, NoSuchRevision
5
5
from bzrlib.fetch import greedy_fetch
54
54
    else:
55
55
        return True
56
56
 
57
 
def compact_ancestors(descendants, ancestors):
 
57
def compact_ancestors(descendants, ancestors, exceptions=()):
58
58
    new_ancestors={}
59
59
    skip = set()
60
60
    for me, my_parents in ancestors.iteritems():
61
61
        if me in skip:
62
62
            continue
63
 
        new_ancestors[me] = set()
 
63
        new_ancestors[me] = {} 
64
64
        for parent in my_parents:
65
65
            new_parent = parent 
 
66
            distance = 0
66
67
            while can_skip(new_parent, descendants, ancestors):
 
68
                if new_parent in exceptions:
 
69
                    break
67
70
                skip.add(new_parent)
68
71
                if new_parent in new_ancestors:
69
72
                    del new_ancestors[new_parent]
70
73
                new_parent = list(ancestors[new_parent])[0]
71
 
            new_ancestors[me].add(new_parent)
 
74
                distance += 1
 
75
            new_ancestors[me][new_parent] = distance
72
76
    return new_ancestors    
73
77
 
74
78
def compact_descendants(descendants, ancestors):
235
239
    node_relations = []
236
240
    num = 0
237
241
    if collapse:
238
 
        visible_ancestors = compact_ancestors(descendants, ancestors)
 
242
        visible_ancestors = compact_ancestors(descendants, ancestors, (base,))
239
243
    else:
240
244
        visible_ancestors = ancestors
241
245
    for node, parents in visible_ancestors.iteritems():
242
246
        if node not in dot_nodes:
243
247
            dot_nodes[node] = dot_node(node, num)
244
248
            num += 1
245
 
        for parent in parents:
 
249
        if visible_ancestors is ancestors:
 
250
            parent_iter = ((f, 0) for f in parents)
 
251
        else:
 
252
            parent_iter = (f for f in parents.iteritems())
 
253
        for parent, skipped in parent_iter:
246
254
            if parent not in dot_nodes:
247
255
                dot_nodes[parent] = dot_node(parent, num)
248
 
                num += 1 
249
 
            node_relations.append((dot_nodes[parent], dot_nodes[node]))
 
256
                num += 1
 
257
            edge = Edge(dot_nodes[parent], dot_nodes[node])
 
258
            if skipped != 0:
 
259
                edge.label = "%d" % skipped
 
260
            node_relations.append(edge)
250
261
    return node_relations
251
262
 
252
263