~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-01 21:02:50 UTC
  • mto: This revision was merged to the branch mainline in revision 5842.
  • Revision ID: jelmer@samba.org-20110501210250-24jq6hrxxc9psvzf
Actually use branch format 5 in branch format 5 test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008-2011 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
21
21
from bzrlib import (
22
22
    branch,
23
23
    bzrdir,
 
24
    controldir,
24
25
    errors,
25
26
    foreign,
26
27
    lockable_files,
27
28
    lockdir,
 
29
    repository,
28
30
    revision,
29
31
    tests,
30
32
    trace,
31
33
    )
32
34
 
 
35
from bzrlib.repofmt import groupcompress_repo
 
36
 
33
37
# This is the dummy foreign revision control system, used 
34
38
# mainly here in the testsuite to test the foreign VCS infrastructure.
35
39
# It is basically standard Bazaar with some minor modifications to 
91
95
        self._base = a_bzrdir.transport.base
92
96
        self._ignore_fallbacks = False
93
97
        self.bzrdir = a_bzrdir
94
 
        foreign.ForeignBranch.__init__(self, 
 
98
        foreign.ForeignBranch.__init__(self,
95
99
            DummyForeignVcsMapping(DummyForeignVcs()))
96
 
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, 
 
100
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
97
101
            *args, **kwargs)
98
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
 
99
151
 
100
152
class InterToDummyVcsBranch(branch.GenericInterBranch,
101
153
                            foreign.InterToForeignBranch):
116
168
        try:
117
169
            # This just handles simple cases, but that's good enough for tests
118
170
            my_history = self.target.revision_history()
119
 
            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()
120
175
            if their_history[:min(len(my_history), len(their_history))] != my_history:
121
176
                raise errors.DivergedBranches(self.target, self.source)
122
177
            todo = their_history[len(my_history):]
172
227
        super(DummyForeignVcsBranchFormat, self).__init__()
173
228
        self._matchingbzrdir = DummyForeignVcsDirFormat()
174
229
 
175
 
    def open(self, a_bzrdir, name=None, _found=False):
 
230
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
 
231
            found_repository=None):
176
232
        if not _found:
177
233
            raise NotImplementedError
178
234
        try:
179
235
            transport = a_bzrdir.get_branch_transport(None, name=name)
180
236
            control_files = lockable_files.LockableFiles(transport, 'lock',
181
237
                                                         lockdir.LockDir)
 
238
            if found_repository is None:
 
239
                found_repository = a_bzrdir.find_repository()
182
240
            return DummyForeignVcsBranch(_format=self,
183
241
                              _control_files=control_files,
184
242
                              a_bzrdir=a_bzrdir,
185
 
                              _repository=a_bzrdir.find_repository())
 
243
                              _repository=found_repository)
186
244
        except errors.NoSuchFile:
187
245
            raise errors.NotBranchError(path=transport.base)
188
246
 
205
263
    def get_branch_format(self):
206
264
        return DummyForeignVcsBranchFormat()
207
265
 
208
 
    @classmethod
209
 
    def probe_transport(klass, transport):
210
 
        """Return the .bzrdir style format present in a directory."""
211
 
        if not transport.has('.dummy'):
212
 
            raise errors.NotBranchError(path=transport.base)
213
 
        return klass()
 
266
    @property
 
267
    def repository_format(self):
 
268
        return DummyForeignVcsRepositoryFormat()
214
269
 
215
270
    def initialize_on_transport(self, transport):
216
271
        """Initialize a new bzrdir in the base directory of a Transport."""
244
299
        self._control_files = lockable_files.LockableFiles(self.transport,
245
300
            "lock", lockable_files.TransportLock)
246
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
 
247
307
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
248
308
        if name is not None:
249
309
            raise errors.NoColocatedBranchSupport(self)
253
313
        """Produce a metadir suitable for cloning with."""
254
314
        return bzrdir.format_registry.make_bzrdir("default")
255
315
 
 
316
    def checkout_metadir(self):
 
317
        return self.cloning_metadir()
 
318
 
256
319
    def sprout(self, url, revision_id=None, force_new_repo=False,
257
320
               recurse='down', possible_transports=None,
258
321
               accelerator_tree=None, hardlink=False, stacked=False,
266
329
 
267
330
 
268
331
def register_dummy_foreign_for_test(testcase):
269
 
    bzrdir.BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
270
 
    testcase.addCleanup(bzrdir.BzrDirFormat.unregister_control_format,
271
 
                        DummyForeignVcsDirFormat)
 
332
    controldir.ControlDirFormat.register_prober(DummyForeignProber)
 
333
    testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
 
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())
272
341
    # We need to register the optimiser to make the dummy appears really
273
342
    # different from a regular bzr repository.
274
343
    branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
276
345
                        InterToDummyVcsBranch)
277
346
 
278
347
 
 
348
class DummyForeignProber(controldir.Prober):
 
349
 
 
350
    @classmethod
 
351
    def probe_transport(klass, transport):
 
352
        """Return the .bzrdir style format present in a directory."""
 
353
        if not transport.has('.dummy'):
 
354
            raise errors.NotBranchError(path=transport.base)
 
355
        return DummyForeignVcsDirFormat()
 
356
 
 
357
    @classmethod
 
358
    def known_formats(cls):
 
359
        return set([DummyForeignVcsDirFormat()])
 
360
 
 
361
 
279
362
class ForeignVcsRegistryTests(tests.TestCase):
280
363
    """Tests for the ForeignVcsRegistry class."""
281
364
 
293
376
        reg = foreign.ForeignVcsRegistry()
294
377
        vcs = DummyForeignVcs()
295
378
        reg.register("dummy", vcs, "Dummy VCS")
296
 
        self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
297
 
                          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"))
298
382
 
299
383
 
300
384
class ForeignRevisionTests(tests.TestCase):