~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Joe Julian
  • Date: 2010-01-10 02:25:31 UTC
  • mto: (4634.119.7 2.0)
  • mto: This revision was merged to the branch mainline in revision 4959.
  • Revision ID: joe@julianfamily.org-20100110022531-wqk61rsagz8xsiga
Added MANIFEST.in to allow bdist_rpm to have all the required include files and tools. bdist_rpm will still fail to build correctly on some distributions due to a disttools bug http://bugs.python.org/issue644744

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    format_registry,
35
35
    )
36
36
from bzrlib.inventory import Inventory
37
 
from bzrlib.revision import Revision
 
37
from bzrlib.revision import (
 
38
    NULL_REVISION,
 
39
    Revision,
 
40
    )
38
41
from bzrlib.tests import (
39
42
    TestCase,
40
43
    TestCaseWithTransport,
101
104
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, 
102
105
            *args, **kwargs)
103
106
 
104
 
    def dpull(self, source, stop_revision=None):
105
 
        source.lock_read()
 
107
 
 
108
class InterToDummyVcsBranch(branch.GenericInterBranch,
 
109
                            foreign.InterToForeignBranch):
 
110
 
 
111
    @staticmethod
 
112
    def is_compatible(source, target):
 
113
        return isinstance(target, DummyForeignVcsBranch)
 
114
 
 
115
    def lossy_push(self, stop_revision=None):
 
116
        result = branch.BranchPushResult()
 
117
        result.source_branch = self.source
 
118
        result.target_branch = self.target
 
119
        result.old_revno, result.old_revid = self.target.last_revision_info()
 
120
        self.source.lock_read()
106
121
        try:
107
122
            # This just handles simple cases, but that's good enough for tests
108
 
            my_history = self.revision_history()
109
 
            their_history = source.revision_history()
 
123
            my_history = self.target.revision_history()
 
124
            their_history = self.source.revision_history()
110
125
            if their_history[:min(len(my_history), len(their_history))] != my_history:
111
 
                raise errors.DivergedBranches(self, source)
 
126
                raise errors.DivergedBranches(self.target, self.source)
112
127
            todo = their_history[len(my_history):]
113
128
            revidmap = {}
114
129
            for revid in todo:
115
 
                rev = source.repository.get_revision(revid)
116
 
                tree = source.repository.revision_tree(revid)
 
130
                rev = self.source.repository.get_revision(revid)
 
131
                tree = self.source.repository.revision_tree(revid)
117
132
                def get_file_with_stat(file_id, path=None):
118
133
                    return (tree.get_file(file_id), None)
119
134
                tree.get_file_with_stat = get_file_with_stat
120
 
                new_revid = self.mapping.revision_id_foreign_to_bzr(
121
 
                    (str(rev.timestamp), str(rev.timezone), str(self.revno())))
122
 
                parent_revno, parent_revid= self.last_revision_info()
123
 
                builder = self.get_commit_builder([parent_revid], 
124
 
                        self.get_config(), rev.timestamp,
 
135
                new_revid = self.target.mapping.revision_id_foreign_to_bzr(
 
136
                    (str(rev.timestamp), str(rev.timezone), 
 
137
                        str(self.target.revno())))
 
138
                parent_revno, parent_revid= self.target.last_revision_info()
 
139
                if parent_revid == NULL_REVISION:
 
140
                    parent_revids = []
 
141
                else:
 
142
                    parent_revids = [parent_revid]
 
143
                builder = self.target.get_commit_builder(parent_revids, 
 
144
                        self.target.get_config(), rev.timestamp,
125
145
                        rev.timezone, rev.committer, rev.properties,
126
146
                        new_revid)
127
147
                try:
129
149
                        new_ie = ie.copy()
130
150
                        new_ie.revision = None
131
151
                        builder.record_entry_contents(new_ie, 
132
 
                            [self.repository.get_inventory(parent_revid)],
 
152
                            [self.target.repository.revision_tree(parent_revid).inventory],
133
153
                            path, tree, 
134
154
                            (ie.kind, ie.text_size, ie.executable, ie.text_sha1))
135
155
                    builder.finish_inventory()
137
157
                    builder.abort()
138
158
                    raise
139
159
                revidmap[revid] = builder.commit(rev.message)
140
 
                self.set_last_revision_info(parent_revno+1, revidmap[revid])
 
160
                self.target.set_last_revision_info(parent_revno+1, 
 
161
                    revidmap[revid])
141
162
                trace.mutter('lossily pushed revision %s -> %s', 
142
163
                    revid, revidmap[revid])
143
164
        finally:
144
 
            source.unlock()
145
 
        return revidmap
 
165
            self.source.unlock()
 
166
        result.new_revno, result.new_revid = self.target.last_revision_info()
 
167
        result.revidmap = revidmap
 
168
        return result
146
169
 
147
170
 
148
171
class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6):
278
301
        self.assertEquals(mapp, rev.mapping)
279
302
 
280
303
 
281
 
class ShowForeignPropertiesTests(TestCase):
282
 
    """Tests for the show_foreign_properties() function."""
283
 
 
284
 
    def setUp(self):
285
 
        super(ShowForeignPropertiesTests, self).setUp()
286
 
        self.vcs = DummyForeignVcs()
287
 
        foreign.foreign_vcs_registry.register("dummy",
288
 
            self.vcs, "Dummy VCS")
289
 
 
290
 
    def tearDown(self):
291
 
        super(ShowForeignPropertiesTests, self).tearDown()
292
 
        foreign.foreign_vcs_registry.remove("dummy")
293
 
 
294
 
    def test_show_non_foreign(self):
295
 
        """Test use with a native (non-foreign) bzr revision."""
296
 
        self.assertEquals({}, foreign.show_foreign_properties(Revision("arevid")))
297
 
 
298
 
    def test_show_imported(self):
299
 
        rev = Revision("dummy-v1:my-foreign-revid")
300
 
        self.assertEquals({ "dummy ding": "my/foreign\\revid" },
301
 
                          foreign.show_foreign_properties(rev))
302
 
 
303
 
    def test_show_direct(self):
304
 
        rev = foreign.ForeignRevision(("some", "foreign", "revid"),
305
 
                                      DummyForeignVcsMapping(self.vcs),
306
 
                                      "roundtrip-revid")
307
 
        self.assertEquals({ "dummy ding": "some/foreign\\revid" },
308
 
                          foreign.show_foreign_properties(rev))
309
 
 
310
 
 
311
304
class WorkingTreeFileUpdateTests(TestCaseWithTransport):
312
305
    """Tests for update_workingtree_fileids()."""
313
306
 
316
309
        self.build_tree_contents([('br1/bla', 'original contents\n')])
317
310
        wt.add('bla', 'bla-a')
318
311
        wt.commit('bla-a')
 
312
        root_id = wt.get_root_id()
319
313
        target = wt.bzrdir.sprout('br2').open_workingtree()
320
314
        target.unversion(['bla-a'])
321
315
        target.add('bla', 'bla-b')
326
320
        foreign.update_workingtree_fileids(wt, target_basis)
327
321
        wt.lock_read()
328
322
        try:
329
 
            self.assertEquals(["TREE_ROOT", "bla-b"], list(wt.inventory))
 
323
            self.assertEquals(set([root_id, "bla-b"]), set(wt.inventory))
330
324
        finally:
331
325
            wt.unlock()
332
326
 
336
330
 
337
331
    def setUp(self):
338
332
        BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
 
333
        branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
339
334
        self.addCleanup(self.unregister)
340
335
        super(DummyForeignVcsTests, self).setUp()
341
336
 
344
339
            BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
345
340
        except ValueError:
346
341
            pass
 
342
        branch.InterBranch.unregister_optimiser(InterToDummyVcsBranch)
347
343
 
348
344
    def test_create(self):
349
345
        """Test we can create dummies."""
360
356
        dir = BzrDir.open("d")
361
357
        newdir = dir.sprout("e")
362
358
        self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string())
 
359
 
 
360
    def test_lossy_push_empty(self):
 
361
        source_tree = self.make_branch_and_tree("source")
 
362
        target_tree = self.make_branch_and_tree("target", 
 
363
            format=DummyForeignVcsDirFormat())
 
364
        pushresult = source_tree.branch.lossy_push(target_tree.branch)
 
365
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
 
366
        self.assertEquals(NULL_REVISION, pushresult.new_revid)
 
367
        self.assertEquals({}, pushresult.revidmap)
 
368
 
 
369
    def test_lossy_push_simple(self):
 
370
        source_tree = self.make_branch_and_tree("source")
 
371
        self.build_tree(['source/a', 'source/b'])
 
372
        source_tree.add(['a', 'b'])
 
373
        revid1 = source_tree.commit("msg")
 
374
        target_tree = self.make_branch_and_tree("target", 
 
375
            format=DummyForeignVcsDirFormat())
 
376
        target_tree.branch.lock_write()
 
377
        try:
 
378
            pushresult = source_tree.branch.lossy_push(target_tree.branch)
 
379
        finally:
 
380
            target_tree.branch.unlock()
 
381
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
 
382
        self.assertEquals({revid1:target_tree.branch.last_revision()}, 
 
383
                           pushresult.revidmap)
 
384
        self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)