19
19
from bzrlib import (
25
from bzrlib.tests import per_branch
28
class TestIterMergeSortedRevisionsSimpleGraph(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)
37
def make_builder_with_merges(self, relpath):
39
builder = self.make_branch_builder(relpath)
40
except (errors.TransportNotPossible, errors.UninitializableFormat):
41
raise tests.TestNotApplicable('format not directly constructable')
42
builder.start_series()
50
builder.build_snapshot('1', None, [
51
('add', ('', 'TREE_ROOT', 'directory', '')),])
52
builder.build_snapshot('1.1.1', ['1'], [])
53
builder.build_snapshot('2', ['1'], [])
54
builder.build_snapshot('3', ['2', '1.1.1'], [])
55
builder.finish_series()
58
def assertIterRevids(self, expected, *args, **kwargs):
59
# 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)]
63
self.assertEqual(expected, revids)
24
from bzrlib.tests.per_branch import TestCaseWithBranch
27
class TestIterMergeSortedRevisions(TestCaseWithBranch):
65
29
def test_merge_sorted(self):
66
self.assertIterRevids(['3', '1.1.1', '2', '1'])
30
tree = self.create_tree_with_merge()
31
the_branch = tree.bzrdir.open_branch()
33
('rev-3', 0, (3,), False),
34
('rev-1.1.1', 1, (1,1,1), True),
35
('rev-2', 0, (2,), False),
36
('rev-1', 0, (1,), True),
37
], list(the_branch.iter_merge_sorted_revisions()))
68
39
def test_merge_sorted_range(self):
69
self.assertIterRevids(['1.1.1'],
70
start_revision_id='1.1.1', stop_revision_id='1')
40
tree = self.create_tree_with_merge()
41
the_branch = tree.bzrdir.open_branch()
43
('rev-1.1.1', 1, (1,1,1), True),
44
('rev-2', 0, (2,), False),
45
], list(the_branch.iter_merge_sorted_revisions(
46
start_revision_id='rev-1.1.1', stop_revision_id='rev-1')))
72
48
def test_merge_sorted_range_start_only(self):
73
self.assertIterRevids(['1.1.1', '1'],
74
start_revision_id='1.1.1')
49
tree = self.create_tree_with_merge()
50
the_branch = tree.bzrdir.open_branch()
52
('rev-1.1.1', 1, (1,1,1), True),
53
('rev-2', 0, (2,), False),
54
('rev-1', 0, (1,), True),
55
], list(the_branch.iter_merge_sorted_revisions(
56
start_revision_id='rev-1.1.1')))
76
58
def test_merge_sorted_range_stop_exclude(self):
77
self.assertIterRevids(['3', '1.1.1', '2'], stop_revision_id='1')
59
tree = self.create_tree_with_merge()
60
the_branch = tree.bzrdir.open_branch()
62
('rev-3', 0, (3,), False),
63
('rev-1.1.1', 1, (1,1,1), True),
64
('rev-2', 0, (2,), False),
65
], list(the_branch.iter_merge_sorted_revisions(
66
stop_revision_id='rev-1')))
79
68
def test_merge_sorted_range_stop_include(self):
80
self.assertIterRevids(['3', '1.1.1', '2'],
81
stop_revision_id='2', stop_rule='include')
69
tree = self.create_tree_with_merge()
70
the_branch = tree.bzrdir.open_branch()
72
('rev-3', 0, (3,), False),
73
('rev-1.1.1', 1, (1,1,1), True),
74
('rev-2', 0, (2,), False),
75
], list(the_branch.iter_merge_sorted_revisions(
76
stop_revision_id='rev-2', stop_rule='include')))
83
78
def test_merge_sorted_range_stop_with_merges(self):
84
self.assertIterRevids(['3', '1.1.1'],
85
stop_revision_id='3', stop_rule='with-merges')
87
def test_merge_sorted_range_stop_with_merges_can_show_non_parents(self):
88
# 1.1.1 gets logged before the end revision is reached.
89
# so it is returned even though 1.1.1 is not a parent of 2.
90
self.assertIterRevids(['3', '1.1.1', '2'],
91
stop_revision_id='2', stop_rule='with-merges')
93
def test_merge_sorted_range_stop_with_merges_ignore_non_parents(self):
94
# 2 is not a parent of 1.1.1 so it must not be returned
95
self.assertIterRevids(['3', '1.1.1'],
96
stop_revision_id='1.1.1', stop_rule='with-merges')
79
tree = self.create_tree_with_merge()
80
the_branch = tree.bzrdir.open_branch()
82
('rev-3', 0, (3,), False),
83
('rev-1.1.1', 1, (1,1,1), True),
84
], list(the_branch.iter_merge_sorted_revisions(
85
stop_revision_id='rev-3', stop_rule='with-merges')))
98
87
def test_merge_sorted_single_stop_exclude(self):
99
88
# from X..X exclusive is an empty result
100
self.assertIterRevids([], start_revision_id='3', stop_revision_id='3')
89
tree = self.create_tree_with_merge()
90
the_branch = tree.bzrdir.open_branch()
91
self.assertEqual([], list(the_branch.iter_merge_sorted_revisions(
92
start_revision_id='rev-3', stop_revision_id='rev-3')))
102
94
def test_merge_sorted_single_stop_include(self):
103
95
# from X..X inclusive is [X]
104
self.assertIterRevids(['3'],
105
start_revision_id='3', stop_revision_id='3',
96
tree = self.create_tree_with_merge()
97
the_branch = tree.bzrdir.open_branch()
99
('rev-3', 0, (3,), False),
100
], list(the_branch.iter_merge_sorted_revisions(
101
start_revision_id='rev-3', stop_revision_id='rev-3',
102
stop_rule='include')))
108
104
def test_merge_sorted_single_stop_with_merges(self):
109
self.assertIterRevids(['3', '1.1.1'],
110
start_revision_id='3', stop_revision_id='3',
111
stop_rule='with-merges')
105
tree = self.create_tree_with_merge()
106
the_branch = tree.bzrdir.open_branch()
108
('rev-3', 0, (3,), False),
109
('rev-1.1.1', 1, (1,1,1), True),
110
], list(the_branch.iter_merge_sorted_revisions(
111
start_revision_id='rev-3', stop_revision_id='rev-3',
112
stop_rule='with-merges')))
113
114
def test_merge_sorted_forward(self):
114
self.assertIterRevids(['1', '2', '1.1.1', '3'], direction='forward')
115
tree = self.create_tree_with_merge()
116
the_branch = tree.bzrdir.open_branch()
118
('rev-1', 0, (1,), True),
119
('rev-2', 0, (2,), False),
120
('rev-1.1.1', 1, (1,1,1), True),
121
('rev-3', 0, (3,), False),
122
], list(the_branch.iter_merge_sorted_revisions(
123
direction='forward')))
116
125
def test_merge_sorted_range_forward(self):
117
self.assertIterRevids(['1.1.1'],
118
start_revision_id='1.1.1', stop_revision_id='1',
126
tree = self.create_tree_with_merge()
127
the_branch = tree.bzrdir.open_branch()
129
('rev-2', 0, (2,), False),
130
('rev-1.1.1', 1, (1,1,1), True),
131
], list(the_branch.iter_merge_sorted_revisions(
132
start_revision_id='rev-1.1.1', stop_revision_id='rev-1',
133
direction='forward')))
121
135
def test_merge_sorted_range_start_only_forward(self):
122
self.assertIterRevids(['1', '1.1.1'],
123
start_revision_id='1.1.1', direction='forward')
136
tree = self.create_tree_with_merge()
137
the_branch = tree.bzrdir.open_branch()
139
('rev-1', 0, (1,), True),
140
('rev-2', 0, (2,), False),
141
('rev-1.1.1', 1, (1,1,1), True),
142
], list(the_branch.iter_merge_sorted_revisions(
143
start_revision_id='rev-1.1.1', direction='forward')))
125
145
def test_merge_sorted_range_stop_exclude_forward(self):
126
self.assertIterRevids(['2', '1.1.1', '3'],
127
stop_revision_id='1', direction='forward')
146
tree = self.create_tree_with_merge()
147
the_branch = tree.bzrdir.open_branch()
149
('rev-2', 0, (2,), False),
150
('rev-1.1.1', 1, (1,1,1), True),
151
('rev-3', 0, (3,), False),
152
], list(the_branch.iter_merge_sorted_revisions(
153
stop_revision_id='rev-1', direction='forward')))
129
155
def test_merge_sorted_range_stop_include_forward(self):
130
self.assertIterRevids(['2', '1.1.1', '3'],
131
stop_revision_id='2', stop_rule='include',
156
tree = self.create_tree_with_merge()
157
the_branch = tree.bzrdir.open_branch()
159
('rev-2', 0, (2,), False),
160
('rev-1.1.1', 1, (1,1,1), True),
161
('rev-3', 0, (3,), False),
162
], list(the_branch.iter_merge_sorted_revisions(
163
stop_revision_id='rev-2', stop_rule='include',
164
direction='forward')))
134
166
def test_merge_sorted_range_stop_with_merges_forward(self):
135
self.assertIterRevids(['1.1.1', '3'],
136
stop_revision_id='3', stop_rule='with-merges',
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')
167
tree = self.create_tree_with_merge()
168
the_branch = tree.bzrdir.open_branch()
170
('rev-1.1.1', 1, (1,1,1), True),
171
('rev-3', 0, (3,), False),
172
], list(the_branch.iter_merge_sorted_revisions(
173
stop_revision_id='rev-3', stop_rule='with-merges',
174
direction='forward')))