/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 graph.py

  • Committer: Scott James Remnant
  • Date: 2005-10-17 04:26:00 UTC
  • Revision ID: scott@netsplit.com-20051017042600-b3a3265abfffdf53
Split the display in two with a pane, we'll use the bottom half to show
information about the current revision.  Add a Back and Forward button
which figure out which revision is logically the next of previous and
moves the cursor to it.  Handle the cursor-changed event to enable/disable
the buttons (and soon update the bottom pane).

Further split up graph.py so we can stash the internal lists to do the
above; also it may allow us in future to produce partial graphs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        self.message = self.revision_id
31
31
 
32
32
 
33
 
def graph(branch, start):
34
 
    """Produce a directed graph of a bzr branch.
 
33
def distances(branch, start):
 
34
    """Sort the revisions.
35
35
 
36
36
    Traverses the branch revision tree starting at start and produces an
37
37
    ordered list of revisions such that a revision always comes after
38
 
    any revision it is the parent of.  It also tries to make a reasonably
39
 
    not-too-stupid decision whether a parent revision is on the same
40
 
    logical branch, as that information is not available with bzr.
41
 
 
42
 
    For each revision it then yields a tuple of (revision, node, lines).
43
 
    If the revision is only referenced in the branch and not present in the
44
 
    store, revision will be a DummyRevision object, otherwise it is the bzr
45
 
    Revision object with the meta-data for the revision.
46
 
 
47
 
    Node is a tuple of (column, colour) with column being a zero-indexed
48
 
    column number of the graph that this revision represents and colour
49
 
    being a zero-indexed colour (which doesn't specify any actual colour
50
 
    in particular) to draw the node in.
51
 
 
52
 
    Lines is a list of tuples which represent lines you should draw away
53
 
    from the revision, if you also need to draw lines into the revision
54
 
    you should use the lines list from the previous iteration.  Each
55
 
    typle in the list is in the form (start, end, colour) with start and
56
 
    end being zero-indexed column numbers and colour as in node.
57
 
 
58
 
    It's up to you how to actually draw the nodes and lines (straight,
59
 
    curved, kinked, etc.) and to pick the actual colours for each index.
 
38
    any revision it is the parent of.
 
39
 
 
40
    Returns a tuple of (revids, revisions, colours, children)
60
41
    """
61
42
    revisions = { start: branch.get_revision(start) }
 
43
    children = { revisions[start]: set() }
62
44
    distances = { start: 0 }
63
45
    colours = { start: 0 }
64
46
    last_colour = 0
82
64
            # Get the parent from the cache, or put it in the cache
83
65
            try:
84
66
                parent = revisions[parent_id]
 
67
                children[parent].add(revision)
85
68
            except KeyError:
86
69
                try:
87
70
                    parent = revisions[parent_id] \
89
72
                except NoSuchRevision:
90
73
                    parent = revisions[parent_id] = DummyRevision(parent_id)
91
74
 
 
75
                children[parent] = set([ revision ])
 
76
 
92
77
            # Penalise revisions a little at a fork if we think they're on
93
78
            # the same branch -- this makes the few few (at least) revisions
94
79
            # of a branch appear straight after the fork
104
89
 
105
90
            todo.add(parent_id)
106
91
 
107
 
    # Now iterate the revisions again, but this time in list order rather
108
 
    # than traversing the tree, and build up the graph lines.  We do this
109
 
    # by keeping a list of "hanging parents", which can only be removed
110
 
    # once we encounter the revision being hung.
111
 
    hanging = [ start ]
112
 
    for revid in sorted(distances, key=distances.get):
 
92
    return ( sorted(distances, key=distances.get), revisions, colours,
 
93
             children )
 
94
 
 
95
def graph(revids, revisions, colours):
 
96
    """Produce a directed graph of a bzr branch.
 
97
 
 
98
    For each revision it then yields a tuple of (revision, node, lines).
 
99
    If the revision is only referenced in the branch and not present in the
 
100
    store, revision will be a DummyRevision object, otherwise it is the bzr
 
101
    Revision object with the meta-data for the revision.
 
102
 
 
103
    Node is a tuple of (column, colour) with column being a zero-indexed
 
104
    column number of the graph that this revision represents and colour
 
105
    being a zero-indexed colour (which doesn't specify any actual colour
 
106
    in particular) to draw the node in.
 
107
 
 
108
    Lines is a list of tuples which represent lines you should draw away
 
109
    from the revision, if you also need to draw lines into the revision
 
110
    you should use the lines list from the previous iteration.  Each
 
111
    typle in the list is in the form (start, end, colour) with start and
 
112
    end being zero-indexed column numbers and colour as in node.
 
113
 
 
114
    It's up to you how to actually draw the nodes and lines (straight,
 
115
    curved, kinked, etc.) and to pick the actual colours for each index.
 
116
    """
 
117
    hanging = revids[:1]
 
118
    for revid in revids:
113
119
        lines = []
114
120
        node = None
115
121