79
74
self.mapping_registry = DummyForeignVcsMappingRegistry()
80
75
self.mapping_registry.register("v1", DummyForeignVcsMapping(self),
82
self.abbreviation = "dummy"
84
78
def show_foreign_revid(self, foreign_revid):
85
79
return { "dummy ding": "%s/%s\\%s" % foreign_revid }
87
def serialize_foreign_revid(self, foreign_revid):
88
return "%s|%s|%s" % foreign_revid
91
82
class DummyForeignVcsBranch(branch.BzrBranch6,foreign.ForeignBranch):
92
83
"""A Dummy VCS Branch."""
95
86
self._format = _format
96
87
self._base = a_bzrdir.transport.base
97
88
self._ignore_fallbacks = False
98
self.bzrdir = a_bzrdir
99
foreign.ForeignBranch.__init__(self,
89
foreign.ForeignBranch.__init__(self,
100
90
DummyForeignVcsMapping(DummyForeignVcs()))
101
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
91
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)
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):
95
class InterToDummyVcsBranch(branch.GenericInterBranch,
96
foreign.InterToForeignBranch):
154
99
def is_compatible(source, target):
155
100
return isinstance(target, DummyForeignVcsBranch)
157
def push(self, overwrite=False, stop_revision=None, lossy=False):
159
raise errors.NoRoundtrippingSupport(self.source, self.target)
102
def lossy_push(self, stop_revision=None):
160
103
result = branch.BranchPushResult()
161
104
result.source_branch = self.source
162
105
result.target_branch = self.target
163
106
result.old_revno, result.old_revid = self.target.last_revision_info()
164
107
self.source.lock_read()
166
graph = self.source.repository.get_graph()
167
109
# This just handles simple cases, but that's good enough for tests
168
110
my_history = self.target.revision_history()
169
if stop_revision is None:
170
stop_revision = self.source.last_revision()
171
their_history = list(graph.iter_lefthand_ancestry(stop_revision,
172
(revision.NULL_REVISION,)))
173
their_history.reverse()
111
their_history = self.source.revision_history()
174
112
if their_history[:min(len(my_history), len(their_history))] != my_history:
175
113
raise errors.DivergedBranches(self.target, self.source)
176
114
todo = their_history[len(my_history):]
226
164
super(DummyForeignVcsBranchFormat, self).__init__()
227
165
self._matchingbzrdir = DummyForeignVcsDirFormat()
229
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
230
found_repository=None):
167
def open(self, a_bzrdir, _found=False):
232
169
raise NotImplementedError
234
transport = a_bzrdir.get_branch_transport(None, name=name)
171
transport = a_bzrdir.get_branch_transport(None)
235
172
control_files = lockable_files.LockableFiles(transport, 'lock',
237
if found_repository is None:
238
found_repository = a_bzrdir.find_repository()
239
174
return DummyForeignVcsBranch(_format=self,
240
175
_control_files=control_files,
241
176
a_bzrdir=a_bzrdir,
242
_repository=found_repository)
177
_repository=a_bzrdir.find_repository())
243
178
except errors.NoSuchFile:
244
179
raise errors.NotBranchError(path=transport.base)
298
236
self._control_files = lockable_files.LockableFiles(self.transport,
299
237
"lock", lockable_files.TransportLock)
301
def create_workingtree(self):
302
# dirstate requires a ".bzr" entry to exist
303
self.root_transport.put_bytes(".bzr", "foo")
304
return super(DummyForeignVcsDir, self).create_workingtree()
306
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
308
raise errors.NoColocatedBranchSupport(self)
239
def open_branch(self, ignore_fallbacks=True):
309
240
return self._format.get_branch_format().open(self, _found=True)
311
242
def cloning_metadir(self, stacked=False):
312
243
"""Produce a metadir suitable for cloning with."""
313
244
return bzrdir.format_registry.make_bzrdir("default")
315
def checkout_metadir(self):
316
return self.cloning_metadir()
318
246
def sprout(self, url, revision_id=None, force_new_repo=False,
319
247
recurse='down', possible_transports=None,
320
248
accelerator_tree=None, hardlink=False, stacked=False,
330
258
def register_dummy_foreign_for_test(testcase):
331
controldir.ControlDirFormat.register_prober(DummyForeignProber)
332
testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
334
repository.format_registry.register(DummyForeignVcsRepositoryFormat())
335
testcase.addCleanup(repository.format_registry.remove,
336
DummyForeignVcsRepositoryFormat())
337
branch.format_registry.register(DummyForeignVcsBranchFormat())
338
testcase.addCleanup(branch.format_registry.remove,
339
DummyForeignVcsBranchFormat())
259
bzrdir.BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
260
testcase.addCleanup(bzrdir.BzrDirFormat.unregister_control_format,
261
DummyForeignVcsDirFormat)
340
262
# We need to register the optimiser to make the dummy appears really
341
263
# different from a regular bzr repository.
342
264
branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
375
283
reg = foreign.ForeignVcsRegistry()
376
284
vcs = DummyForeignVcs()
377
285
reg.register("dummy", vcs, "Dummy VCS")
379
("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
380
reg.parse_revision_id("dummy-v1:some-foreign-revid"))
286
self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
287
reg.parse_revision_id("dummy-v1:some-foreign-revid"))
383
290
class ForeignRevisionTests(tests.TestCase):
440
347
self.assertNotEquals("A Dummy VCS Dir",
441
348
newdir._format.get_format_string())
443
def test_push_not_supported(self):
444
source_tree = self.make_branch_and_tree("source")
445
target_tree = self.make_branch_and_tree("target",
446
format=DummyForeignVcsDirFormat())
447
self.assertRaises(errors.NoRoundtrippingSupport,
448
source_tree.branch.push, target_tree.branch)
450
350
def test_lossy_push_empty(self):
451
351
source_tree = self.make_branch_and_tree("source")
452
352
target_tree = self.make_branch_and_tree("target",
453
353
format=DummyForeignVcsDirFormat())
454
pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
354
pushresult = source_tree.branch.lossy_push(target_tree.branch)
455
355
self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
456
356
self.assertEquals(revision.NULL_REVISION, pushresult.new_revid)
457
357
self.assertEquals({}, pushresult.revidmap)