35
from bzrlib.repofmt import groupcompress_repo
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,
104
class DummyForeignCommitBuilder(repository.RootCommitBuilder):
106
def _generate_revision_if_needed(self):
107
mapping = DummyForeignVcsMapping(DummyForeignVcs())
109
self._new_revision_id = mapping.revision_id_foreign_to_bzr(
110
(str(self._timestamp), str(self._timezone), "UNKNOWN"))
111
self.random_revid = False
113
self._new_revision_id = self._gen_revision_id()
114
self.random_revid = True
117
class DummyForeignVcsRepository(groupcompress_repo.CHKInventoryRepository,
118
foreign.ForeignRepository):
119
"""Dummy foreign vcs repository."""
122
class DummyForeignVcsRepositoryFormat(groupcompress_repo.RepositoryFormat2a):
124
repository_class = DummyForeignVcsRepository
125
_commit_builder_class = DummyForeignCommitBuilder
127
def get_format_string(self):
128
return "Dummy Foreign Vcs Repository"
130
def get_format_description(self):
131
return "Dummy Foreign Vcs Repository"
101
134
class InterToDummyVcsBranch(branch.GenericInterBranch,
102
135
foreign.InterToForeignBranch):
208
241
def get_branch_format(self):
209
242
return DummyForeignVcsBranchFormat()
245
def repository_format(self):
246
return DummyForeignVcsRepositoryFormat()
211
248
def initialize_on_transport(self, transport):
212
249
"""Initialize a new bzrdir in the base directory of a Transport."""
213
250
# Since we don't have a .bzr directory, inherit the
240
277
self._control_files = lockable_files.LockableFiles(self.transport,
241
278
"lock", lockable_files.TransportLock)
280
def create_workingtree(self):
281
# dirstate requires a ".bzr" entry to exist
282
self.root_transport.put_bytes(".bzr", "foo")
283
return super(DummyForeignVcsDir, self).create_workingtree()
243
285
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
244
286
if name is not None:
245
287
raise errors.NoColocatedBranchSupport(self)
265
307
controldir.ControlDirFormat.register_prober(DummyForeignProber)
266
308
testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
267
309
DummyForeignProber)
310
repository.format_registry.register(DummyForeignVcsRepositoryFormat())
311
testcase.addCleanup(repository.format_registry.remove,
312
DummyForeignVcsRepositoryFormat())
268
313
# We need to register the optimiser to make the dummy appears really
269
314
# different from a regular bzr repository.
270
315
branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
303
348
reg = foreign.ForeignVcsRegistry()
304
349
vcs = DummyForeignVcs()
305
350
reg.register("dummy", vcs, "Dummy VCS")
306
self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
307
reg.parse_revision_id("dummy-v1:some-foreign-revid"))
352
("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
353
reg.parse_revision_id("dummy-v1:some-foreign-revid"))
310
356
class ForeignRevisionTests(tests.TestCase):