~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    foreign,
27
27
    lockable_files,
28
28
    lockdir,
 
29
    repository,
29
30
    revision,
30
31
    tests,
31
32
    trace,
32
33
    )
33
34
 
 
35
from bzrlib.repofmt import groupcompress_repo
 
36
 
34
37
# This is the dummy foreign revision control system, used 
35
38
# mainly here in the testsuite to test the foreign VCS infrastructure.
36
39
# It is basically standard Bazaar with some minor modifications to 
92
95
        self._base = a_bzrdir.transport.base
93
96
        self._ignore_fallbacks = False
94
97
        self.bzrdir = a_bzrdir
95
 
        foreign.ForeignBranch.__init__(self, 
 
98
        foreign.ForeignBranch.__init__(self,
96
99
            DummyForeignVcsMapping(DummyForeignVcs()))
97
 
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, 
 
100
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
98
101
            *args, **kwargs)
99
102
 
 
103
    def _get_checkout_format(self):
 
104
        """Return the most suitable metadir for a checkout of this branch.
 
105
        Weaves are used if this branch's repository uses weaves.
 
106
        """
 
107
        return self.bzrdir.checkout_metadir()
 
108
 
 
109
    def import_last_revision_info_and_tags(self, source, revno, revid,
 
110
                                           lossy=False):
 
111
        interbranch = InterToDummyVcsBranch(source, self)
 
112
        if lossy:
 
113
            result = interbranch.lossy_push(revid)
 
114
            revid = result.revidmap[revid]
 
115
        else:
 
116
            interbranch.push(revid)
 
117
        return (revno, revid)
 
118
 
 
119
 
 
120
class DummyForeignCommitBuilder(repository.RootCommitBuilder):
 
121
 
 
122
    def _generate_revision_if_needed(self):
 
123
        mapping = DummyForeignVcsMapping(DummyForeignVcs())
 
124
        if self._lossy:
 
125
            self._new_revision_id = mapping.revision_id_foreign_to_bzr(
 
126
                (str(self._timestamp), str(self._timezone), "UNKNOWN"))
 
127
            self.random_revid = False
 
128
        elif self._new_revision_id is not None:
 
129
            self.random_revid = False
 
130
        else:
 
131
            self._new_revision_id = self._gen_revision_id()
 
132
            self.random_revid = True
 
133
 
 
134
 
 
135
class DummyForeignVcsRepository(groupcompress_repo.CHKInventoryRepository,
 
136
    foreign.ForeignRepository):
 
137
    """Dummy foreign vcs repository."""
 
138
 
 
139
 
 
140
class DummyForeignVcsRepositoryFormat(groupcompress_repo.RepositoryFormat2a):
 
141
 
 
142
    repository_class = DummyForeignVcsRepository
 
143
    _commit_builder_class = DummyForeignCommitBuilder
 
144
 
 
145
    def get_format_string(self):
 
146
        return "Dummy Foreign Vcs Repository"
 
147
 
 
148
    def get_format_description(self):
 
149
        return "Dummy Foreign Vcs Repository"
 
150
 
100
151
 
101
152
class InterToDummyVcsBranch(branch.GenericInterBranch,
102
153
                            foreign.InterToForeignBranch):
117
168
        try:
118
169
            # This just handles simple cases, but that's good enough for tests
119
170
            my_history = self.target.revision_history()
120
 
            their_history = self.source.revision_history()
 
171
            if stop_revision is None:
 
172
                stop_revision = self.source.last_revision()
 
173
            their_history = list(self.source.repository.iter_reverse_revision_history(stop_revision))
 
174
            their_history.reverse()
121
175
            if their_history[:min(len(my_history), len(their_history))] != my_history:
122
176
                raise errors.DivergedBranches(self.target, self.source)
123
177
            todo = their_history[len(my_history):]
173
227
        super(DummyForeignVcsBranchFormat, self).__init__()
174
228
        self._matchingbzrdir = DummyForeignVcsDirFormat()
175
229
 
176
 
    def open(self, a_bzrdir, name=None, _found=False, found_repository=None):
 
230
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
 
231
            found_repository=None):
177
232
        if not _found:
178
233
            raise NotImplementedError
179
234
        try:
208
263
    def get_branch_format(self):
209
264
        return DummyForeignVcsBranchFormat()
210
265
 
 
266
    @property
 
267
    def repository_format(self):
 
268
        return DummyForeignVcsRepositoryFormat()
 
269
 
211
270
    def initialize_on_transport(self, transport):
212
271
        """Initialize a new bzrdir in the base directory of a Transport."""
213
272
        # Since we don't have a .bzr directory, inherit the
240
299
        self._control_files = lockable_files.LockableFiles(self.transport,
241
300
            "lock", lockable_files.TransportLock)
242
301
 
 
302
    def create_workingtree(self):
 
303
        # dirstate requires a ".bzr" entry to exist
 
304
        self.root_transport.put_bytes(".bzr", "foo")
 
305
        return super(DummyForeignVcsDir, self).create_workingtree()
 
306
 
243
307
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
244
308
        if name is not None:
245
309
            raise errors.NoColocatedBranchSupport(self)
249
313
        """Produce a metadir suitable for cloning with."""
250
314
        return bzrdir.format_registry.make_bzrdir("default")
251
315
 
 
316
    def checkout_metadir(self):
 
317
        return self.cloning_metadir()
 
318
 
252
319
    def sprout(self, url, revision_id=None, force_new_repo=False,
253
320
               recurse='down', possible_transports=None,
254
321
               accelerator_tree=None, hardlink=False, stacked=False,
265
332
    controldir.ControlDirFormat.register_prober(DummyForeignProber)
266
333
    testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
267
334
        DummyForeignProber)
 
335
    repository.format_registry.register(DummyForeignVcsRepositoryFormat())
 
336
    testcase.addCleanup(repository.format_registry.remove,
 
337
            DummyForeignVcsRepositoryFormat())
 
338
    branch.format_registry.register(DummyForeignVcsBranchFormat())
 
339
    testcase.addCleanup(branch.format_registry.remove,
 
340
            DummyForeignVcsBranchFormat())
268
341
    # We need to register the optimiser to make the dummy appears really
269
342
    # different from a regular bzr repository.
270
343
    branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
303
376
        reg = foreign.ForeignVcsRegistry()
304
377
        vcs = DummyForeignVcs()
305
378
        reg.register("dummy", vcs, "Dummy VCS")
306
 
        self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
307
 
                          reg.parse_revision_id("dummy-v1:some-foreign-revid"))
 
379
        self.assertEquals((
 
380
            ("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
 
381
            reg.parse_revision_id("dummy-v1:some-foreign-revid"))
308
382
 
309
383
 
310
384
class ForeignRevisionTests(tests.TestCase):