42
41
It's up to you how to actually draw the nodes and lines (straight,
43
42
curved, kinked, etc.) and to pick the actual colours for each index.
45
assert isinstance(start_revs, list)
46
def update_root_progress(step_number):
47
"""IFF our container received a root progress bar, then update it."""
48
if root_progress is not None:
49
root_progress.update(None, step_number)
45
graph_parents = repository.get_revision_graph(start)
53
46
graph_children = {}
54
update_root_progress(1)
55
progress_bar = ui.ui_factory.nested_progress_bar()
57
progress_bar.update("Arranging tree fragments")
58
for i, (revid, parent_revids) in enumerate(graph.iter_ancestry(start_revs)):
61
if parent_revids is None:
64
if parent_revids == (NULL_REVISION,):
65
graph_parents[revid] = ()
67
graph_parents[revid] = parent_revids
68
for parent in parent_revids:
69
graph_children.setdefault(parent, []).append(revid)
70
graph_children.setdefault(revid, [])
72
progress_bar.finished()
74
update_root_progress(2)
75
progress_bar = ui.ui_factory.nested_progress_bar()
77
progress_bar.update("Removing ghosts", 0, len(ghosts))
78
for i, ghost in enumerate(ghosts):
80
progress_bar.update(None, i)
81
for ghost_child in graph_children[ghost]:
82
graph_parents[ghost_child] = [p for p in graph_parents[ghost_child]
85
progress_bar.finished()
86
graph_parents["top:"] = start_revs
47
for revid in graph_parents.iterkeys():
48
graph_children[revid] = []
88
50
if len(graph_parents)>0:
89
51
merge_sorted_revisions = merge_sort(
92
54
generate_revno=True)
94
56
merge_sorted_revisions = ()
117
update_root_progress(3)
118
progress_bar = ui.ui_factory.nested_progress_bar()
120
progress_bar.update("Finding nodes", 0, len(merge_sorted_revisions))
121
for (rev_index, (sequence_number,
125
end_of_merge)) in enumerate(merge_sorted_revisions):
127
if rev_index % 25 == 0:
128
progress_bar.update(None, rev_index)
129
if maxnum and rev_index >= maxnum:
131
revid_index[revid] = rev_index
133
parents = graph_parents[revid]
134
linegraph.append([revid,
142
revno_index[revno_sequence] = rev_index
144
branch_id = revno_sequence[0:-1]
147
if branch_id not in branch_lines:
149
branch_lines[branch_id] = branch_line
151
branch_line = branch_lines[branch_id]
153
branch_line.append(rev_index)
155
progress_bar.finished()
76
for (rev_index, (sequence_number,
80
end_of_merge)) in enumerate(merge_sorted_revisions):
81
if maxnum and rev_index >= maxnum:
83
revid_index[revid] = rev_index
85
parents = graph_parents[revid]
86
for parent_revid in parents:
87
graph_children[parent_revid].append(revid)
89
linegraph.append([revid,
97
revno_index[revno_sequence] = rev_index
99
branch_id = revno_sequence[0:-1]
102
if branch_id not in branch_lines:
104
branch_lines[branch_id] = branch_line
106
branch_line = branch_lines[branch_id]
108
branch_line.append(rev_index)
158
111
branch_ids = branch_lines.keys()
180
133
columns = [list(empty_column)]
183
update_root_progress(4)
184
progress_bar = ui.ui_factory.nested_progress_bar()
186
progress_bar.update("Organizing edges", 0, len(branch_ids))
187
for i, branch_id in enumerate(branch_ids):
189
progress_bar.update(None, i)
190
branch_line = branch_lines[branch_id]
192
# Find the col_index for the direct parent branch. This will be the
193
# starting point when looking for a free column.
196
if len(branch_id) > 1:
197
parent_revno = branch_id[0:-1]
198
if parent_revno in revno_index:
199
parent_index = revno_index[parent_revno]
136
for branch_id in branch_ids:
137
branch_line = branch_lines[branch_id]
139
# Find the col_index for the direct parent branch. This will be the
140
# starting point when looking for a free column.
143
if len(branch_id) > 1:
144
parent_revno = branch_id[0:-1]
145
if parent_revno in revno_index:
146
parent_index = revno_index[parent_revno]
147
parent_node = linegraph[parent_index][1]
149
parent_col_index = parent_node[0]
152
col_search_order = _branch_line_col_search_order(columns,
154
color = reduce(lambda x, y: x+y, branch_id, 0)
158
last_rev_index = None
159
for rev_index in branch_line:
161
if broken_line_length and \
162
rev_index - last_rev_index > broken_line_length:
163
line_range.append(last_rev_index+1)
164
line_range.append(rev_index-1)
166
line_range.extend(range(last_rev_index+1, rev_index))
168
line_range.append(rev_index)
169
last_rev_index = rev_index
172
if broken_line_length and \
173
parent_index - last_rev_index > broken_line_length:
174
line_range.append(last_rev_index+1)
176
line_range.extend(range(last_rev_index+1, parent_index))
178
col_index = _find_free_column(columns,
182
node = (col_index, color)
183
for rev_index in branch_line:
184
linegraph[rev_index][1] = node
185
columns[col_index][rev_index] = True
187
for rev_index in branch_line:
192
end_of_merge) = merge_sorted_revisions[rev_index]
194
linegraph[rev_index][4] = graph_children[revid]
195
col_index = linegraph[rev_index][1][0]
197
for parent_revid in graph_parents[revid]:
198
if parent_revid in revid_index:
200
parent_index = revid_index[parent_revid]
200
201
parent_node = linegraph[parent_index][1]
202
203
parent_col_index = parent_node[0]
205
col_search_order = _branch_line_col_search_order(columns,
207
color = reduce(lambda x, y: x+y, branch_id, 0)
211
last_rev_index = None
212
for rev_index in branch_line:
214
if broken_line_length and \
215
rev_index - last_rev_index > broken_line_length:
216
line_range.append(last_rev_index+1)
217
line_range.append(rev_index-1)
219
line_range.extend(range(last_rev_index+1, rev_index))
221
line_range.append(rev_index)
222
last_rev_index = rev_index
225
if broken_line_length and \
226
parent_index - last_rev_index > broken_line_length:
227
line_range.append(last_rev_index+1)
229
line_range.extend(range(last_rev_index+1, parent_index))
231
col_index = _find_free_column(columns,
235
node = (col_index, color)
236
for rev_index in branch_line:
237
linegraph[rev_index][1] = node
238
columns[col_index][rev_index] = True
240
for rev_index in branch_line:
245
end_of_merge) = merge_sorted_revisions[rev_index]
247
linegraph[rev_index][4] = graph_children[revid]
248
col_index = linegraph[rev_index][1][0]
250
for parent_revid in graph_parents[revid]:
251
if parent_revid in revid_index:
253
parent_index = revid_index[parent_revid]
254
parent_node = linegraph[parent_index][1]
256
parent_col_index = parent_node[0]
258
parent_col_index = None
205
parent_col_index = None
207
_line_col_search_order(columns,
211
# If this line is really long, break it.
212
if len(branch_id) > 0 and \
213
broken_line_length and \
214
parent_index - rev_index > broken_line_length:
215
child_line_col_index = \
216
_find_free_column(columns,
220
_mark_column_as_used(columns,
221
child_line_col_index,
224
# Recall _line_col_search_order to reset it back to
259
226
col_search_order = \
260
227
_line_col_search_order(columns,
261
228
parent_col_index,
264
# If this line is really long, break it.
265
if len(branch_id) > 0 and \
266
broken_line_length and \
267
parent_index - rev_index > broken_line_length:
268
child_line_col_index = \
269
_find_free_column(columns,
273
_mark_column_as_used(columns,
274
child_line_col_index,
277
# Recall _line_col_search_order to reset it back to
280
_line_col_search_order(columns,
283
parent_col_line_index = \
284
_find_free_column(columns,
288
_mark_column_as_used(columns,
289
parent_col_line_index,
291
lines.append((rev_index,
293
(child_line_col_index,
294
parent_col_line_index)))
296
line_col_index = col_index
297
if parent_index - rev_index >1:
298
line_range = range(rev_index + 1, parent_index)
300
_find_free_column(columns,
304
_mark_column_as_used(columns,
307
lines.append((rev_index,
311
progress_bar.finished()
230
parent_col_line_index = \
231
_find_free_column(columns,
235
_mark_column_as_used(columns,
236
parent_col_line_index,
238
lines.append((rev_index,
240
(child_line_col_index,
241
parent_col_line_index)))
243
line_col_index = col_index
244
if parent_index - rev_index >1:
245
line_range = range(rev_index + 1, parent_index)
247
_find_free_column(columns,
251
_mark_column_as_used(columns,
254
lines.append((rev_index,
313
update_root_progress(5)
314
progress_bar = ui.ui_factory.nested_progress_bar()
316
progress_bar.update("Prettifying graph", 0, len(lines))
317
for i, (child_index, parent_index, line_col_indexes) in enumerate(lines):
319
progress_bar.update(None, i)
320
(child_col_index, child_color) = linegraph[child_index][1]
321
(parent_col_index, parent_color) = linegraph[parent_index][1]
323
if len(line_col_indexes) == 1:
324
if parent_index - child_index == 1:
325
linegraph[child_index][2].append(
330
# line from the child's column to the lines column
331
linegraph[child_index][2].append(
335
# lines down the line's column
336
for line_part_index in range(child_index+1, parent_index-1):
337
linegraph[line_part_index][2].append(
338
(line_col_indexes[0],
341
# line from the line's column to the parent's column
342
linegraph[parent_index-1][2].append(
343
(line_col_indexes[0],
258
for (child_index, parent_index, line_col_indexes) in lines:
259
(child_col_index, child_color) = linegraph[child_index][1]
260
(parent_col_index, parent_color) = linegraph[parent_index][1]
262
if len(line_col_indexes) == 1:
263
if parent_index - child_index == 1:
264
linegraph[child_index][2].append(
348
269
# line from the child's column to the lines column
349
270
linegraph[child_index][2].append(
350
271
(child_col_index,
351
272
line_col_indexes[0],
354
linegraph[child_index+1][2].append(
355
(line_col_indexes[0],
360
linegraph[parent_index-2][2].append(
274
# lines down the line's column
275
for line_part_index in range(child_index+1, parent_index-1):
276
linegraph[line_part_index][2].append(
277
(line_col_indexes[0],
364
280
# line from the line's column to the parent's column
365
281
linegraph[parent_index-1][2].append(
366
(line_col_indexes[1],
282
(line_col_indexes[0],
367
283
parent_col_index,
370
progress_bar.finished()
287
# line from the child's column to the lines column
288
linegraph[child_index][2].append(
293
linegraph[child_index+1][2].append(
294
(line_col_indexes[0],
299
linegraph[parent_index-2][2].append(
303
# line from the line's column to the parent's column
304
linegraph[parent_index-1][2].append(
305
(line_col_indexes[1],
371
308
return (linegraph, revid_index, len(columns))
373
310
return (linegraph, revid_index, 0)