101
104
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
104
def dpull(self, source, stop_revision=None):
108
class InterToDummyVcsBranch(branch.GenericInterBranch,
109
foreign.InterToForeignBranch):
112
def is_compatible(source, target):
113
return isinstance(target, DummyForeignVcsBranch)
115
def lossy_push(self, stop_revision=None):
116
result = branch.BranchPushResult()
117
result.source_branch = self.source
118
result.target_branch = self.target
119
result.old_revno, result.old_revid = self.target.last_revision_info()
120
self.source.lock_read()
107
122
# This just handles simple cases, but that's good enough for tests
108
my_history = self.revision_history()
109
their_history = source.revision_history()
123
my_history = self.target.revision_history()
124
their_history = self.source.revision_history()
110
125
if their_history[:min(len(my_history), len(their_history))] != my_history:
111
raise errors.DivergedBranches(self, source)
126
raise errors.DivergedBranches(self.target, self.source)
112
127
todo = their_history[len(my_history):]
114
129
for revid in todo:
115
rev = source.repository.get_revision(revid)
116
tree = source.repository.revision_tree(revid)
130
rev = self.source.repository.get_revision(revid)
131
tree = self.source.repository.revision_tree(revid)
117
132
def get_file_with_stat(file_id, path=None):
118
133
return (tree.get_file(file_id), None)
119
134
tree.get_file_with_stat = get_file_with_stat
120
new_revid = self.mapping.revision_id_foreign_to_bzr(
121
(str(rev.timestamp), str(rev.timezone), str(self.revno())))
122
parent_revno, parent_revid= self.last_revision_info()
123
builder = self.get_commit_builder([parent_revid],
124
self.get_config(), rev.timestamp,
135
new_revid = self.target.mapping.revision_id_foreign_to_bzr(
136
(str(rev.timestamp), str(rev.timezone),
137
str(self.target.revno())))
138
parent_revno, parent_revid= self.target.last_revision_info()
139
if parent_revid == NULL_REVISION:
142
parent_revids = [parent_revid]
143
builder = self.target.get_commit_builder(parent_revids,
144
self.target.get_config(), rev.timestamp,
125
145
rev.timezone, rev.committer, rev.properties,
139
159
revidmap[revid] = builder.commit(rev.message)
140
self.set_last_revision_info(parent_revno+1, revidmap[revid])
160
self.target.set_last_revision_info(parent_revno+1,
141
162
trace.mutter('lossily pushed revision %s -> %s',
142
163
revid, revidmap[revid])
166
result.new_revno, result.new_revid = self.target.last_revision_info()
167
result.revidmap = revidmap
148
171
class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6):
278
301
self.assertEquals(mapp, rev.mapping)
281
class ShowForeignPropertiesTests(TestCase):
282
"""Tests for the show_foreign_properties() function."""
285
super(ShowForeignPropertiesTests, self).setUp()
286
self.vcs = DummyForeignVcs()
287
foreign.foreign_vcs_registry.register("dummy",
288
self.vcs, "Dummy VCS")
291
super(ShowForeignPropertiesTests, self).tearDown()
292
foreign.foreign_vcs_registry.remove("dummy")
294
def test_show_non_foreign(self):
295
"""Test use with a native (non-foreign) bzr revision."""
296
self.assertEquals({}, foreign.show_foreign_properties(Revision("arevid")))
298
def test_show_imported(self):
299
rev = Revision("dummy-v1:my-foreign-revid")
300
self.assertEquals({ "dummy ding": "my/foreign\\revid" },
301
foreign.show_foreign_properties(rev))
303
def test_show_direct(self):
304
rev = foreign.ForeignRevision(("some", "foreign", "revid"),
305
DummyForeignVcsMapping(self.vcs),
307
self.assertEquals({ "dummy ding": "some/foreign\\revid" },
308
foreign.show_foreign_properties(rev))
311
304
class WorkingTreeFileUpdateTests(TestCaseWithTransport):
312
305
"""Tests for update_workingtree_fileids()."""
360
356
dir = BzrDir.open("d")
361
357
newdir = dir.sprout("e")
362
358
self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string())
360
def test_lossy_push_empty(self):
361
source_tree = self.make_branch_and_tree("source")
362
target_tree = self.make_branch_and_tree("target",
363
format=DummyForeignVcsDirFormat())
364
pushresult = source_tree.branch.lossy_push(target_tree.branch)
365
self.assertEquals(NULL_REVISION, pushresult.old_revid)
366
self.assertEquals(NULL_REVISION, pushresult.new_revid)
367
self.assertEquals({}, pushresult.revidmap)
369
def test_lossy_push_simple(self):
370
source_tree = self.make_branch_and_tree("source")
371
self.build_tree(['source/a', 'source/b'])
372
source_tree.add(['a', 'b'])
373
revid1 = source_tree.commit("msg")
374
target_tree = self.make_branch_and_tree("target",
375
format=DummyForeignVcsDirFormat())
376
target_tree.branch.lock_write()
378
pushresult = source_tree.branch.lossy_push(target_tree.branch)
380
target_tree.branch.unlock()
381
self.assertEquals(NULL_REVISION, pushresult.old_revid)
382
self.assertEquals({revid1:target_tree.branch.last_revision()},
384
self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)