/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_missing.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-09 21:42:24 UTC
  • mto: This revision was merged to the branch mainline in revision 3543.
  • Revision ID: john@arbash-meinel.com-20080709214224-r75k87r6a01pfc3h
Restore a real weave merge to 'bzr merge --weave'.

To do so efficiently, we only add the simple LCAs to the final weave
object, unless we run into complexities with the merge graph.
This gives the same effective result as adding all the texts,
with the advantage of not having to extract all of them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
18
 
30
30
 
31
31
class TestMissing(TestCaseWithTransport):
32
32
 
33
 
    def assertUnmerged(self, expected, source, target, restrict='all',
34
 
                       backward=False):
35
 
        unmerged = missing.find_unmerged(source, target, restrict=restrict,
36
 
                                         backward=backward)
 
33
    def assertUnmerged(self, expected, source, target, restrict='all'):
 
34
        unmerged = missing.find_unmerged(source, target, restrict=restrict)
37
35
        self.assertEqual(expected, unmerged)
38
 
 
 
36
            
39
37
    def test_find_unmerged(self):
40
38
        original_tree = self.make_branch_and_tree('original')
41
39
        original = original_tree.branch
45
43
        merger = merger_tree.branch
46
44
        self.assertUnmerged(([], []), original, puller)
47
45
        original_tree.commit('a', rev_id='a')
48
 
        self.assertUnmerged(([('1', 'a')], []), original, puller)
 
46
        self.assertUnmerged(([(1, 'a')], []), original, puller)
49
47
        puller_tree.pull(original)
50
48
        self.assertUnmerged(([], []), original, puller)
51
49
        merger_tree.pull(original)
52
50
        original_tree.commit('b', rev_id='b')
53
51
        original_tree.commit('c', rev_id='c')
54
 
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
 
52
        self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
55
53
                            original, puller)
56
 
        self.assertUnmerged(([('3', 'c'), ('2', 'b')], []),
57
 
                            original, puller, backward=True)
58
54
 
59
55
        puller_tree.pull(original)
60
56
        self.assertUnmerged(([], []), original, puller)
61
 
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
 
57
        self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
62
58
                            original, merger)
63
59
        merger_tree.merge_from_branch(original)
64
 
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
 
60
        self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
65
61
                            original, merger)
66
62
        merger_tree.commit('d', rev_id='d')
67
 
        self.assertUnmerged(([], [('2', 'd')]), original, merger)
 
63
        self.assertUnmerged(([], [(2, 'd')]), original, merger)
68
64
 
69
65
    def test_iter_log_revisions(self):
70
66
        base_tree = self.make_branch_and_tree('base')
89
85
 
90
86
        base_extra, child_extra = missing.find_unmerged(base_tree.branch,
91
87
                                                        child_tree.branch)
92
 
        results = list(iter_log_revisions(base_extra,
 
88
        results = list(iter_log_revisions(base_extra, 
93
89
                            base_tree.branch.repository,
94
90
                            verbose=True))
95
91
        self.assertEqual([], results)
101
97
 
102
98
        r0,r1,r2,r3 = results
103
99
 
104
 
        self.assertEqual([('2', 'c-2'), ('3', 'c-3'),
105
 
                          ('4', 'c-4'), ('5', 'c-5'),],
106
 
                         [(r.revno, r.rev.revision_id) for r in results])
 
100
        self.assertEqual((2, 'c-2'), (r0.revno, r0.rev.revision_id))
 
101
        self.assertEqual((3, 'c-3'), (r1.revno, r1.rev.revision_id))
 
102
        self.assertEqual((4, 'c-4'), (r2.revno, r2.rev.revision_id))
 
103
        self.assertEqual((5, 'c-5'), (r3.revno, r3.rev.revision_id))
107
104
 
108
105
        delta0 = r0.delta
109
106
        self.assertNotEqual(None, delta0)
138
135
class TestFindUnmerged(tests.TestCaseWithTransport):
139
136
 
140
137
    def assertUnmerged(self, local, remote, local_branch, remote_branch,
141
 
            restrict='all', include_merges=False, backward=False,
142
 
            local_revid_range=None, remote_revid_range=None):
 
138
                       restrict):
143
139
        """Check the output of find_unmerged_mainline_revisions"""
144
140
        local_extra, remote_extra = missing.find_unmerged(
145
 
            local_branch, remote_branch, restrict,
146
 
            include_merges=include_merges, backward=backward,
147
 
            local_revid_range=local_revid_range,
148
 
            remote_revid_range=remote_revid_range)
 
141
                                        local_branch, remote_branch, restrict)
149
142
        self.assertEqual(local, local_extra)
150
143
        self.assertEqual(remote, remote_extra)
151
144
 
154
147
        rev1 = tree.commit('one')
155
148
        tree.lock_read()
156
149
        self.addCleanup(tree.unlock)
157
 
        self.assertUnmerged([], [], tree.branch, tree.branch)
158
 
        self.assertUnmerged([], [], tree.branch, tree.branch,
159
 
            local_revid_range=(rev1, rev1))
 
150
        self.assertUnmerged([], [], tree.branch, tree.branch, 'all')
160
151
 
161
152
    def test_one_ahead(self):
162
153
        tree = self.make_branch_and_tree('tree')
163
154
        rev1 = tree.commit('one')
164
155
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
165
156
        rev2 = tree2.commit('two')
166
 
        self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch)
167
 
        self.assertUnmerged([('2', rev2)], [], tree2.branch, tree.branch)
 
157
        tree.lock_read()
 
158
        self.addCleanup(tree.unlock)
 
159
        tree2.lock_read()
 
160
        self.addCleanup(tree2.unlock)
 
161
        self.assertUnmerged([], [(2, rev2)], tree.branch, tree2.branch, 'all')
 
162
        self.assertUnmerged([(2, rev2)], [], tree2.branch, tree.branch, 'all')
168
163
 
169
164
    def test_restrict(self):
170
165
        tree = self.make_branch_and_tree('tree')
171
166
        rev1 = tree.commit('one')
172
167
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
173
168
        rev2 = tree2.commit('two')
174
 
        self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch)
 
169
        tree.lock_read()
 
170
        self.addCleanup(tree.unlock)
 
171
        tree2.lock_read()
 
172
        self.addCleanup(tree2.unlock)
 
173
        self.assertUnmerged([], [(2, rev2)], tree.branch, tree2.branch, 'all')
175
174
        self.assertUnmerged([], None, tree.branch, tree2.branch, 'local')
176
 
        self.assertUnmerged(None, [('2', rev2)], tree.branch, tree2.branch,
 
175
        self.assertUnmerged(None, [(2, rev2)], tree.branch, tree2.branch,
177
176
                                               'remote')
178
177
 
179
178
    def test_merged(self):
185
184
        tree.merge_from_branch(tree2.branch)
186
185
        rev4 = tree.commit('four')
187
186
 
188
 
        self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch)
189
 
        self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch,
190
 
            local_revid_range=(rev4, rev4))
191
 
        self.assertUnmerged([], [], tree.branch, tree2.branch,
192
 
            local_revid_range=(rev1, rev1))
193
 
 
194
 
    def test_include_merges(self):
195
 
        tree = self.make_branch_and_tree('tree')
196
 
        rev1 = tree.commit('one', rev_id='rev1')
197
 
 
198
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
199
 
        rev2 = tree2.commit('two', rev_id='rev2')
200
 
        rev3 = tree2.commit('three', rev_id='rev3')
201
 
 
202
 
        tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
203
 
        rev4 = tree3.commit('four', rev_id='rev4')
204
 
        rev5 = tree3.commit('five', rev_id='rev5')
205
 
 
206
 
        tree2.merge_from_branch(tree3.branch)
207
 
        rev6 = tree2.commit('six', rev_id='rev6')
208
 
 
209
 
        self.assertUnmerged([], [('2', 'rev2', 0), ('3', 'rev3', 0),
210
 
                                 ('4', 'rev6', 0),
211
 
                                 ('3.1.1', 'rev4', 1), ('3.1.2', 'rev5', 1),
212
 
                                 ],
213
 
                            tree.branch, tree2.branch,
214
 
                            include_merges=True)
215
 
 
216
 
        self.assertUnmerged([], [('4', 'rev6', 0),
217
 
                                 ('3.1.2', 'rev5', 1), ('3.1.1', 'rev4', 1),
218
 
                                 ('3', 'rev3', 0), ('2', 'rev2', 0),
219
 
                                 ],
220
 
                            tree.branch, tree2.branch,
221
 
                            include_merges=True,
222
 
                            backward=True)
223
 
 
224
 
        self.assertUnmerged([], [('4', 'rev6', 0)],
225
 
            tree.branch, tree2.branch,
226
 
            include_merges=True, remote_revid_range=(rev6, rev6))
227
 
 
228
 
        self.assertUnmerged([], [('3', 'rev3', 0), ('3.1.1', 'rev4', 1)],
229
 
                    tree.branch, tree2.branch,
230
 
                    include_merges=True, remote_revid_range=(rev3, rev4))
231
 
 
232
 
        self.assertUnmerged([], [('4', 'rev6', 0), ('3.1.2', 'rev5', 1)],
233
 
                    tree.branch, tree2.branch,
234
 
                    include_merges=True, remote_revid_range=(rev5, rev6))
235
 
 
236
 
    def test_revision_range(self):
237
 
        local = self.make_branch_and_tree('local')
238
 
        lrevid1 = local.commit('one')
239
 
        remote = local.bzrdir.sprout('remote').open_workingtree()
240
 
        rrevid2 = remote.commit('two')
241
 
        rrevid3 = remote.commit('three')
242
 
        rrevid4 = remote.commit('four')
243
 
        lrevid2 = local.commit('two')
244
 
        lrevid3 = local.commit('three')
245
 
        lrevid4 = local.commit('four')
246
 
        local_extra = [('2', lrevid2), ('3', lrevid3), ('4', lrevid4)]
247
 
        remote_extra = [('2', rrevid2), ('3', rrevid3), ('4', rrevid4)]
248
 
 
249
 
        # control
250
 
        self.assertUnmerged(local_extra, remote_extra,
251
 
            local.branch, remote.branch)
252
 
        self.assertUnmerged(local_extra, remote_extra,
253
 
            local.branch, remote.branch, local_revid_range=(None, None),
254
 
            remote_revid_range=(None, None))
255
 
 
256
 
        # exclude local revisions
257
 
        self.assertUnmerged([('2', lrevid2)], remote_extra,
258
 
            local.branch, remote.branch, local_revid_range=(lrevid2, lrevid2))
259
 
        self.assertUnmerged([('2', lrevid2), ('3', lrevid3)], remote_extra,
260
 
            local.branch, remote.branch, local_revid_range=(lrevid2, lrevid3))
261
 
        self.assertUnmerged([('2', lrevid2), ('3', lrevid3)], None,
262
 
            local.branch, remote.branch, 'local',
263
 
            local_revid_range=(lrevid2, lrevid3))
264
 
 
265
 
        # exclude remote revisions
266
 
        self.assertUnmerged(local_extra, [('2', rrevid2)],
267
 
            local.branch, remote.branch, remote_revid_range=(None, rrevid2))
268
 
        self.assertUnmerged(local_extra, [('2', rrevid2)],
269
 
            local.branch, remote.branch, remote_revid_range=(lrevid1, rrevid2))
270
 
        self.assertUnmerged(local_extra, [('2', rrevid2)],
271
 
            local.branch, remote.branch, remote_revid_range=(rrevid2, rrevid2))
272
 
        self.assertUnmerged(local_extra, [('2', rrevid2), ('3', rrevid3)],
273
 
            local.branch, remote.branch, remote_revid_range=(None, rrevid3))
274
 
        self.assertUnmerged(local_extra, [('2', rrevid2), ('3', rrevid3)],
275
 
            local.branch, remote.branch, remote_revid_range=(rrevid2, rrevid3))
276
 
        self.assertUnmerged(local_extra, [('3', rrevid3)],
277
 
            local.branch, remote.branch, remote_revid_range=(rrevid3, rrevid3))
278
 
        self.assertUnmerged(None, [('2', rrevid2), ('3', rrevid3)],
279
 
            local.branch, remote.branch, 'remote',
280
 
            remote_revid_range=(rrevid2, rrevid3))
281
 
 
282
 
        # exclude local and remote revisions
283
 
        self.assertUnmerged([('3', lrevid3)], [('3', rrevid3)],
284
 
            local.branch, remote.branch, local_revid_range=(lrevid3, lrevid3),
285
 
            remote_revid_range=(rrevid3, rrevid3))
 
187
        tree.lock_read()
 
188
        self.addCleanup(tree.unlock)
 
189
        tree2.lock_read()
 
190
        self.addCleanup(tree2.unlock)
 
191
 
 
192
        self.assertUnmerged([(2, rev4)], [], tree.branch, tree2.branch, 'all')