92
96
self._base = a_bzrdir.transport.base
93
97
self._ignore_fallbacks = False
94
98
self.bzrdir = a_bzrdir
95
foreign.ForeignBranch.__init__(self,
99
foreign.ForeignBranch.__init__(self,
96
100
DummyForeignVcsMapping(DummyForeignVcs()))
97
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
101
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
104
def _get_checkout_format(self):
105
"""Return the most suitable metadir for a checkout of this branch.
106
Weaves are used if this branch's repository uses weaves.
108
return self.bzrdir.checkout_metadir()
110
def import_last_revision_info_and_tags(self, source, revno, revid,
112
interbranch = InterToDummyVcsBranch(source, self)
114
result = interbranch.lossy_push(revid)
115
revid = result.revidmap[revid]
117
interbranch.push(revid)
118
return (revno, revid)
121
class DummyForeignCommitBuilder(vf_repository.VersionedFileRootCommitBuilder):
123
def _generate_revision_if_needed(self):
124
mapping = DummyForeignVcsMapping(DummyForeignVcs())
126
self._new_revision_id = mapping.revision_id_foreign_to_bzr(
127
(str(self._timestamp), str(self._timezone), "UNKNOWN"))
128
self.random_revid = False
129
elif self._new_revision_id is not None:
130
self.random_revid = False
132
self._new_revision_id = self._gen_revision_id()
133
self.random_revid = True
136
class DummyForeignVcsRepository(groupcompress_repo.CHKInventoryRepository,
137
foreign.ForeignRepository):
138
"""Dummy foreign vcs repository."""
141
class DummyForeignVcsRepositoryFormat(groupcompress_repo.RepositoryFormat2a):
143
repository_class = DummyForeignVcsRepository
144
_commit_builder_class = DummyForeignCommitBuilder
146
def get_format_string(self):
147
return "Dummy Foreign Vcs Repository"
149
def get_format_description(self):
150
return "Dummy Foreign Vcs Repository"
101
153
class InterToDummyVcsBranch(branch.GenericInterBranch,
102
154
foreign.InterToForeignBranch):
118
170
# This just handles simple cases, but that's good enough for tests
119
171
my_history = self.target.revision_history()
120
their_history = self.source.revision_history()
172
if stop_revision is None:
173
stop_revision = self.source.last_revision()
174
their_history = list(self.source.repository.iter_reverse_revision_history(stop_revision))
175
their_history.reverse()
121
176
if their_history[:min(len(my_history), len(their_history))] != my_history:
122
177
raise errors.DivergedBranches(self.target, self.source)
123
178
todo = their_history[len(my_history):]
173
228
super(DummyForeignVcsBranchFormat, self).__init__()
174
229
self._matchingbzrdir = DummyForeignVcsDirFormat()
176
def open(self, a_bzrdir, name=None, _found=False, found_repository=None):
231
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
232
found_repository=None):
178
234
raise NotImplementedError
208
264
def get_branch_format(self):
209
265
return DummyForeignVcsBranchFormat()
268
def repository_format(self):
269
return DummyForeignVcsRepositoryFormat()
211
271
def initialize_on_transport(self, transport):
212
272
"""Initialize a new bzrdir in the base directory of a Transport."""
213
273
# Since we don't have a .bzr directory, inherit the
240
300
self._control_files = lockable_files.LockableFiles(self.transport,
241
301
"lock", lockable_files.TransportLock)
303
def create_workingtree(self):
304
# dirstate requires a ".bzr" entry to exist
305
self.root_transport.put_bytes(".bzr", "foo")
306
return super(DummyForeignVcsDir, self).create_workingtree()
243
308
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
244
309
if name is not None:
245
310
raise errors.NoColocatedBranchSupport(self)
249
314
"""Produce a metadir suitable for cloning with."""
250
315
return bzrdir.format_registry.make_bzrdir("default")
317
def checkout_metadir(self):
318
return self.cloning_metadir()
252
320
def sprout(self, url, revision_id=None, force_new_repo=False,
253
321
recurse='down', possible_transports=None,
254
322
accelerator_tree=None, hardlink=False, stacked=False,
265
333
controldir.ControlDirFormat.register_prober(DummyForeignProber)
266
334
testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
267
335
DummyForeignProber)
336
repository.format_registry.register(DummyForeignVcsRepositoryFormat())
337
testcase.addCleanup(repository.format_registry.remove,
338
DummyForeignVcsRepositoryFormat())
339
branch.format_registry.register(DummyForeignVcsBranchFormat())
340
testcase.addCleanup(branch.format_registry.remove,
341
DummyForeignVcsBranchFormat())
268
342
# We need to register the optimiser to make the dummy appears really
269
343
# different from a regular bzr repository.
270
344
branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
303
377
reg = foreign.ForeignVcsRegistry()
304
378
vcs = DummyForeignVcs()
305
379
reg.register("dummy", vcs, "Dummy VCS")
306
self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
307
reg.parse_revision_id("dummy-v1:some-foreign-revid"))
381
("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
382
reg.parse_revision_id("dummy-v1:some-foreign-revid"))
310
385
class ForeignRevisionTests(tests.TestCase):