~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_missing.py

  • Committer: Alexander Belchenko
  • Date: 2008-02-07 07:53:19 UTC
  • mto: This revision was merged to the branch mainline in revision 3231.
  • Revision ID: bialix@ukr.net-20080207075319-d9jj7as8i5ztiff7
some cleanup in package_mf.py; mention about load_from_zip() deprecation in NEWS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2009, 2011 Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
from bzrlib import (
18
 
    missing,
19
 
    tests,
20
 
    )
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
import os
 
18
 
 
19
 
21
20
from bzrlib.missing import (
 
21
    find_unmerged,
 
22
    iter_log_data,
22
23
    iter_log_revisions,
23
24
    )
 
25
from bzrlib.symbol_versioning import zero_seventeen
24
26
from bzrlib.tests import TestCaseWithTransport
 
27
from bzrlib.workingtree import WorkingTree
25
28
 
26
29
 
27
30
class TestMissing(TestCaseWithTransport):
28
31
 
29
 
    def assertUnmerged(self, expected, source, target, restrict='all',
30
 
                       backward=False):
31
 
        unmerged = missing.find_unmerged(source, target, restrict=restrict,
32
 
                                         backward=backward)
33
 
        self.assertEqual(expected, unmerged)
34
 
 
35
32
    def test_find_unmerged(self):
36
33
        original_tree = self.make_branch_and_tree('original')
37
34
        original = original_tree.branch
39
36
        puller = puller_tree.branch
40
37
        merger_tree = self.make_branch_and_tree('merger')
41
38
        merger = merger_tree.branch
42
 
        self.assertUnmerged(([], []), original, puller)
 
39
        self.assertEqual(find_unmerged(original, puller), ([], []))
43
40
        original_tree.commit('a', rev_id='a')
44
 
        self.assertUnmerged(([('1', 'a')], []), original, puller)
 
41
        self.assertEqual(find_unmerged(original, puller), ([(1, u'a')], []))
45
42
        puller_tree.pull(original)
46
 
        self.assertUnmerged(([], []), original, puller)
 
43
        self.assertEqual(find_unmerged(original, puller), ([], []))
47
44
        merger_tree.pull(original)
48
45
        original_tree.commit('b', rev_id='b')
49
46
        original_tree.commit('c', rev_id='c')
50
 
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
51
 
                            original, puller)
52
 
        self.assertUnmerged(([('3', 'c'), ('2', 'b')], []),
53
 
                            original, puller, backward=True)
 
47
        self.assertEqual(find_unmerged(original, puller), ([(2, u'b'), 
 
48
                                                            (3, u'c')], []))
54
49
 
55
50
        puller_tree.pull(original)
56
 
        self.assertUnmerged(([], []), original, puller)
57
 
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
58
 
                            original, merger)
 
51
        self.assertEqual(find_unmerged(original, puller), ([], []))
 
52
        self.assertEqual(find_unmerged(original, merger), ([(2, u'b'), 
 
53
                                                            (3, u'c')], []))
59
54
        merger_tree.merge_from_branch(original)
60
 
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
61
 
                            original, merger)
 
55
        self.assertEqual(find_unmerged(original, merger), ([(2, u'b'), 
 
56
                                                            (3, u'c')], []))
62
57
        merger_tree.commit('d', rev_id='d')
63
 
        self.assertUnmerged(([], [('2', 'd')]), original, merger)
 
58
        self.assertEqual(find_unmerged(original, merger), ([], [(2, 'd')]))
 
59
 
 
60
    def test_iter_log_data(self):
 
61
        base_tree = self.make_branch_and_tree('base')
 
62
        self.build_tree(['base/a'])
 
63
        base_tree.add(['a'], ['a-id'])
 
64
        base_tree.commit('add a', rev_id='b-1')
 
65
 
 
66
        child_tree = base_tree.bzrdir.sprout('child').open_workingtree()
 
67
 
 
68
        self.build_tree(['child/b'])
 
69
        child_tree.add(['b'], ['b-id'])
 
70
        child_tree.commit('adding b', rev_id='c-2')
 
71
 
 
72
        child_tree.remove(['a'])
 
73
        child_tree.commit('removing a', rev_id='c-3')
 
74
 
 
75
        self.build_tree_contents([('child/b', 'new contents for b\n')])
 
76
        child_tree.commit('modifying b', rev_id='c-4')
 
77
 
 
78
        child_tree.rename_one('b', 'c')
 
79
        child_tree.commit('rename b=>c', rev_id='c-5')
 
80
 
 
81
        base_extra, child_extra = find_unmerged(base_tree.branch,
 
82
                                                child_tree.branch)
 
83
        results = list(self.applyDeprecated(zero_seventeen, iter_log_data,
 
84
                            base_extra,
 
85
                            base_tree.branch.repository,
 
86
                            verbose=True))
 
87
        self.assertEqual([], results)
 
88
 
 
89
        results = list(self.applyDeprecated(zero_seventeen, iter_log_data,
 
90
                            child_extra,
 
91
                            child_tree.branch.repository,
 
92
                            verbose=True))
 
93
        self.assertEqual(4, len(results))
 
94
 
 
95
        r0,r1,r2,r3 = results
 
96
 
 
97
        self.assertEqual((2, 'c-2'), (r0[0], r0[1].revision_id))
 
98
        self.assertEqual((3, 'c-3'), (r1[0], r1[1].revision_id))
 
99
        self.assertEqual((4, 'c-4'), (r2[0], r2[1].revision_id))
 
100
        self.assertEqual((5, 'c-5'), (r3[0], r3[1].revision_id))
 
101
 
 
102
        delta0 = r0[2]
 
103
        self.assertNotEqual(None, delta0)
 
104
        self.assertEqual([('b', 'b-id', 'file')], delta0.added)
 
105
        self.assertEqual([], delta0.removed)
 
106
        self.assertEqual([], delta0.renamed)
 
107
        self.assertEqual([], delta0.modified)
 
108
 
 
109
        delta1 = r1[2]
 
110
        self.assertNotEqual(None, delta1)
 
111
        self.assertEqual([], delta1.added)
 
112
        self.assertEqual([('a', 'a-id', 'file')], delta1.removed)
 
113
        self.assertEqual([], delta1.renamed)
 
114
        self.assertEqual([], delta1.modified)
 
115
 
 
116
        delta2 = r2[2]
 
117
        self.assertNotEqual(None, delta2)
 
118
        self.assertEqual([], delta2.added)
 
119
        self.assertEqual([], delta2.removed)
 
120
        self.assertEqual([], delta2.renamed)
 
121
        self.assertEqual([('b', 'b-id', 'file', True, False)], delta2.modified)
 
122
 
 
123
        delta3 = r3[2]
 
124
        self.assertNotEqual(None, delta3)
 
125
        self.assertEqual([], delta3.added)
 
126
        self.assertEqual([], delta3.removed)
 
127
        self.assertEqual([('b', 'c', 'b-id', 'file', False, False)],
 
128
                         delta3.renamed)
 
129
        self.assertEqual([], delta3.modified)
64
130
 
65
131
    def test_iter_log_revisions(self):
66
132
        base_tree = self.make_branch_and_tree('base')
83
149
        child_tree.rename_one('b', 'c')
84
150
        child_tree.commit('rename b=>c', rev_id='c-5')
85
151
 
86
 
        base_extra, child_extra = missing.find_unmerged(base_tree.branch,
87
 
                                                        child_tree.branch)
88
 
        results = list(iter_log_revisions(base_extra,
 
152
        base_extra, child_extra = find_unmerged(base_tree.branch,
 
153
                                                child_tree.branch)
 
154
        results = list(iter_log_revisions(base_extra, 
89
155
                            base_tree.branch.repository,
90
156
                            verbose=True))
91
157
        self.assertEqual([], results)
97
163
 
98
164
        r0,r1,r2,r3 = results
99
165
 
100
 
        self.assertEqual([('2', 'c-2'), ('3', 'c-3'),
101
 
                          ('4', 'c-4'), ('5', 'c-5'),],
102
 
                         [(r.revno, r.rev.revision_id) for r in results])
 
166
        self.assertEqual((2, 'c-2'), (r0.revno, r0.rev.revision_id))
 
167
        self.assertEqual((3, 'c-3'), (r1.revno, r1.rev.revision_id))
 
168
        self.assertEqual((4, 'c-4'), (r2.revno, r2.rev.revision_id))
 
169
        self.assertEqual((5, 'c-5'), (r3.revno, r3.rev.revision_id))
103
170
 
104
171
        delta0 = r0.delta
105
172
        self.assertNotEqual(None, delta0)
129
196
        self.assertEqual([('b', 'c', 'b-id', 'file', False, False)],
130
197
                         delta3.renamed)
131
198
        self.assertEqual([], delta3.modified)
132
 
 
133
 
 
134
 
class TestFindUnmerged(tests.TestCaseWithTransport):
135
 
 
136
 
    def assertUnmerged(self, local, remote, local_branch, remote_branch,
137
 
            restrict='all', include_merged=False, backward=False,
138
 
            local_revid_range=None, remote_revid_range=None):
139
 
        """Check the output of find_unmerged_mainline_revisions"""
140
 
        local_extra, remote_extra = missing.find_unmerged(
141
 
            local_branch, remote_branch, restrict,
142
 
            include_merged=include_merged, backward=backward,
143
 
            local_revid_range=local_revid_range,
144
 
            remote_revid_range=remote_revid_range)
145
 
        self.assertEqual(local, local_extra)
146
 
        self.assertEqual(remote, remote_extra)
147
 
 
148
 
    def test_same_branch(self):
149
 
        tree = self.make_branch_and_tree('tree')
150
 
        rev1 = tree.commit('one')
151
 
        tree.lock_read()
152
 
        self.addCleanup(tree.unlock)
153
 
        self.assertUnmerged([], [], tree.branch, tree.branch)
154
 
        self.assertUnmerged([], [], tree.branch, tree.branch,
155
 
            local_revid_range=(rev1, rev1))
156
 
 
157
 
    def test_one_ahead(self):
158
 
        tree = self.make_branch_and_tree('tree')
159
 
        rev1 = tree.commit('one')
160
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
161
 
        rev2 = tree2.commit('two')
162
 
        self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch)
163
 
        self.assertUnmerged([('2', rev2)], [], tree2.branch, tree.branch)
164
 
 
165
 
    def test_restrict(self):
166
 
        tree = self.make_branch_and_tree('tree')
167
 
        rev1 = tree.commit('one')
168
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
169
 
        rev2 = tree2.commit('two')
170
 
        self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch)
171
 
        self.assertUnmerged([], None, tree.branch, tree2.branch, 'local')
172
 
        self.assertUnmerged(None, [('2', rev2)], tree.branch, tree2.branch,
173
 
                                               'remote')
174
 
 
175
 
    def test_merged(self):
176
 
        tree = self.make_branch_and_tree('tree')
177
 
        rev1 = tree.commit('one')
178
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
179
 
        rev2 = tree2.commit('two')
180
 
        rev3 = tree2.commit('three')
181
 
        tree.merge_from_branch(tree2.branch)
182
 
        rev4 = tree.commit('four')
183
 
 
184
 
        self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch)
185
 
        self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch,
186
 
            local_revid_range=(rev4, rev4))
187
 
        self.assertUnmerged([], [], tree.branch, tree2.branch,
188
 
            local_revid_range=(rev1, rev1))
189
 
 
190
 
    def test_include_merged(self):
191
 
        tree = self.make_branch_and_tree('tree')
192
 
        rev1 = tree.commit('one', rev_id='rev1')
193
 
 
194
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
195
 
        rev2 = tree2.commit('two', rev_id='rev2')
196
 
        rev3 = tree2.commit('three', rev_id='rev3')
197
 
 
198
 
        tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
199
 
        rev4 = tree3.commit('four', rev_id='rev4')
200
 
        rev5 = tree3.commit('five', rev_id='rev5')
201
 
 
202
 
        tree2.merge_from_branch(tree3.branch)
203
 
        rev6 = tree2.commit('six', rev_id='rev6')
204
 
 
205
 
        self.assertUnmerged([], [('2', 'rev2', 0), ('3', 'rev3', 0),
206
 
                                 ('4', 'rev6', 0),
207
 
                                 ('3.1.1', 'rev4', 1), ('3.1.2', 'rev5', 1),
208
 
                                 ],
209
 
                            tree.branch, tree2.branch,
210
 
                            include_merged=True)
211
 
 
212
 
        self.assertUnmerged([], [('4', 'rev6', 0),
213
 
                                 ('3.1.2', 'rev5', 1), ('3.1.1', 'rev4', 1),
214
 
                                 ('3', 'rev3', 0), ('2', 'rev2', 0),
215
 
                                 ],
216
 
                            tree.branch, tree2.branch,
217
 
                            include_merged=True,
218
 
                            backward=True)
219
 
 
220
 
        self.assertUnmerged([], [('4', 'rev6', 0)],
221
 
            tree.branch, tree2.branch,
222
 
            include_merged=True, remote_revid_range=(rev6, rev6))
223
 
 
224
 
        self.assertUnmerged([], [('3', 'rev3', 0), ('3.1.1', 'rev4', 1)],
225
 
                    tree.branch, tree2.branch,
226
 
                    include_merged=True, remote_revid_range=(rev3, rev4))
227
 
 
228
 
        self.assertUnmerged([], [('4', 'rev6', 0), ('3.1.2', 'rev5', 1)],
229
 
                    tree.branch, tree2.branch,
230
 
                    include_merged=True, remote_revid_range=(rev5, rev6))
231
 
 
232
 
    def test_revision_range(self):
233
 
        local = self.make_branch_and_tree('local')
234
 
        lrevid1 = local.commit('one')
235
 
        remote = local.bzrdir.sprout('remote').open_workingtree()
236
 
        rrevid2 = remote.commit('two')
237
 
        rrevid3 = remote.commit('three')
238
 
        rrevid4 = remote.commit('four')
239
 
        lrevid2 = local.commit('two')
240
 
        lrevid3 = local.commit('three')
241
 
        lrevid4 = local.commit('four')
242
 
        local_extra = [('2', lrevid2), ('3', lrevid3), ('4', lrevid4)]
243
 
        remote_extra = [('2', rrevid2), ('3', rrevid3), ('4', rrevid4)]
244
 
 
245
 
        # control
246
 
        self.assertUnmerged(local_extra, remote_extra,
247
 
            local.branch, remote.branch)
248
 
        self.assertUnmerged(local_extra, remote_extra,
249
 
            local.branch, remote.branch, local_revid_range=(None, None),
250
 
            remote_revid_range=(None, None))
251
 
 
252
 
        # exclude local revisions
253
 
        self.assertUnmerged([('2', lrevid2)], remote_extra,
254
 
            local.branch, remote.branch, local_revid_range=(lrevid2, lrevid2))
255
 
        self.assertUnmerged([('2', lrevid2), ('3', lrevid3)], remote_extra,
256
 
            local.branch, remote.branch, local_revid_range=(lrevid2, lrevid3))
257
 
        self.assertUnmerged([('2', lrevid2), ('3', lrevid3)], None,
258
 
            local.branch, remote.branch, 'local',
259
 
            local_revid_range=(lrevid2, lrevid3))
260
 
 
261
 
        # exclude remote revisions
262
 
        self.assertUnmerged(local_extra, [('2', rrevid2)],
263
 
            local.branch, remote.branch, remote_revid_range=(None, rrevid2))
264
 
        self.assertUnmerged(local_extra, [('2', rrevid2)],
265
 
            local.branch, remote.branch, remote_revid_range=(lrevid1, rrevid2))
266
 
        self.assertUnmerged(local_extra, [('2', rrevid2)],
267
 
            local.branch, remote.branch, remote_revid_range=(rrevid2, rrevid2))
268
 
        self.assertUnmerged(local_extra, [('2', rrevid2), ('3', rrevid3)],
269
 
            local.branch, remote.branch, remote_revid_range=(None, rrevid3))
270
 
        self.assertUnmerged(local_extra, [('2', rrevid2), ('3', rrevid3)],
271
 
            local.branch, remote.branch, remote_revid_range=(rrevid2, rrevid3))
272
 
        self.assertUnmerged(local_extra, [('3', rrevid3)],
273
 
            local.branch, remote.branch, remote_revid_range=(rrevid3, rrevid3))
274
 
        self.assertUnmerged(None, [('2', rrevid2), ('3', rrevid3)],
275
 
            local.branch, remote.branch, 'remote',
276
 
            remote_revid_range=(rrevid2, rrevid3))
277
 
 
278
 
        # exclude local and remote revisions
279
 
        self.assertUnmerged([('3', lrevid3)], [('3', rrevid3)],
280
 
            local.branch, remote.branch, local_revid_range=(lrevid3, lrevid3),
281
 
            remote_revid_range=(rrevid3, rrevid3))