/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to branchview/linegraph.py

  • Committer: Aaron Bentley
  • Date: 2008-04-28 21:20:43 UTC
  • mfrom: (450.8.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 472.
  • Revision ID: aaron@aaronbentley.com-20080428212043-5di54rn0vzymooch
Get viz working on graphs with ghosts

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
__copyright__ = "Copyright © 2005 Canonical Ltd."
10
10
__author__    = "Scott James Remnant <scott@ubuntu.com>"
11
11
 
 
12
from bzrlib.revision import NULL_REVISION
12
13
from bzrlib.tsort import merge_sort
13
14
 
14
 
def linegraph(repository, start, maxnum, broken_line_length = None,
 
15
def linegraph(repository, start_revs, maxnum, broken_line_length = None,
15
16
              graph_data = True, mainline_only = False):
16
17
    """Produce a directed graph of a bzr repository.
17
18
 
42
43
    curved, kinked, etc.) and to pick the actual colours for each index.
43
44
    """
44
45
    
45
 
    graph_parents = repository.get_revision_graph(start)
 
46
    graph = repository.get_graph()
 
47
    graph_parents = {}
 
48
    ghosts = set()
 
49
    my_graph_children = {}
46
50
    graph_children = {}
47
 
    for revid in graph_parents.iterkeys():
 
51
    for (revid, parent_revids) in graph.iter_ancestry(start_revs):
 
52
        if parent_revids is None:
 
53
            ghosts.add(revid)
 
54
            continue
 
55
        if parent_revids == (NULL_REVISION,):
 
56
            graph_parents[revid] = ()
 
57
        else:
 
58
            graph_parents[revid] = parent_revids
 
59
        for parent in parent_revids:
 
60
            my_graph_children.setdefault(parent, []).append(revid)
48
61
        graph_children[revid] = []
 
62
    for ghost in ghosts:
 
63
        for ghost_child in my_graph_children[ghost]:
 
64
            graph_parents [ghost_child] = [p for p in
 
65
            graph_parents [ghost_child] if p not in ghosts]
 
66
    graph_parents["top:"] = start_revs
49
67
 
50
68
    if len(graph_parents)>0:
51
69
        merge_sorted_revisions = merge_sort(
52
70
            graph_parents,
53
 
            start,
 
71
            "top:",
54
72
            generate_revno=True)
55
73
    else:
56
74
        merge_sorted_revisions = ()
58
76
    if mainline_only:
59
77
        merge_sorted_revisions = [elem for elem in merge_sorted_revisions \
60
78
                                  if len(elem[3])==1 ]
 
79
 
 
80
    assert merge_sorted_revisions[0][1] == "top:"
 
81
    merge_sorted_revisions = merge_sorted_revisions[1:]
61
82
    
62
83
    revid_index = {}
63
84
    revno_index = {}