141
145
repository_class = DummyForeignVcsRepository
142
146
_commit_builder_class = DummyForeignCommitBuilder
144
def get_format_string(self):
149
def get_format_string(cls):
145
150
return "Dummy Foreign Vcs Repository"
147
152
def get_format_description(self):
148
153
return "Dummy Foreign Vcs Repository"
156
def branch_history(graph, revid):
157
ret = list(graph.iter_lefthand_ancestry(revid,
158
(revision.NULL_REVISION,)))
151
163
class InterToDummyVcsBranch(branch.GenericInterBranch):
166
178
graph = self.source.repository.get_graph()
167
179
# This just handles simple cases, but that's good enough for tests
168
my_history = self.target.revision_history()
180
my_history = branch_history(self.target.repository.get_graph(),
169
182
if stop_revision is None:
170
183
stop_revision = self.source.last_revision()
171
their_history = list(graph.iter_lefthand_ancestry(stop_revision,
172
(revision.NULL_REVISION,)))
173
their_history.reverse()
184
their_history = branch_history(graph, stop_revision)
174
185
if their_history[:min(len(my_history), len(their_history))] != my_history:
175
186
raise errors.DivergedBranches(self.target, self.source)
176
187
todo = their_history[len(my_history):]
191
202
parent_revids = [parent_revid]
192
203
builder = self.target.get_commit_builder(parent_revids,
193
self.target.get_config(), rev.timestamp,
204
self.target.get_config_stack(), rev.timestamp,
194
205
rev.timezone, rev.committer, rev.properties,
197
for path, ie in tree.inventory.iter_entries():
208
parent_tree = self.target.repository.revision_tree(
210
for path, ie in tree.iter_entries_by_dir():
198
211
new_ie = ie.copy()
199
212
new_ie.revision = None
200
213
builder.record_entry_contents(new_ie,
201
[self.target.repository.revision_tree(parent_revid).inventory],
214
[parent_tree.root_inventory],
203
216
(ie.kind, ie.text_size, ie.executable, ie.text_sha1))
204
217
builder.finish_inventory()
220
233
class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6):
222
def get_format_string(self):
236
def get_format_string(cls):
223
237
return "Branch for Testing"
226
super(DummyForeignVcsBranchFormat, self).__init__()
227
self._matchingbzrdir = DummyForeignVcsDirFormat()
240
def _matchingbzrdir(self):
241
return DummyForeignVcsDirFormat()
229
243
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
230
244
found_repository=None):
246
name = a_bzrdir._get_selected_branch()
232
248
raise NotImplementedError
303
320
self.root_transport.put_bytes(".bzr", "foo")
304
321
return super(DummyForeignVcsDir, self).create_workingtree()
306
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
323
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True,
324
possible_transports=None):
326
name = self._get_selected_branch()
308
328
raise errors.NoColocatedBranchSupport(self)
309
329
return self._format.get_branch_format().open(self, _found=True)
311
331
def cloning_metadir(self, stacked=False):
312
332
"""Produce a metadir suitable for cloning with."""
313
return bzrdir.format_registry.make_bzrdir("default")
333
return controldir.format_registry.make_bzrdir("default")
315
335
def checkout_metadir(self):
316
336
return self.cloning_metadir()
319
339
recurse='down', possible_transports=None,
320
340
accelerator_tree=None, hardlink=False, stacked=False,
321
341
source_branch=None):
322
# dirstate doesn't cope with accelerator_trees well
342
# dirstate doesn't cope with accelerator_trees well
323
343
# that have a different control dir
324
return super(DummyForeignVcsDir, self).sprout(url=url,
325
revision_id=revision_id, force_new_repo=force_new_repo,
326
recurse=recurse, possible_transports=possible_transports,
327
hardlink=hardlink, stacked=stacked, source_branch=source_branch)
344
return super(DummyForeignVcsDir, self).sprout(
346
revision_id=revision_id, force_new_repo=force_new_repo,
347
recurse=recurse, possible_transports=possible_transports,
348
hardlink=hardlink, stacked=stacked, source_branch=source_branch)
330
351
def register_dummy_foreign_for_test(testcase):
331
352
controldir.ControlDirFormat.register_prober(DummyForeignProber)
332
353
testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
334
355
repository.format_registry.register(DummyForeignVcsRepositoryFormat())
335
356
testcase.addCleanup(repository.format_registry.remove,
336
DummyForeignVcsRepositoryFormat())
357
DummyForeignVcsRepositoryFormat())
337
358
branch.format_registry.register(DummyForeignVcsBranchFormat())
338
359
testcase.addCleanup(branch.format_registry.remove,
339
DummyForeignVcsBranchFormat())
360
DummyForeignVcsBranchFormat())
340
361
# We need to register the optimiser to make the dummy appears really
341
362
# different from a regular bzr repository.
342
363
branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
387
408
mapp = DummyForeignVcsMapping(DummyForeignVcs())
388
409
rev = foreign.ForeignRevision(("a", "foreign", "revid"),
389
410
mapp, "roundtripped-revid")
390
self.assertEquals("", rev.inventory_sha1)
391
self.assertEquals(("a", "foreign", "revid"), rev.foreign_revid)
392
self.assertEquals(mapp, rev.mapping)
411
self.assertEqual("", rev.inventory_sha1)
412
self.assertEqual(("a", "foreign", "revid"), rev.foreign_revid)
413
self.assertEqual(mapp, rev.mapping)
395
416
class WorkingTreeFileUpdateTests(tests.TestCaseWithTransport):
435
456
def test_sprout(self):
436
457
"""Test we can clone dummies and that the format is not preserved."""
437
458
self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
438
dir = bzrdir.BzrDir.open("d")
459
dir = controldir.ControlDir.open("d")
439
460
newdir = dir.sprout("e")
440
self.assertNotEquals("A Dummy VCS Dir",
441
newdir._format.get_format_string())
461
self.assertNotEqual("A Dummy VCS Dir",
462
newdir._format.get_format_string())
443
464
def test_push_not_supported(self):
444
465
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)
466
target_tree = self.make_branch_and_tree(
467
"target", format=DummyForeignVcsDirFormat())
468
self.assertRaises(errors.NoRoundtrippingSupport,
469
source_tree.branch.push, target_tree.branch)
450
471
def test_lossy_push_empty(self):
451
472
source_tree = self.make_branch_and_tree("source")
452
target_tree = self.make_branch_and_tree("target",
453
format=DummyForeignVcsDirFormat())
473
target_tree = self.make_branch_and_tree(
474
"target", format=DummyForeignVcsDirFormat())
454
475
pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
455
self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
456
self.assertEquals(revision.NULL_REVISION, pushresult.new_revid)
457
self.assertEquals({}, pushresult.revidmap)
476
self.assertEqual(revision.NULL_REVISION, pushresult.old_revid)
477
self.assertEqual(revision.NULL_REVISION, pushresult.new_revid)
478
self.assertEqual({}, pushresult.revidmap)
459
480
def test_lossy_push_simple(self):
460
481
source_tree = self.make_branch_and_tree("source")
461
482
self.build_tree(['source/a', 'source/b'])
462
483
source_tree.add(['a', 'b'])
463
484
revid1 = source_tree.commit("msg")
464
target_tree = self.make_branch_and_tree("target",
465
format=DummyForeignVcsDirFormat())
485
target_tree = self.make_branch_and_tree(
486
"target", format=DummyForeignVcsDirFormat())
466
487
target_tree.branch.lock_write()
468
pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
489
pushresult = source_tree.branch.push(
490
target_tree.branch, lossy=True)
470
492
target_tree.branch.unlock()
471
self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
472
self.assertEquals({revid1:target_tree.branch.last_revision()},
474
self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)
493
self.assertEqual(revision.NULL_REVISION, pushresult.old_revid)
494
self.assertEqual({revid1: target_tree.branch.last_revision()},
496
self.assertEqual(pushresult.revidmap[revid1], pushresult.new_revid)