~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Aaron Bentley
  • Date: 2005-08-31 18:41:38 UTC
  • Revision ID: abentley@panoramicfeedback.com-20050831184138-b918af6846adb1e7
Allowed disabling ancestry collapsing

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    if len(new_committer) < 2:
25
25
        return committer
26
26
    return new_committer
27
 
    
28
 
 
29
 
def graph_ancestry(branch):
 
27
 
 
28
 
 
29
def compact_descendants(descendants, ancestors):
 
30
    new_descendants={}
 
31
    skip = set()
 
32
    for me, my_descendants in descendants.iteritems():
 
33
        if me in skip:
 
34
            continue
 
35
        new_descendants[me] = []
 
36
        for descendant in my_descendants:
 
37
            new_descendant = descendant
 
38
            while new_descendant in descendants and \
 
39
                len(ancestors[new_descendant]) == 1 and \
 
40
                len(descendants[new_descendant]) == 1:
 
41
                skip.add(new_descendant)
 
42
                if new_descendant in new_descendants:
 
43
                    del new_descendants[new_descendant]
 
44
                new_descendant = descendants[new_descendant][0]
 
45
            new_descendants[me].append(new_descendant)
 
46
    return new_descendants    
 
47
 
 
48
 
 
49
def graph_ancestry(branch, collapse=True):
30
50
    nodes = {}
31
51
    q = ((i+1, n) for (i, n) in enumerate(branch.revision_history()))
32
52
    r = 1
60
80
                descendants[parent].append(rev_id)
61
81
        lines = new_lines
62
82
    node_relations = []
63
 
    def compact_descendants():
64
 
        new_descendants={}
65
 
        skip = set()
66
 
        for me, my_descendants in descendants.iteritems():
67
 
            if me in skip:
68
 
                continue
69
 
            new_descendants[me] = []
70
 
            for descendant in my_descendants:
71
 
                new_descendant = descendant
72
 
                while new_descendant in descendants and \
73
 
                    len(ancestors[new_descendant]) == 1 and \
74
 
                    len(descendants[new_descendant]) == 1:
75
 
                    skip.add(new_descendant)
76
 
                    if new_descendant in new_descendants:
77
 
                        del new_descendants[new_descendant]
78
 
                    new_descendant = descendants[new_descendant][0]
79
 
                new_descendants[me].append(new_descendant)
80
 
        return new_descendants    
 
83
 
 
84
    if collapse:
 
85
        visible_descendants = compact_descendants(descendants, ancestors)
 
86
    else:
 
87
        visible_descendants = descendants
81
88
                
82
 
    for key, values in compact_descendants().iteritems():
 
89
    for key, values in visible_descendants.iteritems():
83
90
        for value in values:
84
91
            node_relations.append((nodes[key], nodes[value]))
85
92
    return node_relations
86
93
 
87
 
def write_ancestry_file(branch, filename):
 
94
def write_ancestry_file(branch, filename, collapse=True):
88
95
    b = Branch(branch)
89
 
    relations = graph_ancestry(b)
 
96
    relations = graph_ancestry(b, collapse)
90
97
    ext = filename.split('.')[-1]
91
98
    if ext in ('svg', 'svgz', 'gif', 'jpg', 'ps', 'fig', 'mif', 'png'):
92
99
        invoke_dot(dot_output(relations), filename, ext)