89
89
class MergeSortTests(TestCase):
91
91
def assertSortAndIterate(self, graph, branch_tip, result_list,
92
mainline_revisions=None):
92
generate_revno, mainline_revisions=None):
93
93
"""Check that merge based sorting and iter_topo_order on graph works."""
94
94
self.assertEquals(result_list,
95
merge_sort(graph, branch_tip, mainline_revisions=mainline_revisions))
95
merge_sort(graph, branch_tip, mainline_revisions=mainline_revisions,
96
generate_revno=generate_revno))
96
97
self.assertEqual(result_list,
100
mainline_revisions=mainline_revisions).iter_topo_order()))
101
mainline_revisions=mainline_revisions,
102
generate_revno=generate_revno,
103
).iter_topo_order()))
102
105
def test_merge_sort_empty(self):
103
106
# sorting of an emptygraph does not error
104
self.assertSortAndIterate({}, None, [])
107
self.assertSortAndIterate({}, None, [], False)
108
self.assertSortAndIterate({}, None, [], True)
106
110
def test_merge_sort_not_empty_no_tip(self):
107
111
# merge sorting of a branch starting with None should result
108
112
# in an empty list: no revisions are dragged in.
109
self.assertSortAndIterate({0: []}.items(), None, [])
113
self.assertSortAndIterate({0: []}.items(), None, [], False)
114
self.assertSortAndIterate({0: []}.items(), None, [], True)
111
116
def test_merge_sort_one_revision(self):
112
117
# sorting with one revision as the tip returns the correct fields:
113
118
# sequence - 0, revision id, merge depth - 0, end_of_merge
114
119
self.assertSortAndIterate({'id': []}.items(),
116
[(0, 'id', 0, True)])
121
[(0, 'id', 0, True)],
123
self.assertSortAndIterate({'id': []}.items(),
125
[(0, 'id', 0, (1,), True)],
118
128
def test_sequence_numbers_increase_no_merges(self):
119
129
# emit a few revisions with no merges to check the sequence
139
161
[(0, 'C', 0, False),
140
162
(1, 'B', 1, True),
141
163
(2, 'A', 0, True),
167
self.assertSortAndIterate(
170
'C': ['A', 'B']}.items(),
172
[(0, 'C', 0, (2,), False),
173
(1, 'B', 1, (1,1,1), True),
174
(2, 'A', 0, (1,), True),
145
179
def test_merge_depth_with_nested_merges(self):
173
207
(5, 'F', 2, True),
174
208
(6, 'G', 1, True),
175
209
(7, 'H', 0, True),
213
self.assertSortAndIterate(
224
[(0, 'A', 0, (3,), False),
225
(1, 'B', 1, (1,2,2), False),
226
(2, 'C', 1, (1,2,1), True),
227
(3, 'D', 0, (2,), False),
228
(4, 'E', 1, (1,1,2), False),
229
(5, 'F', 2, (1,1,1,1,1), True),
230
(6, 'G', 1, (1,1,1), True),
231
(7, 'H', 0, (1,), True),
179
236
def test_end_of_merge_not_last_revision_in_branch(self):
222
290
(5, 'F', 2, True),
223
291
(6, 'G', 1, True),
224
292
(7, 'H', 0, True),
296
self.assertSortAndIterate(
297
{'A': ['H', 'B', 'E'],
307
[(0, 'A', 0, (2,), False),
308
(1, 'B', 1, (1,2,2), False),
309
(2, 'C', 2, (1,2,1,1,1), True),
310
(3, 'D', 1, (1,2,1), True),
311
(4, 'E', 1, (1,1,2), False),
312
(5, 'F', 2, (1,1,1,1,1), True),
313
(6, 'G', 1, (1,1,1), True),
314
(7, 'H', 0, (1,), True),
228
319
def test_mainline_revs_partial(self):
264
356
(1, 'B', 0, False),
265
357
(2, 'C', 1, True),
360
mainline_revisions=['D', 'B', 'A']
362
self.assertSortAndIterate(
370
[(0, 'A', 0, (4,), False),
371
(1, 'B', 0, (3,), False),
372
(2, 'C', 1, (2,1,1), True),
267
375
mainline_revisions=['D', 'B', 'A']
277
385
[(0, 'A', 0, True),
388
mainline_revisions=[None, 'A']
390
self.assertSortAndIterate(
394
[(0, 'A', 0, (1,), True),
279
397
mainline_revisions=[None, 'A']
400
def test_parallel_root_sequence_numbers_increase_with_merges(self):
401
"""When there are parallel roots, check their revnos."""
402
self.assertSortAndIterate(
405
'C': ['A', 'B']}.items(),
407
[(0, 'C', 0, (2,), False),
408
(1, 'B', 1, (0,1,1), True),
409
(2, 'A', 0, (1,), True),
414
def test_revnos_are_globally_assigned(self):
415
"""revnos are assigned according to the revision they derive from."""
416
# in this test we setup a number of branches that all derive from
417
# the first revision, and then merge them one at a time, which
418
# should give the revisions as they merge numbers still deriving from
419
# the revision were based on.
420
# merge 3: J: ['G', 'I']
424
# merge 2: G: ['D', 'F']
428
# merge 1: D: ['A', 'C']
433
self.assertSortAndIterate(
446
[(0, 'J', 0, (4,), False),
447
(1, 'I', 1, (1,3,2), False),
448
(2, 'H', 1, (1,3,1), True),
449
(3, 'G', 0, (3,), False),
450
(4, 'F', 1, (1,2,2), False),
451
(5, 'E', 1, (1,2,1), True),
452
(6, 'D', 0, (2,), False),
453
(7, 'C', 1, (1,1,2), False),
454
(8, 'B', 1, (1,1,1), True),
455
(9, 'A', 0, (1,), True),