~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_branch/test_iter_merge_sorted_revisions.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from bzrlib.tests import per_branch
26
26
 
27
27
 
28
 
class TestIterMergeSortedRevisionsSimpleGraph(per_branch.TestCaseWithBranch):
 
28
class TestIterMergeSortedRevisions(per_branch.TestCaseWithBranch):
29
29
 
30
30
    def setUp(self):
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('.')
36
33
 
37
 
    def make_builder_with_merges(self, relpath):
 
34
    def make_branch_with_merges(self, relpath):
38
35
        try:
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()
43
 
        # 1
44
 
        # |\
45
 
        # 2 |
46
 
        # | |
47
 
        # | 1.1.1
48
 
        # |/
49
 
        # 3
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()
56
 
        return builder
 
46
        return builder.get_branch()
 
47
 
57
48
 
58
49
    def assertIterRevids(self, expected, *args, **kwargs):
59
50
        # We don't care about depths and revnos here, only about returning the
60
51
        # right revids.
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)
64
55
 
65
56
    def test_merge_sorted(self):
66
57
        self.assertIterRevids(['3', '1.1.1', '2', '1'])
67
58
 
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')
71
62
 
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')
75
66
 
76
67
    def test_merge_sorted_range_stop_exclude(self):
114
105
        self.assertIterRevids(['1', '2', '1.1.1', '3'], direction='forward')
115
106
 
116
107
    def test_merge_sorted_range_forward(self):
117
 
        self.assertIterRevids(['1.1.1'],
 
108
        self.assertIterRevids(['2', '1.1.1'],
118
109
                              start_revision_id='1.1.1', stop_revision_id='1',
119
110
                              direction='forward')
120
111
 
121
112
    def test_merge_sorted_range_start_only_forward(self):
122
 
        self.assertIterRevids(['1', '1.1.1'],
 
113
        self.assertIterRevids(['1', '2', '1.1.1'],
123
114
                              start_revision_id='1.1.1', direction='forward')
124
115
 
125
116
    def test_merge_sorted_range_stop_exclude_forward(self):
135
126
        self.assertIterRevids(['1.1.1', '3'],
136
127
                              stop_revision_id='3', stop_rule='with-merges',
137
128
                              direction='forward')
138
 
 
139
 
 
140
 
class TestIterMergeSortedRevisionsBushyGraph(per_branch.TestCaseWithBranch):
141
 
 
142
 
    def make_branch_builder(self, relpath):
143
 
        try:
144
 
            builder = super(TestIterMergeSortedRevisionsBushyGraph,
145
 
                            self).make_branch_builder(relpath)
146
 
        except (errors.TransportNotPossible, errors.UninitializableFormat):
147
 
            raise tests.TestNotApplicable('format not directly constructable')
148
 
        return builder
149
 
 
150
 
    def make_branch_with_embedded_merges(self, relpath='.'):
151
 
        builder = self.make_branch_builder(relpath)
152
 
        # 1
153
 
        # |\
154
 
        # | 1.1.1
155
 
        # | /
156
 
        # 2
157
 
        # | \
158
 
        # 3 |
159
 
        # | |
160
 
        # | 2.1.1
161
 
        # | |    \
162
 
        # | 2.1.2 |
163
 
        # | |     |
164
 
        # | |   2.2.1
165
 
        # | |  /
166
 
        # | 2.1.3
167
 
        # |/
168
 
        # 4
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()
182
 
        br.lock_read()
183
 
        self.addCleanup(br.unlock)
184
 
        return br
185
 
 
186
 
    def make_branch_with_different_depths_merges(self, relpath='.'):
187
 
        builder = self.make_branch_builder(relpath)
188
 
        # 1
189
 
        # |\
190
 
        # | 1.1.1
191
 
        # | /
192
 
        # 2
193
 
        # | \
194
 
        # 3 |
195
 
        # | |
196
 
        # | 2.1.1
197
 
        # | |    \
198
 
        # | 2.1.2 |
199
 
        # | |     |
200
 
        # | |     2.2.1
201
 
        # | |    /
202
 
        # | 2.1.3
203
 
        # |/
204
 
        # 4
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'],
225
 
                               [])
226
 
        builder.finish_series()
227
 
        br = builder.get_branch()
228
 
        br.lock_read()
229
 
        self.addCleanup(br.unlock)
230
 
        return br
231
 
 
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)
239
 
        # 1
240
 
        # |\
241
 
        # | 1.1.1
242
 
        # | /| \
243
 
        # 2  |  |
244
 
        # |  |  1.2.1
245
 
        # |  | /
246
 
        # |  1.1.2
247
 
        # | /
248
 
        # 3
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()
259
 
        br.lock_read()
260
 
        self.addCleanup(br.unlock)
261
 
        return br
262
 
 
263
 
    def assertIterRevids(self, expected, branch, *args, **kwargs):
264
 
        # We don't care about depths and revnos here, only about returning the
265
 
        # right revids.
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)
269
 
 
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'],
274
 
                              branch)
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')
279
 
 
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',
283
 
                               '3',
284
 
                               '1.2.3', '1.3.3', '1.3.2', '1.3.1',
285
 
                               '1.2.2', '1.2.1', '1.1.1',
286
 
                               '2', '1'],
287
 
                              branch)
288
 
        # 3 (and its descendants) and 2.1.2 are not part of 2.2.1 ancestry and
289
 
        # should not appear
290
 
        self.assertIterRevids(['2.2.1', '2.1.1', '2', '1'],
291
 
                              branch, start_revision_id='2.2.1',
292
 
                              stop_rule='with-merges')
293
 
 
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'],
297
 
                              branch)
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'],
301
 
                              branch,
302
 
                              stop_rule='with-merges-without-common-ancestry',
303
 
                              start_revision_id='1.1.2',
304
 
                              stop_revision_id='1.1.1')
305