2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2005 Canonical Ltd
|
1185.16.113
by mbp at sourcefrog
Add topo_sort utility function |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
17 |
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
18 |
"""Tests for topological sort."""
|
19 |
||
20 |
||
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
21 |
from bzrlib.tests import TestCase |
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
22 |
from bzrlib.tsort import topo_sort, TopoSorter, MergeSorter, merge_sort |
1185.16.114
by mbp at sourcefrog
Improved topological sort |
23 |
from bzrlib.errors import GraphCycleError |
3236.2.1
by Michael Hudson
test and fix |
24 |
from bzrlib.revision import NULL_REVISION |
1185.16.113
by mbp at sourcefrog
Add topo_sort utility function |
25 |
|
1570.1.6
by Robert Collins
Update fast topological_sort to be a function and to have the topo_sort tests run against it. |
26 |
|
1185.16.113
by mbp at sourcefrog
Add topo_sort utility function |
27 |
class TopoSortTests(TestCase): |
28 |
||
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
29 |
def assertSortAndIterate(self, graph, result_list): |
30 |
"""Check that sorting and iter_topo_order on graph works."""
|
|
31 |
self.assertEquals(result_list, topo_sort(graph)) |
|
32 |
self.assertEqual(result_list, |
|
33 |
list(TopoSorter(graph).iter_topo_order())) |
|
34 |
||
35 |
def assertSortAndIterateRaise(self, exception_type, graph): |
|
36 |
"""Try both iterating and topo_sorting graph and expect an exception."""
|
|
37 |
self.assertRaises(exception_type, topo_sort, graph) |
|
38 |
self.assertRaises(exception_type, |
|
39 |
list, |
|
40 |
TopoSorter(graph).iter_topo_order()) |
|
41 |
||
1185.16.113
by mbp at sourcefrog
Add topo_sort utility function |
42 |
def test_tsort_empty(self): |
43 |
"""TopoSort empty list"""
|
|
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
44 |
self.assertSortAndIterate([], []) |
1185.16.113
by mbp at sourcefrog
Add topo_sort utility function |
45 |
|
46 |
def test_tsort_easy(self): |
|
1185.16.114
by mbp at sourcefrog
Improved topological sort |
47 |
"""TopoSort list with one node"""
|
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
48 |
self.assertSortAndIterate({0: []}.items(), [0]) |
1185.16.113
by mbp at sourcefrog
Add topo_sort utility function |
49 |
|
50 |
def test_tsort_cycle(self): |
|
1185.16.114
by mbp at sourcefrog
Improved topological sort |
51 |
"""TopoSort traps graph with cycles"""
|
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
52 |
self.assertSortAndIterateRaise(GraphCycleError, |
53 |
{0: [1], |
|
54 |
1: [0]}.items()) |
|
1185.16.113
by mbp at sourcefrog
Add topo_sort utility function |
55 |
|
1185.16.114
by mbp at sourcefrog
Improved topological sort |
56 |
def test_tsort_cycle_2(self): |
57 |
"""TopoSort traps graph with longer cycle"""
|
|
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
58 |
self.assertSortAndIterateRaise(GraphCycleError, |
59 |
{0: [1], |
|
60 |
1: [2], |
|
61 |
2: [0]}.items()) |
|
1185.16.114
by mbp at sourcefrog
Improved topological sort |
62 |
|
1185.16.113
by mbp at sourcefrog
Add topo_sort utility function |
63 |
def test_tsort_1(self): |
64 |
"""TopoSort simple nontrivial graph"""
|
|
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
65 |
self.assertSortAndIterate({0: [3], |
66 |
1: [4], |
|
67 |
2: [1, 4], |
|
68 |
3: [], |
|
69 |
4: [0, 3]}.items(), |
|
70 |
[3, 0, 4, 1, 2]) |
|
1185.16.115
by mbp at sourcefrog
Another topo_sort test |
71 |
|
72 |
def test_tsort_partial(self): |
|
73 |
"""Topological sort with partial ordering.
|
|
74 |
||
75 |
If the graph does not give an order between two nodes, they are
|
|
76 |
returned in lexicographical order.
|
|
77 |
"""
|
|
1570.1.7
by Robert Collins
Replace the slow topo_sort routine with a much faster one for non trivial datasets. |
78 |
self.assertSortAndIterate(([(0, []), |
79 |
(1, [0]), |
|
80 |
(2, [0]), |
|
81 |
(3, [0]), |
|
82 |
(4, [1, 2, 3]), |
|
83 |
(5, [1, 2]), |
|
84 |
(6, [1, 2]), |
|
85 |
(7, [2, 3]), |
|
86 |
(8, [0, 1, 4, 5, 6])]), |
|
87 |
[0, 1, 2, 3, 4, 5, 6, 7, 8]) |
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
88 |
|
2490.2.31
by Aaron Bentley
Fix iter_topo_order to permit un-included parents |
89 |
def test_tsort_unincluded_parent(self): |
90 |
"""Sort nodes, but don't include some parents in the output"""
|
|
91 |
self.assertSortAndIterate([(0, [1]), |
|
92 |
(1, [2])], |
|
93 |
[1, 0]) |
|
94 |
||
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
95 |
|
96 |
class MergeSortTests(TestCase): |
|
97 |
||
1624.1.3
by Robert Collins
Convert log to use the new tsort.merge_sort routine. |
98 |
def assertSortAndIterate(self, graph, branch_tip, result_list, |
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
99 |
generate_revno, mainline_revisions=None): |
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
100 |
"""Check that merge based sorting and iter_topo_order on graph works."""
|
1624.1.3
by Robert Collins
Convert log to use the new tsort.merge_sort routine. |
101 |
self.assertEquals(result_list, |
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
102 |
merge_sort(graph, branch_tip, mainline_revisions=mainline_revisions, |
103 |
generate_revno=generate_revno)) |
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
104 |
self.assertEqual(result_list, |
1624.1.3
by Robert Collins
Convert log to use the new tsort.merge_sort routine. |
105 |
list(MergeSorter( |
106 |
graph, |
|
107 |
branch_tip, |
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
108 |
mainline_revisions=mainline_revisions, |
109 |
generate_revno=generate_revno, |
|
110 |
).iter_topo_order())) |
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
111 |
|
112 |
def test_merge_sort_empty(self): |
|
113 |
# sorting of an emptygraph does not error
|
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
114 |
self.assertSortAndIterate({}, None, [], False) |
115 |
self.assertSortAndIterate({}, None, [], True) |
|
3236.2.1
by Michael Hudson
test and fix |
116 |
self.assertSortAndIterate({}, NULL_REVISION, [], False) |
117 |
self.assertSortAndIterate({}, NULL_REVISION, [], True) |
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
118 |
|
119 |
def test_merge_sort_not_empty_no_tip(self): |
|
120 |
# merge sorting of a branch starting with None should result
|
|
121 |
# in an empty list: no revisions are dragged in.
|
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
122 |
self.assertSortAndIterate({0: []}.items(), None, [], False) |
123 |
self.assertSortAndIterate({0: []}.items(), None, [], True) |
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
124 |
|
125 |
def test_merge_sort_one_revision(self): |
|
126 |
# sorting with one revision as the tip returns the correct fields:
|
|
127 |
# sequence - 0, revision id, merge depth - 0, end_of_merge
|
|
128 |
self.assertSortAndIterate({'id': []}.items(), |
|
129 |
'id', |
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
130 |
[(0, 'id', 0, True)], |
131 |
False) |
|
132 |
self.assertSortAndIterate({'id': []}.items(), |
|
133 |
'id', |
|
134 |
[(0, 'id', 0, (1,), True)], |
|
135 |
True) |
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
136 |
|
137 |
def test_sequence_numbers_increase_no_merges(self): |
|
138 |
# emit a few revisions with no merges to check the sequence
|
|
139 |
# numbering works in trivial cases
|
|
140 |
self.assertSortAndIterate( |
|
141 |
{'A': [], |
|
142 |
'B': ['A'], |
|
143 |
'C': ['B']}.items(), |
|
144 |
'C', |
|
145 |
[(0, 'C', 0, False), |
|
146 |
(1, 'B', 0, False), |
|
147 |
(2, 'A', 0, True), |
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
148 |
],
|
149 |
False
|
|
150 |
)
|
|
151 |
self.assertSortAndIterate( |
|
152 |
{'A': [], |
|
153 |
'B': ['A'], |
|
154 |
'C': ['B']}.items(), |
|
155 |
'C', |
|
156 |
[(0, 'C', 0, (3,), False), |
|
157 |
(1, 'B', 0, (2,), False), |
|
158 |
(2, 'A', 0, (1,), True), |
|
159 |
],
|
|
160 |
True
|
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
161 |
)
|
162 |
||
163 |
def test_sequence_numbers_increase_with_merges(self): |
|
164 |
# test that sequence numbers increase across merges
|
|
165 |
self.assertSortAndIterate( |
|
166 |
{'A': [], |
|
167 |
'B': ['A'], |
|
168 |
'C': ['A', 'B']}.items(), |
|
169 |
'C', |
|
170 |
[(0, 'C', 0, False), |
|
171 |
(1, 'B', 1, True), |
|
172 |
(2, 'A', 0, True), |
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
173 |
],
|
174 |
False
|
|
175 |
)
|
|
176 |
self.assertSortAndIterate( |
|
177 |
{'A': [], |
|
178 |
'B': ['A'], |
|
179 |
'C': ['A', 'B']}.items(), |
|
180 |
'C', |
|
181 |
[(0, 'C', 0, (2,), False), |
|
182 |
(1, 'B', 1, (1,1,1), True), |
|
183 |
(2, 'A', 0, (1,), True), |
|
184 |
],
|
|
185 |
True
|
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
186 |
)
|
3170.3.4
by John Arbash Meinel
Update the tests for the new revision numbering. |
187 |
|
188 |
def test_merge_sort_race(self): |
|
189 |
# A
|
|
190 |
# |
|
|
191 |
# B-.
|
|
192 |
# |\ \
|
|
193 |
# | | C
|
|
194 |
# | |/
|
|
195 |
# | D
|
|
196 |
# |/
|
|
197 |
# F
|
|
198 |
graph = {'A': [], |
|
199 |
'B': ['A'], |
|
200 |
'C': ['B'], |
|
201 |
'D': ['B', 'C'], |
|
202 |
'F': ['B', 'D'], |
|
203 |
}
|
|
204 |
self.assertSortAndIterate(graph, 'F', |
|
205 |
[(0, 'F', 0, (3,), False), |
|
206 |
(1, 'D', 1, (2,2,1), False), |
|
3170.3.8
by John Arbash Meinel
Finish the rest of the review feedback. |
207 |
(2, 'C', 1, (2,1,1), True), # XXX: Shouldn't it be merge_depth=2? |
3170.3.4
by John Arbash Meinel
Update the tests for the new revision numbering. |
208 |
(3, 'B', 0, (2,), False), |
209 |
(4, 'A', 0, (1,), True), |
|
210 |
], True) |
|
211 |
# A
|
|
212 |
# |
|
|
213 |
# B-.
|
|
214 |
# |\ \
|
|
215 |
# | X C
|
|
216 |
# | |/
|
|
217 |
# | D
|
|
218 |
# |/
|
|
219 |
# F
|
|
220 |
graph = {'A': [], |
|
221 |
'B': ['A'], |
|
222 |
'C': ['B'], |
|
223 |
'X': ['B'], |
|
224 |
'D': ['X', 'C'], |
|
225 |
'F': ['B', 'D'], |
|
226 |
}
|
|
227 |
self.assertSortAndIterate(graph, 'F', |
|
228 |
[(0, 'F', 0, (3,), False), |
|
229 |
(1, 'D', 1, (2,1,2), False), |
|
230 |
(2, 'C', 2, (2,2,1), True), |
|
231 |
(3, 'X', 1, (2,1,1), True), |
|
232 |
(4, 'B', 0, (2,), False), |
|
233 |
(5, 'A', 0, (1,), True), |
|
234 |
], True) |
|
235 |
||
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
236 |
def test_merge_depth_with_nested_merges(self): |
237 |
# the merge depth marker should reflect the depth of the revision
|
|
238 |
# in terms of merges out from the mainline
|
|
239 |
# revid, depth, parents:
|
|
240 |
# A 0 [D, B]
|
|
241 |
# B 1 [C, F]
|
|
242 |
# C 1 [H]
|
|
243 |
# D 0 [H, E]
|
|
244 |
# E 1 [G, F]
|
|
245 |
# F 2 [G]
|
|
246 |
# G 1 [H]
|
|
247 |
# H 0
|
|
248 |
self.assertSortAndIterate( |
|
249 |
{'A': ['D', 'B'], |
|
250 |
'B': ['C', 'F'], |
|
251 |
'C': ['H'], |
|
252 |
'D': ['H', 'E'], |
|
253 |
'E': ['G', 'F'], |
|
254 |
'F': ['G'], |
|
255 |
'G': ['H'], |
|
256 |
'H': [] |
|
257 |
}.items(), |
|
258 |
'A', |
|
259 |
[(0, 'A', 0, False), |
|
260 |
(1, 'B', 1, False), |
|
261 |
(2, 'C', 1, True), |
|
262 |
(3, 'D', 0, False), |
|
263 |
(4, 'E', 1, False), |
|
264 |
(5, 'F', 2, True), |
|
265 |
(6, 'G', 1, True), |
|
266 |
(7, 'H', 0, True), |
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
267 |
],
|
268 |
False
|
|
269 |
)
|
|
270 |
self.assertSortAndIterate( |
|
271 |
{'A': ['D', 'B'], |
|
272 |
'B': ['C', 'F'], |
|
273 |
'C': ['H'], |
|
274 |
'D': ['H', 'E'], |
|
275 |
'E': ['G', 'F'], |
|
276 |
'F': ['G'], |
|
277 |
'G': ['H'], |
|
278 |
'H': [] |
|
279 |
}.items(), |
|
280 |
'A', |
|
281 |
[(0, 'A', 0, (3,), False), |
|
3170.3.4
by John Arbash Meinel
Update the tests for the new revision numbering. |
282 |
(1, 'B', 1, (1,3,2), False), |
283 |
(2, 'C', 1, (1,3,1), True), |
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
284 |
(3, 'D', 0, (2,), False), |
285 |
(4, 'E', 1, (1,1,2), False), |
|
3170.3.4
by John Arbash Meinel
Update the tests for the new revision numbering. |
286 |
(5, 'F', 2, (1,2,1), True), |
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
287 |
(6, 'G', 1, (1,1,1), True), |
288 |
(7, 'H', 0, (1,), True), |
|
289 |
],
|
|
290 |
True
|
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
291 |
)
|
3170.3.1
by John Arbash Meinel
Write up a simple test that is getting ready to fix up deeply nested dotted revnos. |
292 |
|
293 |
def test_dotted_revnos_with_simple_merges(self): |
|
294 |
# A 1
|
|
295 |
# |\
|
|
296 |
# B C 2, 1.1.1
|
|
297 |
# | |\
|
|
298 |
# D E F 3, 1.1.2, 1.2.1
|
|
299 |
# |/ /|
|
|
300 |
# G H I 4, 1.2.2, 1.3.1
|
|
301 |
# |/ /
|
|
302 |
# J K 5, 1.3.2
|
|
303 |
# |/
|
|
304 |
# L 6
|
|
305 |
self.assertSortAndIterate( |
|
306 |
{'A': [], |
|
307 |
'B': ['A'], |
|
308 |
'C': ['A'], |
|
309 |
'D': ['B'], |
|
310 |
'E': ['C'], |
|
311 |
'F': ['C'], |
|
312 |
'G': ['D', 'E'], |
|
313 |
'H': ['F'], |
|
314 |
'I': ['F'], |
|
315 |
'J': ['G', 'H'], |
|
316 |
'K': ['I'], |
|
317 |
'L': ['J', 'K'], |
|
318 |
}.items(), |
|
319 |
'L', |
|
320 |
[(0, 'L', 0, (6,), False), |
|
3170.3.2
by John Arbash Meinel
Implement the new dotted revision numbering. |
321 |
(1, 'K', 1, (1,3,2), False), |
322 |
(2, 'I', 1, (1,3,1), True), |
|
3170.3.1
by John Arbash Meinel
Write up a simple test that is getting ready to fix up deeply nested dotted revnos. |
323 |
(3, 'J', 0, (5,), False), |
3170.3.2
by John Arbash Meinel
Implement the new dotted revision numbering. |
324 |
(4, 'H', 1, (1,2,2), False), |
325 |
(5, 'F', 1, (1,2,1), True), |
|
3170.3.1
by John Arbash Meinel
Write up a simple test that is getting ready to fix up deeply nested dotted revnos. |
326 |
(6, 'G', 0, (4,), False), |
327 |
(7, 'E', 1, (1,1,2), False), |
|
328 |
(8, 'C', 1, (1,1,1), True), |
|
329 |
(9, 'D', 0, (3,), False), |
|
330 |
(10, 'B', 0, (2,), False), |
|
331 |
(11, 'A', 0, (1,), True), |
|
332 |
],
|
|
333 |
True
|
|
334 |
)
|
|
335 |
# Adding a shortcut from the first revision should not change any of
|
|
336 |
# the existing numbers
|
|
337 |
self.assertSortAndIterate( |
|
338 |
{'A': [], |
|
339 |
'B': ['A'], |
|
340 |
'C': ['A'], |
|
341 |
'D': ['B'], |
|
342 |
'E': ['C'], |
|
343 |
'F': ['C'], |
|
344 |
'G': ['D', 'E'], |
|
345 |
'H': ['F'], |
|
346 |
'I': ['F'], |
|
347 |
'J': ['G', 'H'], |
|
348 |
'K': ['I'], |
|
349 |
'L': ['J', 'K'], |
|
350 |
'M': ['A'], |
|
351 |
'N': ['L', 'M'], |
|
352 |
}.items(), |
|
353 |
'N', |
|
354 |
[(0, 'N', 0, (7,), False), |
|
3170.3.2
by John Arbash Meinel
Implement the new dotted revision numbering. |
355 |
(1, 'M', 1, (1,4,1), True), |
3170.3.1
by John Arbash Meinel
Write up a simple test that is getting ready to fix up deeply nested dotted revnos. |
356 |
(2, 'L', 0, (6,), False), |
3170.3.2
by John Arbash Meinel
Implement the new dotted revision numbering. |
357 |
(3, 'K', 1, (1,3,2), False), |
358 |
(4, 'I', 1, (1,3,1), True), |
|
3170.3.1
by John Arbash Meinel
Write up a simple test that is getting ready to fix up deeply nested dotted revnos. |
359 |
(5, 'J', 0, (5,), False), |
3170.3.2
by John Arbash Meinel
Implement the new dotted revision numbering. |
360 |
(6, 'H', 1, (1,2,2), False), |
361 |
(7, 'F', 1, (1,2,1), True), |
|
3170.3.1
by John Arbash Meinel
Write up a simple test that is getting ready to fix up deeply nested dotted revnos. |
362 |
(8, 'G', 0, (4,), False), |
363 |
(9, 'E', 1, (1,1,2), False), |
|
364 |
(10, 'C', 1, (1,1,1), True), |
|
365 |
(11, 'D', 0, (3,), False), |
|
366 |
(12, 'B', 0, (2,), False), |
|
367 |
(13, 'A', 0, (1,), True), |
|
368 |
],
|
|
369 |
True
|
|
370 |
)
|
|
371 |
||
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
372 |
def test_end_of_merge_not_last_revision_in_branch(self): |
373 |
# within a branch only the last revision gets an
|
|
374 |
# end of merge marker.
|
|
375 |
self.assertSortAndIterate( |
|
376 |
{'A': ['B'], |
|
377 |
'B': [], |
|
378 |
},
|
|
379 |
'A', |
|
380 |
[(0, 'A', 0, False), |
|
381 |
(1, 'B', 0, True) |
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
382 |
],
|
383 |
False
|
|
384 |
)
|
|
385 |
self.assertSortAndIterate( |
|
386 |
{'A': ['B'], |
|
387 |
'B': [], |
|
388 |
},
|
|
389 |
'A', |
|
390 |
[(0, 'A', 0, (2,), False), |
|
391 |
(1, 'B', 0, (1,), True) |
|
392 |
],
|
|
393 |
True
|
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
394 |
)
|
395 |
||
396 |
def test_end_of_merge_multiple_revisions_merged_at_once(self): |
|
397 |
# when multiple branches are merged at once, both of their
|
|
398 |
# branch-endpoints should be listed as end-of-merge.
|
|
399 |
# Also, the order of the multiple merges should be
|
|
400 |
# left-right shown top to bottom.
|
|
401 |
# * means end of merge
|
|
402 |
# A 0 [H, B, E]
|
|
403 |
# B 1 [D, C]
|
|
404 |
# C 2 [D] *
|
|
405 |
# D 1 [H] *
|
|
406 |
# E 1 [G, F]
|
|
407 |
# F 2 [G] *
|
|
408 |
# G 1 [H] *
|
|
409 |
# H 0 [] *
|
|
410 |
self.assertSortAndIterate( |
|
411 |
{'A': ['H', 'B', 'E'], |
|
412 |
'B': ['D', 'C'], |
|
413 |
'C': ['D'], |
|
414 |
'D': ['H'], |
|
415 |
'E': ['G', 'F'], |
|
416 |
'F': ['G'], |
|
417 |
'G': ['H'], |
|
418 |
'H': [], |
|
419 |
},
|
|
420 |
'A', |
|
421 |
[(0, 'A', 0, False), |
|
422 |
(1, 'B', 1, False), |
|
423 |
(2, 'C', 2, True), |
|
424 |
(3, 'D', 1, True), |
|
425 |
(4, 'E', 1, False), |
|
426 |
(5, 'F', 2, True), |
|
427 |
(6, 'G', 1, True), |
|
428 |
(7, 'H', 0, True), |
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
429 |
],
|
430 |
False
|
|
431 |
)
|
|
432 |
self.assertSortAndIterate( |
|
433 |
{'A': ['H', 'B', 'E'], |
|
434 |
'B': ['D', 'C'], |
|
435 |
'C': ['D'], |
|
436 |
'D': ['H'], |
|
437 |
'E': ['G', 'F'], |
|
438 |
'F': ['G'], |
|
439 |
'G': ['H'], |
|
440 |
'H': [], |
|
441 |
},
|
|
442 |
'A', |
|
443 |
[(0, 'A', 0, (2,), False), |
|
3170.3.4
by John Arbash Meinel
Update the tests for the new revision numbering. |
444 |
(1, 'B', 1, (1,3,2), False), |
445 |
(2, 'C', 2, (1,4,1), True), |
|
446 |
(3, 'D', 1, (1,3,1), True), |
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
447 |
(4, 'E', 1, (1,1,2), False), |
3170.3.4
by John Arbash Meinel
Update the tests for the new revision numbering. |
448 |
(5, 'F', 2, (1,2,1), True), |
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
449 |
(6, 'G', 1, (1,1,1), True), |
450 |
(7, 'H', 0, (1,), True), |
|
451 |
],
|
|
452 |
True
|
|
1624.1.2
by Robert Collins
Add MergeSort facility to bzrlib.tsort. |
453 |
)
|
1624.1.3
by Robert Collins
Convert log to use the new tsort.merge_sort routine. |
454 |
|
455 |
def test_mainline_revs_partial(self): |
|
456 |
# when a mainline_revisions list is passed this must
|
|
457 |
# override the graphs idea of mainline, and must also
|
|
458 |
# truncate the output to the specified range, if needed.
|
|
459 |
# so we test both at once: a mainline_revisions list that
|
|
460 |
# disagrees with the graph about which revs are 'mainline'
|
|
461 |
# and also truncates the output.
|
|
462 |
# graph:
|
|
463 |
# A 0 [E, B]
|
|
464 |
# B 1 [D, C]
|
|
465 |
# C 2 [D]
|
|
466 |
# D 1 [E]
|
|
467 |
# E 0
|
|
468 |
# with a mainline of NONE,E,A (the inferred one) this will show the merge
|
|
469 |
# depths above.
|
|
470 |
# with a overriden mainline of NONE,E,D,B,A it should show:
|
|
471 |
# A 0
|
|
472 |
# B 0
|
|
473 |
# C 1
|
|
474 |
# D 0
|
|
475 |
# E 0
|
|
476 |
# and thus when truncated to D,B,A it should show
|
|
477 |
# A 0
|
|
478 |
# B 0
|
|
479 |
# C 1
|
|
480 |
# because C is brought in by B in this view and D
|
|
481 |
# is the terminating revision id
|
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
482 |
# this should also preserve revision numbers: C should still be 2.1.1
|
1624.1.3
by Robert Collins
Convert log to use the new tsort.merge_sort routine. |
483 |
self.assertSortAndIterate( |
484 |
{'A': ['E', 'B'], |
|
485 |
'B': ['D', 'C'], |
|
486 |
'C': ['D'], |
|
487 |
'D': ['E'], |
|
488 |
'E': [] |
|
489 |
},
|
|
490 |
'A', |
|
491 |
[(0, 'A', 0, False), |
|
492 |
(1, 'B', 0, False), |
|
493 |
(2, 'C', 1, True), |
|
494 |
],
|
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
495 |
False, |
496 |
mainline_revisions=['D', 'B', 'A'] |
|
497 |
)
|
|
498 |
self.assertSortAndIterate( |
|
499 |
{'A': ['E', 'B'], |
|
500 |
'B': ['D', 'C'], |
|
501 |
'C': ['D'], |
|
502 |
'D': ['E'], |
|
503 |
'E': [] |
|
504 |
},
|
|
505 |
'A', |
|
506 |
[(0, 'A', 0, (4,), False), |
|
507 |
(1, 'B', 0, (3,), False), |
|
508 |
(2, 'C', 1, (2,1,1), True), |
|
509 |
],
|
|
510 |
True, |
|
1624.1.3
by Robert Collins
Convert log to use the new tsort.merge_sort routine. |
511 |
mainline_revisions=['D', 'B', 'A'] |
512 |
)
|
|
513 |
||
514 |
def test_mainline_revs_with_none(self): |
|
515 |
# a simple test to ensure that a mainline_revs
|
|
516 |
# list which goes all the way to None works
|
|
517 |
self.assertSortAndIterate( |
|
518 |
{'A': [], |
|
519 |
},
|
|
520 |
'A', |
|
521 |
[(0, 'A', 0, True), |
|
522 |
],
|
|
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
523 |
False, |
524 |
mainline_revisions=[None, 'A'] |
|
525 |
)
|
|
526 |
self.assertSortAndIterate( |
|
527 |
{'A': [], |
|
528 |
},
|
|
529 |
'A', |
|
530 |
[(0, 'A', 0, (1,), True), |
|
531 |
],
|
|
532 |
True, |
|
1624.1.3
by Robert Collins
Convert log to use the new tsort.merge_sort routine. |
533 |
mainline_revisions=[None, 'A'] |
534 |
)
|
|
535 |
||
1988.4.1
by Robert Collins
bzrlib.tsort.merge_sorted now accepts 'generate_revnos'. This parameter |
536 |
def test_parallel_root_sequence_numbers_increase_with_merges(self): |
537 |
"""When there are parallel roots, check their revnos."""
|
|
538 |
self.assertSortAndIterate( |
|
539 |
{'A': [], |
|
540 |
'B': [], |
|
541 |
'C': ['A', 'B']}.items(), |
|
542 |
'C', |
|
543 |
[(0, 'C', 0, (2,), False), |
|
544 |
(1, 'B', 1, (0,1,1), True), |
|
545 |
(2, 'A', 0, (1,), True), |
|
546 |
],
|
|
547 |
True
|
|
548 |
)
|
|
549 |
||
550 |
def test_revnos_are_globally_assigned(self): |
|
551 |
"""revnos are assigned according to the revision they derive from."""
|
|
552 |
# in this test we setup a number of branches that all derive from
|
|
553 |
# the first revision, and then merge them one at a time, which
|
|
554 |
# should give the revisions as they merge numbers still deriving from
|
|
555 |
# the revision were based on.
|
|
556 |
# merge 3: J: ['G', 'I']
|
|
557 |
# branch 3:
|
|
558 |
# I: ['H']
|
|
559 |
# H: ['A']
|
|
560 |
# merge 2: G: ['D', 'F']
|
|
561 |
# branch 2:
|
|
562 |
# F: ['E']
|
|
563 |
# E: ['A']
|
|
564 |
# merge 1: D: ['A', 'C']
|
|
565 |
# branch 1:
|
|
566 |
# C: ['B']
|
|
567 |
# B: ['A']
|
|
568 |
# root: A: []
|
|
569 |
self.assertSortAndIterate( |
|
570 |
{'J': ['G', 'I'], |
|
571 |
'I': ['H',], |
|
572 |
'H': ['A'], |
|
573 |
'G': ['D', 'F'], |
|
574 |
'F': ['E'], |
|
575 |
'E': ['A'], |
|
576 |
'D': ['A', 'C'], |
|
577 |
'C': ['B'], |
|
578 |
'B': ['A'], |
|
579 |
'A': [], |
|
580 |
}.items(), |
|
581 |
'J', |
|
582 |
[(0, 'J', 0, (4,), False), |
|
583 |
(1, 'I', 1, (1,3,2), False), |
|
584 |
(2, 'H', 1, (1,3,1), True), |
|
585 |
(3, 'G', 0, (3,), False), |
|
586 |
(4, 'F', 1, (1,2,2), False), |
|
587 |
(5, 'E', 1, (1,2,1), True), |
|
588 |
(6, 'D', 0, (2,), False), |
|
589 |
(7, 'C', 1, (1,1,2), False), |
|
590 |
(8, 'B', 1, (1,1,1), True), |
|
591 |
(9, 'A', 0, (1,), True), |
|
592 |
],
|
|
593 |
True
|
|
594 |
)
|