Debian Codegraph @

lib/tests/test_loggraphviz.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2010 Gary van der Merwe <[email protected]>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 # RJLRJL a lot of the changes for breezy were changing strings to bytes
20
21 from breezy.tests import TestCase, TestCaseWithTransport
22 from io import StringIO
23
24 from breezy.plugins.qbrz.lib import loggraphviz
25 from breezy.revision import NULL_REVISION
26
27 # TODO:
28 # Tag loading
29 # Branch labels + Filtering
30 # Ghosts
31 # file_ids filtering
32
33 class TestLogGraphVizMixin(object):
34 def computed_to_list(self, computed, branch_labels=False):
35 if not branch_labels:
36 item = lambda c_rev: (c_rev.rev.revid,
37 c_rev.col_index,
38 c_rev.twisty_state,
39 sorted(c_rev.lines),)
40 else:
41 item = lambda c_rev: (c_rev.rev.revid,
42 c_rev.col_index,
43 c_rev.twisty_state,
44 sorted(c_rev.lines),
45 [label for bi, label in c_rev.branch_labels])
46
47 return [item(c_rev) for c_rev in computed.filtered_revs]
48
49 def assertComputed(self, expected_list, computed, branch_labels=False):
50 computed_list = self.computed_to_list(computed, branch_labels)
51 if not expected_list == computed_list:
52 raise AssertionError(
53 "not equal: \nexpected_list = \n%scomputed_list = \n%s"
54 % (format_graph_lines(expected_list, use_unicode=True),
55 format_graph_lines(computed_list, use_unicode=True),))
56
57
58 class TestLogGraphVizWithBranches(TestCaseWithTransport, TestLogGraphVizMixin):
59
60 def test_no_commits(self):
61 br = self.make_branch('.')
62
63 bi = loggraphviz.BranchInfo('', None, br)
64 gv = loggraphviz.GraphVizLoader([bi], bi, False)
65 gv.load()
66
67 self.assertEqual(len(gv.revisions), 0)
68
69 state = loggraphviz.GraphVizFilterState(gv)
70 computed = gv.compute_viz(state)
71 self.assertEqual(len(computed.revisions), 0)
72
73 def make_banches_for_tips_date_sorted(self):
74 builder = self.make_branch_builder('trunk')
75 builder.start_series()
76 rev_a = builder.build_snapshot(None, [('add', ('', b'TREE_ROOT', 'directory', b'')),])
77 rev_old = builder.build_snapshot([rev_a], [])
78 rev_new = builder.build_snapshot([rev_a], [])
79 rev_trunk = builder.build_snapshot([rev_a], [])
80 builder.finish_series()
81
82 trunk = builder.get_branch()
83 #trunk.set_last_revision('rev-trunk')
84
85 old = trunk.controldir.sprout('../old', revision_id=rev_old).open_branch()
86
87 new = trunk.controldir.sprout('../new', revision_id=rev_new).open_branch()
88
89 return rev_a, trunk, old, new
90
91 def test_branch_tips_date_sorted(self):
92 common_rev, trunk, old, new = self.make_banches_for_tips_date_sorted()
93
94 trunk_bi = loggraphviz.BranchInfo('trunk', None, trunk)
95 gv = loggraphviz.GraphVizLoader(
96 [trunk_bi,
97 loggraphviz.BranchInfo('old', None, old),
98 loggraphviz.BranchInfo('new', None, new),],
99 trunk_bi, False)
100 gv.load()
101
102 state = loggraphviz.GraphVizFilterState(gv)
103 computed = gv.compute_viz(state)
104
105 self.assertComputed(
106 [(new.last_revision(), 2, None, [(2, 2, 0, True)]) , # ○
107 # │
108 (old.last_revision(), 1, None, [(1, 1, 0, True), (2, 2, 0, True)]), # ○ │
109 # │ │
110 (trunk.last_revision(), 0, None, [(0, 0, 0, True), (1, 0, 0, True), # ○ │ │
111 (2, 0, 0, True)]), # ├─╯─╯
112 (common_rev, 0, None, []) ],# ○
113 computed)
114
115 def test_branch_tips_date_sorted_with_working_tree_provider(self):
116 common_rev, trunk, old, new = self.make_banches_for_tips_date_sorted()
117 trunk_tree = trunk.controldir.create_workingtree()
118 old_tree = old.controldir.open_workingtree()
119 new_tree = new.controldir.open_workingtree()
120
121 trunk_bi = loggraphviz.BranchInfo('trunk', trunk_tree, trunk)
122 gv = loggraphviz.WithWorkingTreeGraphVizLoader(
123 [trunk_bi,
124 loggraphviz.BranchInfo('old', old_tree, old),
125 loggraphviz.BranchInfo('new', new_tree, new),],
126 trunk_bi, False)
127 gv.load()
128
129 state = loggraphviz.GraphVizFilterState(gv)
130 computed = gv.compute_viz(state)
131
132 self.assertComputed(
133 [(gv.tree_revid(new_tree), 2, None, [(2, 2, 3, True)]), # ○
134 # │
135 (new.last_revision(), 2, None, [(2, 2, 0, True)]), # ○
136 # │
137 (gv.tree_revid(old_tree), 1, None, [(1, 1, 2, True), # ○ │
138 (2, 2, 0, True)]), # │ │
139 (old.last_revision(), 1, None, [(1, 1, 0, True), (2, 2, 0, True)]), # ○ │
140 # │ │
141 (gv.tree_revid(trunk_tree), 0, None, [ # ○ │ │
142 (0, 0, 0, True), (1, 1, 0, True), (2, 2, 0, True)]), # │ │ │
143 (trunk.last_revision(), 0, None, [(0, 0, 0, True), (1, 0, 0, True), # ○ │ │
144 (2, 0, 0, True)]), # ├─╯─╯
145 (common_rev, 0, None, [])], # ○
146 computed)
147
148
149 def make_tree_with_pending_merge(self, path):
150 builder = self.make_branch_builder('branch')
151 builder.start_series()
152 rev_a = builder.build_snapshot(None, [('add', ('', b'TREE_ROOT', 'directory', b'')),])
153 rev_b = builder.build_snapshot([rev_a], [])
154 builder.finish_series()
155
156 branch = builder.get_branch()
157 branch.set_last_revision_info(1, rev_a) # go back to rev-a
158 tree = branch.controldir.create_workingtree()
159 tree.merge_from_branch(branch, to_revision=rev_b)
160 # RJLRJL WARNING, tree's basedir will be of type str!
161 return tree, [rev_a, rev_b]
162
163 def make_tree_not_up_to_date(self, path):
164 builder = self.make_branch_builder('branch')
165 builder.start_series()
166 rev_a = builder.build_snapshot(None, [('add', ('', b'TREE_ROOT', 'directory', b'')),])
167 rev_b = builder.build_snapshot([rev_a], [])
168 builder.finish_series()
169
170 branch = builder.get_branch()
171 tree = branch.controldir.create_workingtree()
172 tree.update(revision=rev_a)
173 return tree, [rev_a, rev_b]
174
175 def test_pending_merge(self):
176 tree, [rev_a, rev_b] = self.make_tree_with_pending_merge('branch')
177
178 bi = loggraphviz.BranchInfo(None, tree, tree.branch)
179 gv = loggraphviz.GraphVizLoader([bi], bi, False)
180 gv.load()
181
182 state = loggraphviz.GraphVizFilterState(gv)
183 computed = gv.compute_viz(state)
184
185 self.assertComputed(
186 [(rev_b, 1, None, [(1, 0, 0, True)], ['Pending Merge']), # ○
187 # ╭─╯
188 (rev_a, 0, None, [], [None]) ],# ○
189 computed, branch_labels=True)
190
191 def test_out_of_date_wt(self):
192 tree, [rev_a, rev_b] = self.make_tree_not_up_to_date('branch')
193 bi = loggraphviz.BranchInfo(None, tree, tree.branch)
194 gv = loggraphviz.GraphVizLoader([bi], bi, False)
195 gv.load()
196
197 state = loggraphviz.GraphVizFilterState(gv)
198 computed = gv.compute_viz(state)
199
200 self.assertComputed(
201 [(rev_b, 0, None, [(0, 0, 0, True)], [None]), # ○
202 # │
203 (rev_a, 0, None, [], ['Working Tree']) ],# ○
204 computed, branch_labels=True)
205
206 def test_with_working_tree_provider(self):
207 # RJLRJL tree.basedir seems to come back as a string here...
208 tree, [rev_a, rev_b] = self.make_tree_with_pending_merge('branch')
209
210 bi = loggraphviz.BranchInfo('branch', tree, tree.branch)
211 gv = loggraphviz.WithWorkingTreeGraphVizLoader([bi], bi, False)
212 gv.load()
213
214 state = loggraphviz.GraphVizFilterState(gv)
215 computed = gv.compute_viz(state)
216
217 # RJLRL Force 'current...' string to bytes
218 self.assertComputed(
219 [(bytes('current:%s' % tree.basedir, 'utf-8'), 0, True, # ⊖
220 [(0, 0, 0, True), (0, 1, 2, True)], # ├─╮
221 ['branch - Working Tree']), # │ │
222 (rev_b, 1, None, [(0, 0, 0, True), (1, 0, 0, True)], # │ ○
223 ['branch - Pending Merge']), # ├─╯
224 (rev_a, 0, None, [], ['branch'])], # ○
225 computed, branch_labels=True)
226
227 def test_with_working_tree_provider_out_of_date_wt(self):
228 tree, [rev_a, rev_b] = self.make_tree_not_up_to_date('branch')
229 bi = loggraphviz.BranchInfo('branch', tree, tree.branch)
230 gv = loggraphviz.WithWorkingTreeGraphVizLoader([bi], bi, False)
231 gv.load()
232
233 state = loggraphviz.GraphVizFilterState(gv)
234 computed = gv.compute_viz(state)
235
236 self.assertComputed(
237 [(bytes('current:%s' % tree.basedir, 'utf-8'), 1, None, [(1, 1, 0, True)], # ○
238 ['branch - Working Tree']), # │
239 (rev_b, 0, None, [(0, 0, 0, True), (1, 0, 0, True)], # ○ │
240 ['branch']), # ├─╯
241 (rev_a, 0, None, [], []) ], # ○
242 computed, branch_labels=True)
243
244 def test_with_working_tree_provider_filtered(self):
245 # This test makes sure that label for a Working Tree shows for on it's
246 # nearest visble unique ansestor when the working tree node is
247 # filtered.
248 builder = self.make_branch_builder('branch')
249 builder.start_series()
250 rev_a = builder.build_snapshot(None, [('add', ('', b'TREE_ROOT', 'directory', b'')),])
251 rev_b = builder.build_snapshot([rev_a], [])
252 rev_c = builder.build_snapshot([rev_a], [])
253 builder.finish_series()
254
255 branch = builder.get_branch()
256 tree = branch.controldir.create_workingtree()
257 tree.update(revision=rev_b)
258
259 bi = loggraphviz.BranchInfo('branch', tree, tree.branch)
260 gv = loggraphviz.WithWorkingTreeGraphVizLoader([bi], bi, False)
261 gv.load()
262
263 state = loggraphviz.GraphVizFilterState(gv)
264 # state.filters.append(BasicFilterer(set(['current:%s' % tree.basedir.encode('unicode-escape')])))
265 state.filters.append(BasicFilterer(set([bytes('current:%s' % tree.basedir, 'utf-8')])))
266 computed = gv.compute_viz(state)
267 self.assertComputed(
268 [(rev_b, 1, None, [(1, 1, 0, True)], ['branch - Working Tree']) , # ○
269 # │
270 (rev_c, 0, None, [(0, 0, 0, True), (1, 0, 0, True)], ['branch']), # ○ │
271 # ├─╯
272 (rev_a, 0, None, [], []) ],# ○
273 computed, branch_labels=True)
274
275 def test_pending_merges_provider(self):
276 tree, [rev_a, rev_b] = self.make_tree_with_pending_merge('branch')
277
278 bi = loggraphviz.BranchInfo(None, tree, tree.branch)
279 gv = loggraphviz.PendingMergesGraphVizLoader([bi], bi, False)
280 gv.load()
281
282 state = loggraphviz.GraphVizFilterState(gv)
283 computed = gv.compute_viz(state)
284
285 self.assertComputed(
286 [(rev_b, 1, None, [(1, 0, 0, True)]), # ○
287 # ╭─╯
288 ('root:', 0, None, []) ],# ○
289 computed)
290
291 def test_with_ghost(self):
292 tree = self.make_branch_and_tree('tree')
293 rev_a = tree.commit('a')
294 tree.add_parent_tree_id(b'rev-b')
295 rev_c = tree.commit('c')
296 # rev-b is a ghost. We think he is there, but he dose not exist. Boo!
297
298 bi = loggraphviz.BranchInfo(None, tree, tree.branch)
299 gv = loggraphviz.GraphVizLoader([bi], bi, False)
300 gv.load()
301
302 state = loggraphviz.GraphVizFilterState(gv)
303 state.expand_all_branch_lines()
304 computed = gv.compute_viz(state)
305
306 self.assertComputed(
307 [(rev_c, 0, True, [(0, 0, 0, True), (0, 1, 1, True)]), # ⊖
308 # ├─╮
309 (b'rev-b', 1, None, [(0, 0, 0, True)]) , # │ ○
310 # │
311 (rev_a, 0, None, []) ],# ○
312 computed)
313
314 def test_with_ghost_mainline(self):
315 tree = self.make_branch_and_tree('tree')
316 tree.add_parent_tree_id(b'rev-a', allow_leftmost_as_ghost=True)
317 rev_b = tree.commit('b')
318
319 bi = loggraphviz.BranchInfo(None, tree, tree.branch)
320 gv = loggraphviz.GraphVizLoader([bi], bi, False)
321 gv.load()
322
323 state = loggraphviz.GraphVizFilterState(gv)
324 computed = gv.compute_viz(state)
325
326 self.assertComputed(
327 [(rev_b, 0, None, [(0, 0, 0, True)]), # ○
328 # │
329 (b'rev-a', 0, None, []) ],# ○
330 computed)
331
332 def test_get_revid_branch_info(self):
333 builder = self.make_branch_builder('trunk')
334 builder.start_series()
335 rev_a = builder.build_snapshot(None, [('add', ('', b'TREE_ROOT', 'directory', b'')),])
336 rev_branch = builder.build_snapshot([rev_a], [])
337 rev_trunk = builder.build_snapshot([rev_a], [])
338 builder.finish_series()
339 # ○ branch
340 # │
341 # ○ │ trunk
342 # ├─╯
343 # ○ rev-a
344
345 trunk = builder.get_branch()
346 #trunk.set_last_revision(rev_trunk)
347
348 branch = trunk.controldir.sprout('../branch', revision_id=rev_branch).open_branch()
349
350 trunk_bi = loggraphviz.BranchInfo('trunk', None, trunk)
351 branch_bi = loggraphviz.BranchInfo('branch', None, branch)
352 gv = loggraphviz.GraphVizLoader(
353 [trunk_bi, branch_bi],
354 trunk_bi, False)
355 gv.load()
356
357 self.assertEqual(trunk_bi, gv.get_revid_branch_info(rev_trunk))
358 self.assertEqual(branch_bi, gv.get_revid_branch_info(rev_branch))
359
360 # may return either
361 self.assertIn(gv.get_revid_branch_info(rev_a),
362 (branch_bi, trunk_bi))
363
364 def test_get_revid_branch_info_with_ghost(self):
365 tree = self.make_branch_and_tree('tree')
366 rev_a = tree.commit('a')
367 tree.add_parent_tree_id(b'rev-b')
368 rev_c = tree.commit('c')
369 # rev-b is a ghost. We think he is there, but he does not exist. Boo!
370 # c
371 # ├─╮
372 # │ b
373 # │
374 # a
375
376 bi = loggraphviz.BranchInfo(None, tree, tree.branch)
377 gv = loggraphviz.GraphVizLoader([bi], bi, False)
378 gv.load()
379
380 self.assertRaises(loggraphviz.GhostRevisionError, gv.get_revid_branch_info, b'rev-b')
381
382
383 class TestLogGraphVizLayouts(TestCase, TestLogGraphVizMixin):
384
385 def test_basic_branch_line(self):
386 gv = BasicGraphVizLoader(('rev-d',), {
387 'rev-a': (NULL_REVISION, ),
388 'rev-b': ('rev-a', ),
389 'rev-c': ('rev-a', ),
390 'rev-d': ('rev-b', 'rev-c'),
391 })
392 gv.load()
393
394 state = loggraphviz.GraphVizFilterState(gv)
395 computed = gv.compute_viz(state)
396
397 # only mainline.
398 self.assertComputed(
399 [('rev-d', 0, False, [(0, 0, 0, True)]), # ⊕
400 # │
401 ('rev-b', 0, None, [(0, 0, 0, True)]) , # ○
402 # │
403 ('rev-a', 0, None, []) ],# ○
404 computed)
405
406 state.collapse_expand_rev(computed.filtered_revs[0])
407 computed = gv.compute_viz(state)
408
409 # expanded branch line.
410 self.assertComputed(
411 [('rev-d', 0, True, [(0, 0, 0, True), (0, 1, 2, True)]), # ⊖
412 # ├─╮
413 ('rev-c', 1, None, [(0, 0, 0, True), (1, 1, 0, True)]), # │ ○
414 # │ │
415 ('rev-b', 0, None, [(0, 0, 0, True), (1, 0, 0, True)]), # ○ │
416 # ├─╯
417 ('rev-a', 0, None, []) ],# ○
418 computed)
419
420 def test_branch_line_order(self):
421 gv = BasicGraphVizLoader(('rev-f',), {
422 'rev-a': (NULL_REVISION, ),
423 'rev-b': ('rev-a', ),
424 'rev-c': ('rev-b', ),
425 'rev-d': ('rev-a', 'rev-c'),
426 'rev-e': ('rev-b', ),
427 'rev-f': ('rev-d', 'rev-e' ),
428 })
429 gv.load()
430
431 state = loggraphviz.GraphVizFilterState(gv)
432 state.expand_all_branch_lines()
433 computed = gv.compute_viz(state)
434
435 # branch lines should not cross over
436 self.assertComputed(
437 [('rev-f', 0, True, [(0, 0, 0, True), (0, 2, 3, True)]) , # ⊖
438 # ├───╮
439 ('rev-e', 2, True, [(0, 0, 0, True), (2, 2, 2, True)]) , # │ ⊖
440 # │ │
441 ('rev-d', 0, True, [(0, 0, 0, True), (0, 1, 2, True), (2, 2, 2, True)]), # ⊖ │
442 # ├─╮ │
443 ('rev-c', 1, None, [(0, 0, 0, True), (1, 1, 2, True), (2, 1, 2, True)]), # │ ○ │
444 # │ ├─╯
445 ('rev-b', 1, None, [(0, 0, 0, True), (1, 0, 0, True)]) , # │ ○
446 # ├─╯
447 ('rev-a', 0, None, []) ],# ○
448 computed)
449
450 def test_branch_line_order2(self):
451 gv = BasicGraphVizLoader(('rev-h',), {
452 'rev-a': (NULL_REVISION, ),
453 'rev-b': ('rev-a', ),
454 'rev-c': ('rev-b', ),
455 'rev-d': ('rev-a', ),
456 'rev-e': ('rev-d', 'rev-b' ),
457 'rev-f': ('rev-e', ),
458 'rev-g': ('rev-e', 'rev-f' ),
459 'rev-h': ('rev-c', 'rev-g' ),
460 })
461 gv.load()
462
463 state = loggraphviz.GraphVizFilterState(gv)
464 state.expand_all_branch_lines()
465 computed = gv.compute_viz(state)
466
467 # branch lines should not cross over
468 self.assertComputed(
469 [('rev-h', 0, True, [(0, 0, 0, True), (0, 2, 2, True)]) , # ⊖
470 # ├───╮
471 ('rev-g', 2, True, [(0, 0, 0, True), (2, 2, 2, True), (2, 3, 3, True)]), # │ ⊖
472 # │ ├─╮
473 ('rev-f', 3, None, [(0, 0, 0, True), (2, 2, 2, True), (3, 2, 2, True)]), # │ │ ○
474 # │ ├─╯
475 ('rev-e', 2, None, [(0, 0, 0, True), (2, 1, 0, True), (2, 2, 2, True)]), # │ ○
476 # │ ╭─┤
477 ('rev-d', 2, None, [(0, 0, 0, True), (1, 1, 0, True), (2, 2, 0, True)]), # │ │ ○
478 # │ │ │
479 ('rev-c', 0, None, [(0, 0, 0, True), (1, 0, 0, True), (2, 2, 0, True)]), # ○ │ │
480 # ├─╯ │
481 ('rev-b', 0, None, [(0, 0, 0, True), (2, 0, 0, True)]) , # ○ │
482 # ├───╯
483 ('rev-a', 0, None, []) ],# ○
484 computed)
485
486 def test_octopus_merge(self):
487 gv = BasicGraphVizLoader(('rev-e',), {
488 'rev-a': (NULL_REVISION, ),
489 'rev-b': ('rev-a', ),
490 'rev-c': ('rev-a', ),
491 'rev-d': ('rev-a', ),
492 'rev-e': ('rev-a', 'rev-b', 'rev-c', 'rev-d'),
493 })
494 gv.load()
495
496 state = loggraphviz.GraphVizFilterState(gv)
497 state.expand_all_branch_lines()
498 computed = gv.compute_viz(state)
499
500 self.assertComputed(
501 [('rev-e', 0, True, [(0, 0, 0, True), (0, 1, 2, True), (0, 2, 3, True), (0, 3, 4, True)]), # ⊖
502 # ├─╮─╮─╮
503 ('rev-b', 3, None, [(0, 0, 0, True), (1, 1, 2, True), (2, 2, 3, True), (3, 3, 0, True)]), # │ │ │ ○
504 # │ │ │ │
505 ('rev-c', 2, None, [(0, 0, 0, True), (1, 1, 2, True), (2, 2, 0, True), (3, 3, 0, True)]), # │ │ ○ │
506 # │ │ │ │
507 ('rev-d', 1, None, [(0, 0, 0, True), (1, 0, 0, True), (2, 0, 0, True), (3, 0, 0, True)]), # │ ○ │ │
508 # ├─╯─╯─╯
509 ('rev-a', 0, None, []) ],# ○
510 computed)
511
512 def test_lots_of_merges_between_branch_lines(self):
513 gv = BasicGraphVizLoader(('rev-g',), {
514 'rev-a': (NULL_REVISION, ),
515 'rev-b': ('rev-a', ),
516 'rev-c': ('rev-b', ),
517 'rev-d': ('rev-a', ),
518 'rev-e': ('rev-d', 'rev-b',),
519 'rev-f': ('rev-e', 'rev-c',),
520 'rev-g': ('rev-c', 'rev-f',),
521 })
522 gv.load()
523
524 state = loggraphviz.GraphVizFilterState(gv)
525 state.expand_all_branch_lines()
526 computed = gv.compute_viz(state)
527
528 self.assertComputed(
529 [('rev-g', 0, True, [(0, 0, 0, True), (0, 2, 2, True)]) , # ⊖
530 # ├───╮
531 ('rev-f', 2, None, [(0, 0, 0, True), (2, 0.75, 0, True), (2, 2, 2, True)]) , # │ ○
532 # │ ╭─┤
533 ('rev-e', 2, None, [(0, 0, 0, True), (0.75, 0.75, 0, True), (2, 1.25, 0, True), (2, 2, 2, True)]), # │ │ ○
534 # │ ├─┤
535 ('rev-d', 2, None, [(0, 0, 0, True), (0.75, 0, 0, True), (1.25, 1.25, 0, True), (2, 2, 0, True)]), # │ │ ○
536 # ├─┤ │
537 ('rev-c', 0, None, [(0, 0, 0, True), (1.25, 0, 0, True), (2, 2, 0, True)]) , # ○ │ │
538 # ├─╯ │
539 ('rev-b', 0, None, [(0, 0, 0, True), (2, 0, 0, True)]) , # ○ │
540 # ├───╯
541 ('rev-a', 0, None, []) ],# ○
542 computed)
543
544 def test_hidden_branch_line_hides_child_line(self):
545 gv = BasicGraphVizLoader(('rev-g',), {
546 'rev-a': (NULL_REVISION, ),
547 'rev-b': ('rev-a', ),
548 'rev-c': ('rev-a', ),
549 'rev-d': ('rev-b', 'rev-c', ),
550 'rev-e': ('rev-b', 'rev-d', ),
551 'rev-f': ('rev-c', ),
552 'rev-g': ('rev-e', 'rev-f', ),
553 })
554 gv.load()
555
556 state = loggraphviz.GraphVizFilterState(gv)
557 state.branch_line_state[(2, 1)] = None
558 computed = gv.compute_viz(state)
559
560 self.assertComputed(
561 [('rev-g', 0, False, [(0, 0, 0, True)]) , # ⊕
562 # │
563 ('rev-e', 0, True, [(0, 0, 0, True), (0, 1, 3, True)]) , # ⊖
564 # ├─╮
565 ('rev-d', 1, False, [(0, 0, 0, True), (1, 0, 0, True)]), # │ ⊕
566 # ├─╯
567 ('rev-b', 0, None, [(0, 0, 0, True)]) , # ○
568 # │
569 ('rev-a', 0, None, []) ],# ○
570 computed)
571
572 def test_merge_line_hidden(self):
573 gv = BasicGraphVizLoader(('rev-d',), {
574 'rev-a': (NULL_REVISION, ),
575 'rev-b': ('rev-a', ),
576 'rev-c': ('rev-a', 'rev-b'),
577 'rev-d': ('rev-a', 'rev-c'),
578 })
579 # d
580 # ├─╮
581 # │ c
582 # │ ├─╮
583 # │ │ b
584 # ├─╯─╯
585 # a
586 gv.load()
587
588 state = loggraphviz.GraphVizFilterState(gv)
589 state.branch_line_state[(1, 1)] = None
590
591 computed = gv.compute_viz(state)
592 # when the merge by branch line, we should show a non direct line
593 self.assertComputed(
594 [('rev-d', 0, False, [(0, 0, 0, True), (0, 1, 2, False)]), # ⊕
595 # ├┄╮
596 ('rev-b', 1, None, [(0, 0, 0, True), (1, 0, 0, True)]) , # │ ○
597 # ├─╯
598 ('rev-a', 0, None, []) ],# ○
599 computed)
600
601 def test_merge_line_hidden2(self):
602 gv = BasicGraphVizLoader(('rev-e',), {
603 'rev-a': (NULL_REVISION, ),
604 'rev-z': ('rev-a', ),
605 'rev-y': ('rev-a', 'rev-z', ),
606 'rev-b': ('rev-a', ),
607 'rev-c': ('rev-a', ),
608 'rev-d': ('rev-a', 'rev-c'),
609 'rev-e': ('rev-y', 'rev-b', 'rev-d'),
610 })
611 # f
612 # ├─╮─╮
613 # │ b │
614 # │ │ │
615 # │ │ e
616 # │ │ ├─╮
617 # │ │ │ d
618 # ├─╯─╯─╯
619 # a
620 gv.load()
621
622 state = loggraphviz.GraphVizFilterState(gv)
623 #state.expand_all_branch_lines()
624 state.branch_line_state[(1, 1)] = None
625 state.branch_line_state[(1, 2)] = None
626 #state.branch_line_state[(1, 3)] = None
627 state.branch_line_state[(1, 4)] = None
628
629 computed = gv.compute_viz(state)
630 # when the merge by branch line, we should show a non direct line
631 # this could layout better, but that's another story...
632 self.assertComputed(
633 [('rev-e', 0, False, [(0, 0, 0, True), (0, 1, 3, False), (0, 2, 5, True)]) , # ⊕
634 # ├┄╮─╮
635 ('rev-b', 2, None, [(0, 0, 0, True), (1, 3, 3, False), (2, 2, 0, True)]) , # │ ┆ ○
636 # │ ╰┄┼┄╮
637 ('rev-c', 3, None, [(0, 0, 0, True), (2, 2, 0, True), (3, 3, 0, True)]) , # │ │ ○
638 # │ │ │
639 ('rev-y', 0, True, [(0, 0, 0, True), (0, 1, 2, True), (2, 2, 0, True), (3, 3, 0, True)]), # ⊖ │ │
640 # ├─╮ │ │
641 ('rev-z', 1, None, [(0, 0, 0, True), (1, 0, 0, True), (2, 0, 0, True), (3, 0, 0, True)]), # │ ○ │ │
642 # ├─╯─╯─╯
643 ('rev-a', 0, None, []) ],# ○
644 computed)
645
646 def test_merge_line_hidden_merge_rev_filtered(self):
647 gv = BasicGraphVizLoader(('rev-e',), {
648 'rev-a': (NULL_REVISION, ),
649 'rev-b': ('rev-a', ),
650 'rev-c': ('rev-b', ),
651 'rev-d': ('rev-a', 'rev-c'),
652 'rev-e': ('rev-a', 'rev-d'),
653 })
654 gv.load()
655
656 state = loggraphviz.GraphVizFilterState(gv)
657 state.filters.append(BasicFilterer(set(['rev-c'])))
658 state.branch_line_state[(1, 1)] = None
659
660 computed = gv.compute_viz(state)
661
662 # when the merge by branch line, we should show a non direct line
663 self.assertComputed(
664 [('rev-e', 0, False, [(0, 0, 0, True), (0, 1, 2, False)]), # ⊕
665 # ├┄╮
666 ('rev-b', 1, None, [(0, 0, 0, True), (1, 0, 0, True)]) , # │ ○
667 # ├─╯
668 ('rev-a', 0, None, []) ],# ○
669 computed)
670
671 def test_non_direct_hidden_branch(self):
672 gv = BasicGraphVizLoader(('rev-f',), {
673 'rev-a': (NULL_REVISION, ),
674 'rev-b': ('rev-a', ),
675 'rev-c': ('rev-b', ),
676 'rev-d': ('rev-a', 'rev-c', ),
677 'rev-e': ('rev-b', ),
678 'rev-f': ('rev-d', 'rev-e', ),
679 })
680 gv.load()
681
682 state = loggraphviz.GraphVizFilterState(gv)
683 state.branch_line_state[(1, 2)] = None
684
685 computed = gv.compute_viz(state)
686
687 self.assertComputed(
688 [('rev-f', 0, True, [(0, 0, 0, True), (0, 1, 3, True)]) , # ⊖
689 # ├─╮
690 ('rev-e', 1, False, [(0, 0, 0, True), (1, 1, 0, False)]), # │ ⊕
691 # │ ┆
692 ('rev-d', 0, False, [(0, 0, 0, True), (1, 0, 0, False)]), # ⊕ ┆
693 # ├┄╯
694 ('rev-a', 0, None, []) ],# ○
695 computed)
696
697 def test_non_direct_hidden_parent(self):
698 gv = BasicGraphVizLoader(('rev-e',), {
699 'rev-a': (NULL_REVISION, ),
700 'rev-b': ('rev-a', ),
701 'rev-c': ('rev-b', ),
702 'rev-d': ('rev-a', 'rev-c'),
703 'rev-e': ('rev-a', 'rev-d'),
704 })
705 gv.load()
706
707 state = loggraphviz.GraphVizFilterState(gv)
708 state.filters.append(BasicFilterer(set(['rev-c'])))
709 state.expand_all_branch_lines()
710
711 computed = gv.compute_viz(state)
712
713 self.assertComputed(
714 [('rev-e', 0, True, [(0, 0, 0, True), (0, 1, 3, True)]) , # ⊖
715 # ├─╮
716 ('rev-d', 1, True, [(0, 0, 0, True), (1, 1, 0, True), (1, 2, 2, False)]), # │ ⊖
717 # │ ├┄╮
718 ('rev-b', 2, None, [(0, 0, 0, True), (1, 0, 0, True), (2, 0, 0, True)]) , # │ │ ○
719 # ├─╯─╯
720 ('rev-a', 0, None, []) ],# ○
721 computed)
722
723 def test_no_graph(self):
724 gv = BasicGraphVizLoader(('rev-d',), {
725 'rev-a': (NULL_REVISION, ),
726 'rev-b': ('rev-a', ),
727 'rev-c': ('rev-a', ),
728 'rev-d': ('rev-b', 'rev-c'),
729 }, no_graph=True)
730 gv.load()
731
732 state = loggraphviz.GraphVizFilterState(gv)
733 computed = gv.compute_viz(state)
734 self.assertComputed(
735 [('rev-d', 0.0, None, []), # ○
736 #
737 ('rev-c', 0.5, None, []), # ○
738 #
739 ('rev-b', 0.0, None, []), # ○
740 #
741 ('rev-a', 0.0, None, [])],# ○
742 computed)
743
744 def test_no_graph_filtered(self):
745 gv = BasicGraphVizLoader(('rev-d',), {
746 'rev-a': (NULL_REVISION, ),
747 'rev-b': ('rev-a', ),
748 'rev-c': ('rev-a', ),
749 'rev-d': ('rev-b', 'rev-c'),
750 }, no_graph=True)
751 gv.load()
752
753 state = loggraphviz.GraphVizFilterState(gv)
754 state.filters.append(BasicFilterer(set(['rev-b'])))
755 computed = gv.compute_viz(state)
756 self.assertComputed(
757 [('rev-d', 0.0, None, []), # ○
758 #
759 ('rev-c', 0.5, None, []), # ○
760 #
761 ('rev-a', 0.0, None, [])],# ○
762 computed)
763
764 class TestLogGraphProviderState(TestCase):
765
766 def assertFilteredRevisions(self, expected_revids, state):
767 revids = [rev.revid for rev in state.get_filtered_revisions()]
768 self.assertEqual(list(expected_revids), revids)
769
770 def test_collapse_expand_rev_basic(self):
771 gv = BasicGraphVizLoader(('c',), {
772 'a': (NULL_REVISION, ),
773 'b': ('a', ),
774 'c': ('a', 'b'),
775 })
776 gv.load()
777 # c
778 # ├─╮
779 # │ b
780 # ├─╯
781 # a
782
783 state = loggraphviz.GraphVizFilterState(gv)
784
785 # just mainline showing
786 self.assertFilteredRevisions('ca', state)
787
788 # bla - we need a computed to call collapse_expand_rev
789 # expand 'c'
790 state.collapse_expand_rev(gv.compute_viz(state).filtered_revs[0])
791
792 # all should be showing
793 self.assertFilteredRevisions('cba', state)
794
795 # colapse 'c'
796 state.collapse_expand_rev(gv.compute_viz(state).filtered_revs[0])
797
798 # just mainline showing
799 self.assertFilteredRevisions('ca', state)
800
801 def get_expanded_by_graph_provider(self):
802 gv = BasicGraphVizLoader(('f',), {
803 'a': (NULL_REVISION, ),
804 'b': ('a', ),
805 'c': ('a', 'b'),
806 'd': ('a', 'c', ),
807 'e': ('b', ),
808 'f': ('d', 'e')
809 })
810 gv.load()
811 # f
812 # ├───╮
813 # │ e
814 # │ │
815 # d │
816 # ├─╮ │
817 # │ c │
818 # │ │\│
819 # │ │ b
820 # ├─╯─╯
821 # a
822 return gv
823
824 def test_collapse_colapses_sub_expand(self):
825 gv = self.get_expanded_by_graph_provider()
826
827 state = loggraphviz.GraphVizFilterState(gv)
828 # just mainline showing
829 self.assertFilteredRevisions('fda', state)
830
831 # expand 'd'
832 state.collapse_expand_rev(gv.compute_viz(state).revisions[2])
833 # branchline c now showing
834 self.assertFilteredRevisions('fdca', state)
835
836 # expand 'c'
837 state.collapse_expand_rev(gv.compute_viz(state).revisions[3])
838 # all showing
839 self.assertFilteredRevisions('fedcba', state)
840
841 # colapse 'd'
842 state.collapse_expand_rev(gv.compute_viz(state).filtered_revs[2])
843 # cause c expanded branchline eb, and d expanded c, d colapses
844 # just mainline showing
845 self.assertFilteredRevisions('fda', state)
846
847 def test_collapse_dosent_colapses_prev_expand(self):
848 gv = self.get_expanded_by_graph_provider()
849
850 state = loggraphviz.GraphVizFilterState(gv)
851 # just mainline showing
852 self.assertFilteredRevisions('fda', state)
853
854 # expand 'f'
855 state.collapse_expand_rev(gv.compute_viz(state).revisions[0])
856 # branchline eb now showing
857 self.assertFilteredRevisions('fedba', state)
858
859 # expand 'd'
860 state.collapse_expand_rev(gv.compute_viz(state).revisions[2])
861 # all showing
862 self.assertFilteredRevisions('fedcba', state)
863
864 # colapse 'd'
865 state.collapse_expand_rev(gv.compute_viz(state).filtered_revs[2])
866 # cause branchline eb was expanded by f, and not d, collapsing d dose
867 # not collapse branchline eb, even though it expanded it
868 # branchline eb and mainline left showing
869 self.assertFilteredRevisions('fedba', state)
870
871 def test_collapse_deep_expanded_by(self):
872 # This use to error at one point
873 gv = BasicGraphVizLoader(('g',), {
874 'a': (NULL_REVISION, ),
875 'b': ('a', ),
876 'c': ('a', 'b'),
877 'd': ('a', 'c', ),
878 'e': ('b', ),
879 'f': ('d', 'e'),
880 'g': ('a', 'f'),
881 })
882 # g v-----1.3
883 # ├─╮
884 # │ f v-1.1
885 # │ ├───╮
886 # │ │ e
887 # │ │ │
888 # │ d v-│-1.2
889 # │ ├─╮ │
890 # │ │ c │
891 # │ │ │\│
892 # │ │ │ b
893 # ├─╯─╯─╯
894 # a
895
896 gv.load()
897
898 state = loggraphviz.GraphVizFilterState(gv)
899 # just mainline showing
900 self.assertFilteredRevisions('ga', state)
901
902 # expand 'g'
903 state.collapse_expand_rev(gv.compute_viz(state).revisions[0])
904 # branchline fd now showing
905 self.assertFilteredRevisions('gfda', state)
906
907 # expand 'f'
908 state.collapse_expand_rev(gv.compute_viz(state).revisions[1])
909 # branchline eb now showing
910 self.assertFilteredRevisions('gfedba', state)
911
912 # expand 'd'
913 state.collapse_expand_rev(gv.compute_viz(state).revisions[3])
914 # branchline c now showing (all showing)
915 self.assertFilteredRevisions('gfedcba', state)
916
917 # colapse 'g'
918 state.collapse_expand_rev(gv.compute_viz(state).filtered_revs[0])
919 # back to just mainline showing
920 self.assertFilteredRevisions('ga', state)
921
922 def test_filter(self):
923 gv = BasicGraphVizLoader(('e',), {
924 'a': (NULL_REVISION, ),
925 'b': ('a', ),
926 'c': ('a', 'b'),
927 'd': ('c', ),
928 'e': ('d', ),
929 })
930 gv.load()
931 # e
932 # │
933 # d
934 # │
935 # c
936 # ├─╮
937 # │ b
938 # ├─╯
939 # a
940
941 state = loggraphviz.GraphVizFilterState(gv)
942
943 # expand 'c'
944 state.collapse_expand_rev(gv.compute_viz(state).filtered_revs[2])
945
946 # all should be showing
947 self.assertFilteredRevisions('edcba', state)
948
949 state.filters.append(BasicFilterer(('d', 'c', 'a')))
950 state.filter_changed()
951 # d and a not showing bucause of filter
952 # c shows even though it is filtered, because it merges a revision
953 # that is not filtered.
954 self.assertFilteredRevisions('ecb', state)
955
956
957
958 class BasicGraphVizLoader(loggraphviz.GraphVizLoader):
959
960 def __init__(self, heads, graph_dict, no_graph=False):
961 self.heads = heads
962 self.graph_dict = graph_dict
963 bi = loggraphviz.BranchInfo(None, None, None)
964 loggraphviz.GraphVizLoader.__init__(self, [bi], bi, no_graph)
965
966 def load(self):
967 for head in self.heads:
968 self.append_head_info(head, self.branches[0], head)
969
970 self.process_graph_parents(self.heads, list(self.graph_dict.items()))
971
972 self.compute_head_info()
973
974 if not self.no_graph:
975 self.compute_branch_lines()
976 self.compute_merge_info()
977
978
979 class BasicFilterer(object):
980 def __init__(self, filtered_revids):
981 self.filtered_revids = filtered_revids
982
983 def get_revision_visible(self, rev):
984 return rev.revid not in self.filtered_revids
985
986 def print_computed(computed):
987 print_lines([(c_rev.rev.revid,
988 c_rev.col_index,
989 c_rev.twisty_state,
990 c_rev.lines,)
991 for c_rev in computed.filtered_revs])
992
993 def print_lines(list):
994 print('')
995 print(format_graph_lines(list))
996
997 def format_graph_lines(list, use_unicode=True):
998 if not list:
999 return list.__repr__() + '\n'
1000 s = StringIO()
1001 item_repr = [item.__repr__() for item in list]
1002 repr_width = max([len(repr) for repr in item_repr])
1003 if use_unicode:
1004 twisty_char = {None: '○',
1005 True: '⊖',
1006 False: '⊕'}
1007 ver_char = {True: '│',
1008 False: '┆'}
1009
1010 hor_char = {True: {' ': '─',
1011 '│': '┼',
1012 '┆': '┼'},
1013 False: {' ': '┄',
1014 '│': '┼',
1015 '┆': '┼'}}
1016
1017 tl_char = {' ': '╭',
1018 '│': '├',
1019 '┆': '├',
1020 '─': '┬',
1021 '┄': '┬',
1022 '┴': '┼',
1023 '┤': '┼',}
1024
1025 tr_char = {' ': '╮',
1026 '│': '┤',
1027 '┆': '┤',
1028 '─': '┬',
1029 '┄': '┬',
1030 '┴': '┼',
1031 '├': '┼',}
1032
1033 bl_char = {' ': '╰',
1034 '│': '├',
1035 '┆': '├',
1036 '─': '┴',
1037 '┄': '┴',
1038 '┬': '┼',
1039 '┤': '┼',}
1040
1041 br_char = {' ': '╯',
1042 '│': '┤',
1043 '┆': '┤',
1044 '─': '┴',
1045 '┄': '┴',
1046 '┬': '┼',
1047 '├': '┼',}
1048 else:
1049 twisty_char = {None: '*',
1050 True: '~',
1051 False: '+'}
1052 ver_char = {True: '|',
1053 False: ':'}
1054
1055 hor_char = {True: {' ': '-',},
1056 False: {' ': '-'}}
1057
1058 tl_char = {}
1059
1060 tr_char = {}
1061
1062 bl_char = {}
1063
1064 br_char = {}
1065
1066 for row, (item, repr) in enumerate(zip(list, item_repr)):
1067 if row == 0:
1068 s.write('[')
1069 else:
1070 s.write(' ')
1071 s.write(repr.ljust(repr_width))
1072 if row == len(list)-1:
1073 s.write('] # ')
1074 else:
1075 s.write(', # ')
1076
1077 if len(item) == 4:
1078 revid, col_index, twisty_state, lines = item
1079 if len(item) == 5:
1080 revid, col_index, twisty_state, lines, labels = item
1081
1082 all_cols = [col_index]
1083 all_cols += [start for start, end, color, direct in lines]
1084 all_cols += [end for start, end, color, direct in lines]
1085 num_cols = (max(all_cols) + 1) * 2
1086 this_line = [' ' for i in range(num_cols)]
1087 next_line = [' ' for i in range(num_cols)]
1088
1089 for start, end, color, direct in lines:
1090 if start is None or end is None:
1091 continue
1092 start = int(round(start))
1093 end = int(round(end))
1094 if start == end:
1095 this_line[start * 2] = ver_char[direct]
1096 next_line[start * 2] = ver_char[direct]
1097 else:
1098 this_line[start * 2] = ver_char[direct]
1099
1100 def replace_char(line, i, char_dict):
1101 old_char = line[i]
1102 if old_char in char_dict:
1103 line[i] = char_dict[old_char]
1104
1105 for start, end, color, direct in lines:
1106 if start is None or end is None:
1107 continue
1108 start = int(round(start))
1109 end = int(round(end))
1110 if start < end:
1111 for i in range(start * 2 + 1, end * 2):
1112 replace_char(next_line, i, hor_char[direct])
1113 replace_char(next_line, start * 2, bl_char)
1114 replace_char(next_line, end * 2, tr_char)
1115 elif start > end:
1116 for i in range(end * 2 + 1, start * 2):
1117 replace_char(next_line, i, hor_char[direct])
1118 replace_char(next_line, start * 2, br_char)
1119 replace_char(next_line, end * 2, tl_char)
1120
1121 this_line[int(col_index * 2)] = twisty_char[twisty_state]
1122
1123 s.write(''.join(this_line))
1124 s.write('\n')
1125
1126 if not row == len(list)-1:
1127 s.write('# '.rjust(repr_width + 5))
1128 s.write(''.join(next_line))
1129 s.write('\n')
1130 return s.getvalue()
1131
1132
1133 class TestGroupOverlapping(TestCase):
1134 def test_group_overlapping(self):
1135 lines = [
1136 (['a1'], 1, 3, 'a'),
1137 (['a2'], 2, 5, 'a'),
1138 (['a3'], 4, 6, 'a'),
1139 (['a4'], 6, 8, 'a'),
1140 (['b1'], 1, 3, 'b'),
1141 (['b2'], 2, 5, 'b'),
1142 (['n1'], 1, 8, None),
1143 (['n2'], 1, 8, None),
1144 ]
1145 groups = loggraphviz.group_overlapping(lines)
1146 self.assertEqual(
1147 [(['a1', 'a2', 'a3'], 1, 6, 'a'),
1148 (['a4'], 6, 8, 'a'),
1149 (['b1', 'b2'], 1, 5, 'b'),
1150 (['n1'], 1, 8, None),
1151 (['n2'], 1, 8, None)],
1152 groups)