~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-16 01:09:56 UTC
  • mfrom: (5784.1.4 760435-less-fail)
  • Revision ID: pqm@pqm.ubuntu.com-20110416010956-5wrpm136qq2hz5f3
(mbp) rename and deprecate failUnlessExists and failIfExists (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    foreign,
27
27
    lockable_files,
28
28
    lockdir,
29
 
    repository,
30
29
    revision,
31
30
    tests,
32
31
    trace,
33
32
    )
34
33
 
35
 
from bzrlib.repofmt import groupcompress_repo
36
 
 
37
34
# This is the dummy foreign revision control system, used 
38
35
# mainly here in the testsuite to test the foreign VCS infrastructure.
39
36
# It is basically standard Bazaar with some minor modifications to 
95
92
        self._base = a_bzrdir.transport.base
96
93
        self._ignore_fallbacks = False
97
94
        self.bzrdir = a_bzrdir
98
 
        foreign.ForeignBranch.__init__(self,
 
95
        foreign.ForeignBranch.__init__(self, 
99
96
            DummyForeignVcsMapping(DummyForeignVcs()))
100
 
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
 
97
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, 
101
98
            *args, **kwargs)
102
99
 
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
 
 
151
100
 
152
101
class InterToDummyVcsBranch(branch.GenericInterBranch,
153
102
                            foreign.InterToForeignBranch):
168
117
        try:
169
118
            # This just handles simple cases, but that's good enough for tests
170
119
            my_history = self.target.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
            their_history = self.source.revision_history()
175
121
            if their_history[:min(len(my_history), len(their_history))] != my_history:
176
122
                raise errors.DivergedBranches(self.target, self.source)
177
123
            todo = their_history[len(my_history):]
227
173
        super(DummyForeignVcsBranchFormat, self).__init__()
228
174
        self._matchingbzrdir = DummyForeignVcsDirFormat()
229
175
 
230
 
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
231
 
            found_repository=None):
 
176
    def open(self, a_bzrdir, name=None, _found=False, found_repository=None):
232
177
        if not _found:
233
178
            raise NotImplementedError
234
179
        try:
263
208
    def get_branch_format(self):
264
209
        return DummyForeignVcsBranchFormat()
265
210
 
266
 
    @property
267
 
    def repository_format(self):
268
 
        return DummyForeignVcsRepositoryFormat()
269
 
 
270
211
    def initialize_on_transport(self, transport):
271
212
        """Initialize a new bzrdir in the base directory of a Transport."""
272
213
        # Since we don't have a .bzr directory, inherit the
299
240
        self._control_files = lockable_files.LockableFiles(self.transport,
300
241
            "lock", lockable_files.TransportLock)
301
242
 
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
 
 
307
243
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
308
244
        if name is not None:
309
245
            raise errors.NoColocatedBranchSupport(self)
313
249
        """Produce a metadir suitable for cloning with."""
314
250
        return bzrdir.format_registry.make_bzrdir("default")
315
251
 
316
 
    def checkout_metadir(self):
317
 
        return self.cloning_metadir()
318
 
 
319
252
    def sprout(self, url, revision_id=None, force_new_repo=False,
320
253
               recurse='down', possible_transports=None,
321
254
               accelerator_tree=None, hardlink=False, stacked=False,
332
265
    controldir.ControlDirFormat.register_prober(DummyForeignProber)
333
266
    testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
334
267
        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())
341
268
    # We need to register the optimiser to make the dummy appears really
342
269
    # different from a regular bzr repository.
343
270
    branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
376
303
        reg = foreign.ForeignVcsRegistry()
377
304
        vcs = DummyForeignVcs()
378
305
        reg.register("dummy", vcs, "Dummy VCS")
379
 
        self.assertEquals((
380
 
            ("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
381
 
            reg.parse_revision_id("dummy-v1:some-foreign-revid"))
 
306
        self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
 
307
                          reg.parse_revision_id("dummy-v1:some-foreign-revid"))
382
308
 
383
309
 
384
310
class ForeignRevisionTests(tests.TestCase):