25
25
from bzrlib.tests import per_branch
28
class TestIterMergeSortedRevisionsSimpleGraph(per_branch.TestCaseWithBranch):
28
class TestIterMergeSortedRevisions(per_branch.TestCaseWithBranch):
31
super(TestIterMergeSortedRevisionsSimpleGraph, self).setUp()
32
builder = self.make_builder_with_merges('.')
33
self.branch = builder.get_branch()
34
self.branch.lock_read()
35
self.addCleanup(self.branch.unlock)
31
super(TestIterMergeSortedRevisions, self).setUp()
32
self.branch = self.make_branch_with_merges('.')
37
def make_builder_with_merges(self, relpath):
34
def make_branch_with_merges(self, relpath):
39
36
builder = self.make_branch_builder(relpath)
40
37
except (errors.TransportNotPossible, errors.UninitializableFormat):
41
38
raise tests.TestNotApplicable('format not directly constructable')
42
39
builder.start_series()
50
40
builder.build_snapshot('1', None, [
51
41
('add', ('', 'TREE_ROOT', 'directory', '')),])
52
42
builder.build_snapshot('1.1.1', ['1'], [])
53
43
builder.build_snapshot('2', ['1'], [])
54
44
builder.build_snapshot('3', ['2', '1.1.1'], [])
55
45
builder.finish_series()
46
return builder.get_branch()
58
49
def assertIterRevids(self, expected, *args, **kwargs):
59
50
# We don't care about depths and revnos here, only about returning the
61
revids = [revid for (revid, depth, revno, eom) in
62
self.branch.iter_merge_sorted_revisions(*args, **kwargs)]
52
revids = [ revid for (revid, depth, revno, eom) in
53
self.branch.iter_merge_sorted_revisions(*args, **kwargs)]
63
54
self.assertEqual(expected, revids)
65
56
def test_merge_sorted(self):
66
57
self.assertIterRevids(['3', '1.1.1', '2', '1'])
68
59
def test_merge_sorted_range(self):
69
self.assertIterRevids(['1.1.1'],
60
self.assertIterRevids(['1.1.1', '2'],
70
61
start_revision_id='1.1.1', stop_revision_id='1')
72
63
def test_merge_sorted_range_start_only(self):
73
self.assertIterRevids(['1.1.1', '1'],
64
self.assertIterRevids(['1.1.1', '2', '1'],
74
65
start_revision_id='1.1.1')
76
67
def test_merge_sorted_range_stop_exclude(self):
135
126
self.assertIterRevids(['1.1.1', '3'],
136
127
stop_revision_id='3', stop_rule='with-merges',
137
128
direction='forward')
140
class TestIterMergeSortedRevisionsBushyGraph(per_branch.TestCaseWithBranch):
142
def make_branch_builder(self, relpath):
144
builder = super(TestIterMergeSortedRevisionsBushyGraph,
145
self).make_branch_builder(relpath)
146
except (errors.TransportNotPossible, errors.UninitializableFormat):
147
raise tests.TestNotApplicable('format not directly constructable')
150
def make_branch_with_embedded_merges(self, relpath='.'):
151
builder = self.make_branch_builder(relpath)
169
builder.start_series()
170
builder.build_snapshot('1', None, [
171
('add', ('', 'TREE_ROOT', 'directory', '')),])
172
builder.build_snapshot('1.1.1', ['1'], [])
173
builder.build_snapshot('2', ['1', '1.1.1'], [])
174
builder.build_snapshot('2.1.1', ['2'], [])
175
builder.build_snapshot('2.1.2', ['2.1.1'], [])
176
builder.build_snapshot('2.2.1', ['2.1.1'], [])
177
builder.build_snapshot('2.1.3', ['2.1.2', '2.2.1'], [])
178
builder.build_snapshot('3', ['2'], [])
179
builder.build_snapshot('4', ['3', '2.1.3'], [])
180
builder.finish_series()
181
br = builder.get_branch()
183
self.addCleanup(br.unlock)
186
def make_branch_with_different_depths_merges(self, relpath='.'):
187
builder = self.make_branch_builder(relpath)
205
builder.start_series()
206
builder.build_snapshot('1', None, [
207
('add', ('', 'TREE_ROOT', 'directory', '')),])
208
builder.build_snapshot('2', ['1'], [])
209
builder.build_snapshot('1.1.1', ['1'], [])
210
builder.build_snapshot('1.1.2', ['1.1.1'], [])
211
builder.build_snapshot('1.2.1', ['1.1.1'], [])
212
builder.build_snapshot('1.2.2', ['1.2.1'], [])
213
builder.build_snapshot('1.3.1', ['1.2.1'], [])
214
builder.build_snapshot('1.3.2', ['1.3.1'], [])
215
builder.build_snapshot('1.4.1', ['1.3.1'], [])
216
builder.build_snapshot('1.3.3', ['1.3.2', '1.4.11'], [])
217
builder.build_snapshot('1.2.3', ['1.2.2', '1.3.3'], [])
218
builder.build_snapshot('2.1.1', ['2'], [])
219
builder.build_snapshot('2.1.2', ['2.1.1'], [])
220
builder.build_snapshot('2.2.1', ['2.1.1'], [])
221
builder.build_snapshot('2.1.3', ['2.1.2', '2.2.1'], [])
222
builder.build_snapshot('3', ['2', '1.2.3'], [])
223
# .. to bring them all and ... bind them
224
builder.build_snapshot('4', ['3', '2.1.3'],
226
builder.finish_series()
227
br = builder.get_branch()
229
self.addCleanup(br.unlock)
232
def make_branch_with_alternate_ancestries(self, relpath='.'):
233
# See test_merge_sorted_exclude_ancestry below for the difference with
234
# bt.test_log.TestLogExcludeAncestry.
235
# make_branch_with_alternate_ancestries and
236
# test_merge_sorted_exclude_ancestry
237
# See the FIXME in assertLogRevnos there too.
238
builder = self.make_branch_builder(relpath)
249
builder.start_series()
250
builder.build_snapshot('1', None, [
251
('add', ('', 'TREE_ROOT', 'directory', '')),])
252
builder.build_snapshot('1.1.1', ['1'], [])
253
builder.build_snapshot('2', ['1', '1.1.1'], [])
254
builder.build_snapshot('1.2.1', ['1.1.1'], [])
255
builder.build_snapshot('1.1.2', ['1.1.1', '1.2.1'], [])
256
builder.build_snapshot('3', ['2', '1.1.2'], [])
257
builder.finish_series()
258
br = builder.get_branch()
260
self.addCleanup(br.unlock)
263
def assertIterRevids(self, expected, branch, *args, **kwargs):
264
# We don't care about depths and revnos here, only about returning the
266
revs = list(branch.iter_merge_sorted_revisions(*args, **kwargs))
267
revids = [revid for (revid, depth, revno, eom) in revs]
268
self.assertEqual(expected, revids)
270
def test_merge_sorted_starting_at_embedded_merge(self):
271
branch = self.make_branch_with_embedded_merges()
272
self.assertIterRevids(['4', '2.1.3', '2.2.1', '2.1.2', '2.1.1',
273
'3', '2', '1.1.1', '1'],
275
# 3 and 2.1.2 are not part of 2.2.1 ancestry and should not appear
276
self.assertIterRevids(['2.2.1', '2.1.1', '2', '1.1.1', '1'],
277
branch, start_revision_id='2.2.1',
278
stop_rule='with-merges')
280
def test_merge_sorted_with_different_depths_merge(self):
281
branch = self.make_branch_with_different_depths_merges()
282
self.assertIterRevids(['4', '2.1.3', '2.2.1', '2.1.2', '2.1.1',
284
'1.2.3', '1.3.3', '1.3.2', '1.3.1',
285
'1.2.2', '1.2.1', '1.1.1',
288
# 3 (and its descendants) and 2.1.2 are not part of 2.2.1 ancestry and
290
self.assertIterRevids(['2.2.1', '2.1.1', '2', '1'],
291
branch, start_revision_id='2.2.1',
292
stop_rule='with-merges')
294
def test_merge_sorted_exclude_ancestry(self):
295
branch = self.make_branch_with_alternate_ancestries()
296
self.assertIterRevids(['3', '1.1.2', '1.2.1', '2', '1.1.1', '1'],
298
# '2' is not part of the ancestry even if merge_sort order will make it
299
# appear before 1.1.1
300
self.assertIterRevids(['1.1.2', '1.2.1'],
302
stop_rule='with-merges-without-common-ancestry',
303
start_revision_id='1.1.2',
304
stop_revision_id='1.1.1')