30
30
self.message = self.revision_id
33
def distances(branch, start):
34
"""Sort the revisions.
33
def graph(branch, start):
34
"""Produce a directed graph of a bzr branch.
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.
40
Returns a tuple of (revids, revisions, colours, children)
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.
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.
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.
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.
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.
42
61
revisions = { start: branch.get_revision(start) }
43
children = { revisions[start]: set() }
44
62
distances = { start: 0 }
45
63
colours = { start: 0 }
72
90
except NoSuchRevision:
73
91
parent = revisions[parent_id] = DummyRevision(parent_id)
75
children[parent] = set([ revision ])
77
# Penalise revisions a little at a fork if we think they're on
78
# the same branch -- this makes the few few (at least) revisions
79
# of a branch appear straight after the fork
80
if same_branch(revision, parent):
81
colours[parent_id] = colour
82
if len(revision.parent_ids) > 1:
83
distances[parent_id] = distance + 10
85
distances[parent_id] = distance
93
# Make a guess as to whether this node represents the same
94
# branch, or a new one. Penalise same branches in the distance
95
# stakes to give new ones a chance to appear first as one set.
96
if len(revision.parent_ids) == 1:
97
colours[parent_id] = colour
98
distances[parent_id] = distance
99
elif revision.committer == parent.committer and not reused:
100
colours[parent_id] = colour
101
distances[parent_id] = distance
87
104
colours[parent_id] = last_colour = last_colour + 1
88
distances[parent_id] = distance
105
distances[parent_id] = distance + 10
90
107
todo.add(parent_id)
92
return ( sorted(distances, key=distances.get), revisions, colours,
95
def graph(revids, revisions, colours):
96
"""Produce a directed graph of a bzr branch.
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.
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.
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.
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.
109
# Now iterate the revisions again, but this time in list order rather
110
# than traversing the tree, and build up the graph lines. We do this
111
# by keeping a list of "hanging parents", which can only be removed
112
# once we encounter the revision being hung.
114
for revid in sorted(distances, key=distances.get):