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,
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.
107
return self.bzrdir.checkout_metadir()
109
def import_last_revision_info_and_tags(self, source, revno, revid,
111
interbranch = InterToDummyVcsBranch(source, self)
113
result = interbranch.lossy_push(revid)
114
revid = result.revidmap[revid]
116
interbranch.push(revid)
117
return (revno, revid)
120
class DummyForeignCommitBuilder(repository.RootCommitBuilder):
122
def _generate_revision_if_needed(self):
123
mapping = DummyForeignVcsMapping(DummyForeignVcs())
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
131
self._new_revision_id = self._gen_revision_id()
132
self.random_revid = True
135
class DummyForeignVcsRepository(groupcompress_repo.CHKInventoryRepository,
136
foreign.ForeignRepository):
137
"""Dummy foreign vcs repository."""
140
class DummyForeignVcsRepositoryFormat(groupcompress_repo.RepositoryFormat2a):
142
repository_class = DummyForeignVcsRepository
143
_commit_builder_class = DummyForeignCommitBuilder
145
def get_format_string(self):
146
return "Dummy Foreign Vcs Repository"
148
def get_format_description(self):
149
return "Dummy Foreign Vcs Repository"
152
101
class InterToDummyVcsBranch(branch.GenericInterBranch,
153
102
foreign.InterToForeignBranch):
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()
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):
233
178
raise NotImplementedError
263
208
def get_branch_format(self):
264
209
return DummyForeignVcsBranchFormat()
267
def repository_format(self):
268
return DummyForeignVcsRepositoryFormat()
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)
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()
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")
316
def checkout_metadir(self):
317
return self.cloning_metadir()
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")
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"))
384
310
class ForeignRevisionTests(tests.TestCase):