110
110
def import_last_revision_info_and_tags(self, source, revno, revid,
112
112
interbranch = InterToDummyVcsBranch(source, self)
113
result = interbranch.push(stop_revision=revid, lossy=True)
114
result = interbranch.lossy_push(revid)
115
115
revid = result.revidmap[revid]
117
interbranch.push(revid)
116
118
return (revno, revid)
148
150
return "Dummy Foreign Vcs Repository"
151
class InterToDummyVcsBranch(branch.GenericInterBranch):
153
class InterToDummyVcsBranch(branch.GenericInterBranch,
154
foreign.InterToForeignBranch):
154
157
def is_compatible(source, target):
155
158
return isinstance(target, DummyForeignVcsBranch)
157
def push(self, overwrite=False, stop_revision=None, lossy=False):
159
raise errors.NoRoundtrippingSupport(self.source, self.target)
160
def push(self, overwrite=False, stop_revision=None):
161
raise errors.NoRoundtrippingSupport(self.source, self.target)
163
def lossy_push(self, stop_revision=None):
160
164
result = branch.BranchPushResult()
161
165
result.source_branch = self.source
162
166
result.target_branch = self.target
163
167
result.old_revno, result.old_revid = self.target.last_revision_info()
164
168
self.source.lock_read()
166
graph = self.source.repository.get_graph()
167
170
# This just handles simple cases, but that's good enough for tests
168
171
my_history = self.target.revision_history()
169
172
if stop_revision is None:
170
173
stop_revision = self.source.last_revision()
171
their_history = list(graph.iter_lefthand_ancestry(stop_revision,
172
(revision.NULL_REVISION,)))
174
their_history = list(self.source.repository.iter_reverse_revision_history(stop_revision))
173
175
their_history.reverse()
174
176
if their_history[:min(len(my_history), len(their_history))] != my_history:
175
177
raise errors.DivergedBranches(self.target, self.source)
182
184
return (tree.get_file(file_id), None)
183
185
tree.get_file_with_stat = get_file_with_stat
184
186
new_revid = self.target.mapping.revision_id_foreign_to_bzr(
185
(str(rev.timestamp), str(rev.timezone),
187
(str(rev.timestamp), str(rev.timezone),
186
188
str(self.target.revno())))
187
189
parent_revno, parent_revid= self.target.last_revision_info()
188
190
if parent_revid == revision.NULL_REVISION:
451
453
source_tree = self.make_branch_and_tree("source")
452
454
target_tree = self.make_branch_and_tree("target",
453
455
format=DummyForeignVcsDirFormat())
454
pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
456
pushresult = source_tree.branch.lossy_push(target_tree.branch)
455
457
self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
456
458
self.assertEquals(revision.NULL_REVISION, pushresult.new_revid)
457
459
self.assertEquals({}, pushresult.revidmap)
465
467
format=DummyForeignVcsDirFormat())
466
468
target_tree.branch.lock_write()
468
pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
470
pushresult = source_tree.branch.lossy_push(target_tree.branch)
470
472
target_tree.branch.unlock()
471
473
self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)