/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: Jelmer Vernooij
  • Date: 2008-06-29 15:54:40 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629155440-iuzfrlfifnplp9jq
Add simple test for linegraph.

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
 
              graph_data = True, mainline_only = False):
 
15
def linegraph(graph, start_revs, maxnum=None, broken_line_length=None,
 
16
              graph_data=True, mainline_only=False):
16
17
    """Produce a directed graph of a bzr repository.
17
18
 
18
19
    Returns a tuple of (line_graph, revid_index, columns_len) where
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_parents = {}
 
47
    ghosts = set()
46
48
    graph_children = {}
47
 
    for revid in graph_parents.iterkeys():
48
 
        graph_children[revid] = []
 
49
    for (revid, parent_revids) in graph.iter_ancestry(start_revs):
 
50
        if parent_revids is None:
 
51
            ghosts.add(revid)
 
52
            continue
 
53
        if parent_revids == (NULL_REVISION,):
 
54
            graph_parents[revid] = ()
 
55
        else:
 
56
            graph_parents[revid] = parent_revids
 
57
        for parent in parent_revids:
 
58
            graph_children.setdefault(parent, []).append(revid)
 
59
        graph_children.setdefault(revid, [])
 
60
    for ghost in ghosts:
 
61
        for ghost_child in graph_children[ghost]:
 
62
            graph_parents[ghost_child] = [p for p in graph_parents[ghost_child]
 
63
                                          if p not in ghosts]
 
64
    graph_parents["top:"] = start_revs
49
65
 
50
66
    if len(graph_parents)>0:
51
67
        merge_sorted_revisions = merge_sort(
52
68
            graph_parents,
53
 
            start,
 
69
            "top:",
54
70
            generate_revno=True)
55
71
    else:
56
72
        merge_sorted_revisions = ()
58
74
    if mainline_only:
59
75
        merge_sorted_revisions = [elem for elem in merge_sorted_revisions \
60
76
                                  if len(elem[3])==1 ]
 
77
 
 
78
    assert merge_sorted_revisions[0][1] == "top:"
 
79
    merge_sorted_revisions = merge_sorted_revisions[1:]
61
80
    
62
81
    revid_index = {}
63
82
    revno_index = {}
83
102
        revid_index[revid] = rev_index
84
103
        
85
104
        parents = graph_parents[revid]
86
 
        for parent_revid in parents:
87
 
            graph_children[parent_revid].append(revid)
88
 
        
89
105
        linegraph.append([revid,
90
106
                          None,
91
107
                          [],