1
1
from dotgraph import Node, dot_output, invoke_dot, invoke_dot_aa, NoDot, NoRsvg
2
2
from dotgraph import mail_map
3
3
from bzrlib.branch import Branch
4
from bzrlib.errors import BzrCommandError
4
from bzrlib.errors import BzrCommandError, NoCommonRoot
5
5
from bzrlib.fetch import greedy_fetch
6
from bzrlib.graph import node_distances
6
from bzrlib.graph import node_distances, select_farthest
7
from bzrlib.revision import combined_graph
122
123
def graph_merge_pick(branch, other_branch):
123
124
greedy_fetch(branch, other_branch)
125
revision_a = branch.last_patch()
126
revision_b = other_branch.last_patch()
125
128
root, ancestors, descendants, common = \
126
combined_graph(revision_a, revision_b, revision_source)
129
combined_graph(revision_a, revision_b, branch)
127
130
except bzrlib.errors.NoCommonRoot:
128
131
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
129
nodes = node_distances(descendants, ancestors, root)
130
base = select_farthest(nodes, common)
132
distances = node_distances(descendants, ancestors, root)
133
base = select_farthest(distances, common)
131
134
n_history = branch.revision_history()
132
135
m_history = other_branch.revision_history()
134
137
def dot_node(node, num):
135
n_rev = n_history.index(node) + 1
136
m_rev = m_history.index(node) + 1
139
n_rev = n_history.index(node) + 1
143
m_rev = m_history.index(node) + 1
137
146
if (n_rev, m_rev) == (None, None):
165
174
color = "#33ff99"
169
label.append('%d' % distance[node])
173
for num,node in enumerate(ancestors):
177
if node in distances:
178
label.append('%d' % distances[node])
179
return Node("n%d" % num, color=color, label=label, rev_id=node,
183
for num,node in enumerate(descendants):
174
184
dot_nodes[node] = dot_node(node, num)
176
186
node_relations = []
177
for ancestor, children in descendants.iteritems():
187
for ancestor, children in ancestors.iteritems():
188
if ancestor not in dot_nodes:
189
dot_nodes[ancestor] = dot_node(node, 100000)
178
190
for child in children:
179
node_relations.append((ancestor, child))
191
if None in (dot_nodes[ancestor], dot_nodes[child]):
192
print (dot_nodes[ancestor], dot_nodes[child])
193
node_relations.append((dot_nodes[ancestor], dot_nodes[child]))
194
return node_relations
182
197
def write_ancestry_file(branch, filename, collapse=True, antialias=True):
183
198
b = Branch(branch)
184
relations = graph_ancestry(b, collapse)
199
relations = graph_merge_pick(b, b)
185
200
ext = filename.split('.')[-1]
186
201
if antialias and ext in ('png', 'jpg'):