91
96
self._base = a_bzrdir.transport.base
92
97
self._ignore_fallbacks = False
93
98
self.bzrdir = a_bzrdir
94
foreign.ForeignBranch.__init__(self,
99
foreign.ForeignBranch.__init__(self,
95
100
DummyForeignVcsMapping(DummyForeignVcs()))
96
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
101
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
100
class InterToDummyVcsBranch(branch.GenericInterBranch,
101
foreign.InterToForeignBranch):
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)
113
result = interbranch.push(stop_revision=revid, lossy=True)
115
revid = result.revidmap[revid]
116
return (revno, revid)
119
class DummyForeignCommitBuilder(vf_repository.VersionedFileRootCommitBuilder):
121
def _generate_revision_if_needed(self):
122
mapping = DummyForeignVcsMapping(DummyForeignVcs())
124
self._new_revision_id = mapping.revision_id_foreign_to_bzr(
125
(str(self._timestamp), str(self._timezone), "UNKNOWN"))
126
self.random_revid = False
127
elif self._new_revision_id is not None:
128
self.random_revid = False
130
self._new_revision_id = self._gen_revision_id()
131
self.random_revid = True
134
class DummyForeignVcsRepository(groupcompress_repo.CHKInventoryRepository,
135
foreign.ForeignRepository):
136
"""Dummy foreign vcs repository."""
139
class DummyForeignVcsRepositoryFormat(groupcompress_repo.RepositoryFormat2a):
141
repository_class = DummyForeignVcsRepository
142
_commit_builder_class = DummyForeignCommitBuilder
144
def get_format_string(self):
145
return "Dummy Foreign Vcs Repository"
147
def get_format_description(self):
148
return "Dummy Foreign Vcs Repository"
151
class InterToDummyVcsBranch(branch.GenericInterBranch):
104
154
def is_compatible(source, target):
105
155
return isinstance(target, DummyForeignVcsBranch)
107
def push(self, overwrite=False, stop_revision=None):
108
raise errors.NoRoundtrippingSupport(self.source, self.target)
110
def lossy_push(self, stop_revision=None):
157
def push(self, overwrite=False, stop_revision=None, lossy=False):
159
raise errors.NoRoundtrippingSupport(self.source, self.target)
111
160
result = branch.BranchPushResult()
112
161
result.source_branch = self.source
113
162
result.target_branch = self.target
117
166
# This just handles simple cases, but that's good enough for tests
118
167
my_history = self.target.revision_history()
119
their_history = self.source.revision_history()
168
if stop_revision is None:
169
stop_revision = self.source.last_revision()
170
their_history = list(
171
self.source.repository.iter_reverse_revision_history(stop_revision))
172
their_history.reverse()
120
173
if their_history[:min(len(my_history), len(their_history))] != my_history:
121
174
raise errors.DivergedBranches(self.target, self.source)
122
175
todo = their_history[len(my_history):]
172
225
super(DummyForeignVcsBranchFormat, self).__init__()
173
226
self._matchingbzrdir = DummyForeignVcsDirFormat()
175
def open(self, a_bzrdir, name=None, _found=False):
228
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
229
found_repository=None):
177
231
raise NotImplementedError
179
233
transport = a_bzrdir.get_branch_transport(None, name=name)
180
234
control_files = lockable_files.LockableFiles(transport, 'lock',
236
if found_repository is None:
237
found_repository = a_bzrdir.find_repository()
182
238
return DummyForeignVcsBranch(_format=self,
183
239
_control_files=control_files,
184
240
a_bzrdir=a_bzrdir,
185
_repository=a_bzrdir.find_repository())
241
_repository=found_repository)
186
242
except errors.NoSuchFile:
187
243
raise errors.NotBranchError(path=transport.base)
205
261
def get_branch_format(self):
206
262
return DummyForeignVcsBranchFormat()
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)
265
def repository_format(self):
266
return DummyForeignVcsRepositoryFormat()
215
268
def initialize_on_transport(self, transport):
216
269
"""Initialize a new bzrdir in the base directory of a Transport."""
244
297
self._control_files = lockable_files.LockableFiles(self.transport,
245
298
"lock", lockable_files.TransportLock)
300
def create_workingtree(self):
301
# dirstate requires a ".bzr" entry to exist
302
self.root_transport.put_bytes(".bzr", "foo")
303
return super(DummyForeignVcsDir, self).create_workingtree()
247
305
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
248
306
if name is not None:
249
307
raise errors.NoColocatedBranchSupport(self)
253
311
"""Produce a metadir suitable for cloning with."""
254
312
return bzrdir.format_registry.make_bzrdir("default")
314
def checkout_metadir(self):
315
return self.cloning_metadir()
256
317
def sprout(self, url, revision_id=None, force_new_repo=False,
257
318
recurse='down', possible_transports=None,
258
319
accelerator_tree=None, hardlink=False, stacked=False,
268
329
def register_dummy_foreign_for_test(testcase):
269
bzrdir.BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
270
testcase.addCleanup(bzrdir.BzrDirFormat.unregister_control_format,
271
DummyForeignVcsDirFormat)
330
controldir.ControlDirFormat.register_prober(DummyForeignProber)
331
testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
333
repository.format_registry.register(DummyForeignVcsRepositoryFormat())
334
testcase.addCleanup(repository.format_registry.remove,
335
DummyForeignVcsRepositoryFormat())
336
branch.format_registry.register(DummyForeignVcsBranchFormat())
337
testcase.addCleanup(branch.format_registry.remove,
338
DummyForeignVcsBranchFormat())
272
339
# We need to register the optimiser to make the dummy appears really
273
340
# different from a regular bzr repository.
274
341
branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
276
343
InterToDummyVcsBranch)
346
class DummyForeignProber(controldir.Prober):
349
def probe_transport(klass, transport):
350
"""Return the .bzrdir style format present in a directory."""
351
if not transport.has('.dummy'):
352
raise errors.NotBranchError(path=transport.base)
353
return DummyForeignVcsDirFormat()
356
def known_formats(cls):
357
return set([DummyForeignVcsDirFormat()])
279
360
class ForeignVcsRegistryTests(tests.TestCase):
280
361
"""Tests for the ForeignVcsRegistry class."""
293
374
reg = foreign.ForeignVcsRegistry()
294
375
vcs = DummyForeignVcs()
295
376
reg.register("dummy", vcs, "Dummy VCS")
296
self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
297
reg.parse_revision_id("dummy-v1:some-foreign-revid"))
378
("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
379
reg.parse_revision_id("dummy-v1:some-foreign-revid"))
300
382
class ForeignRevisionTests(tests.TestCase):
368
450
source_tree = self.make_branch_and_tree("source")
369
451
target_tree = self.make_branch_and_tree("target",
370
452
format=DummyForeignVcsDirFormat())
371
pushresult = source_tree.branch.lossy_push(target_tree.branch)
453
pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
372
454
self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
373
455
self.assertEquals(revision.NULL_REVISION, pushresult.new_revid)
374
456
self.assertEquals({}, pushresult.revidmap)