783
781
def generate_revision_history(self, revision_id, last_rev=None,
784
782
other_branch=None):
785
783
"""See Branch.generate_revision_history"""
786
# FIXME: This shouldn't have to fetch the entire history
787
history = self._lefthand_history(revision_id, last_rev, other_branch)
784
graph = self.repository.get_graph()
785
known_revision_ids = [
786
self.last_revision_info(),
787
(_mod_revision.NULL_REVISION, 0),
789
if last_rev is not None:
790
if not graph.is_ancestor(last_rev, revision_id):
791
# our previous tip is not merged into stop_revision
792
raise errors.DivergedBranches(self, other_branch)
793
revno = graph.find_distance_to_null(revision_id, known_revision_ids)
789
794
self.set_last_revision_info(revno, revision_id)
790
self._cache_revision_history(history)
792
796
@needs_write_lock
793
797
def set_parent(self, url):
1099
1103
stop_revision=stop_revision,
1100
1104
possible_transports=possible_transports, *args, **kwargs)
1102
def push(self, target, overwrite=False, stop_revision=None, *args,
1106
def push(self, target, overwrite=False, stop_revision=None, lossy=False,
1104
1108
"""Mirror this branch into target.
1106
1110
This branch is considered to be 'local', having low latency.
1108
1112
return InterBranch.get(self, target).push(overwrite, stop_revision,
1111
def lossy_push(self, target, stop_revision=None):
1112
"""Push deltas into another branch.
1114
:note: This does not, like push, retain the revision ids from
1115
the source branch and will, rather than adding bzr-specific
1116
metadata, push only those semantics of the revision that can be
1117
natively represented by this branch' VCS.
1119
:param target: Target branch
1120
:param stop_revision: Revision to push, defaults to last revision.
1121
:return: BranchPushResult with an extra member revidmap:
1122
A dictionary mapping revision ids from the target branch
1123
to new revision ids in the target branch, for each
1124
revision that was pushed.
1126
inter = InterBranch.get(self, target)
1127
lossy_push = getattr(inter, "lossy_push", None)
1128
if lossy_push is None:
1129
raise errors.LossyPushToSameVCS(self, target)
1130
return lossy_push(stop_revision)
1113
lossy, *args, **kwargs)
1132
1115
def basis_tree(self):
1133
1116
"""Return `Tree` object for last revision."""
2809
2792
self._reference_info = None
2811
2794
def _check_history_violation(self, revision_id):
2812
last_revision = _mod_revision.ensure_null(self.last_revision())
2795
current_revid = self.last_revision()
2796
last_revision = _mod_revision.ensure_null(current_revid)
2813
2797
if _mod_revision.is_null(last_revision):
2815
if last_revision not in self._lefthand_history(revision_id):
2816
raise errors.AppendRevisionsOnlyViolation(self.user_url)
2799
graph = self.repository.get_graph()
2800
for lh_ancestor in graph.iter_lefthand_ancestry(revision_id):
2801
if lh_ancestor == current_revid:
2803
raise errors.AppendRevisionsOnlyViolation(self.user_url)
2818
2805
def _gen_revision_history(self):
2819
2806
"""Generate the revision history from last revision
3244
3231
raise NotImplementedError(self.pull)
3246
3233
@needs_write_lock
3247
def push(self, overwrite=False, stop_revision=None,
3234
def push(self, overwrite=False, stop_revision=None, lossy=False,
3248
3235
_override_hook_source_branch=None):
3249
3236
"""Mirror the source branch into the target branch.
3401
3388
if master_branch:
3402
3389
master_branch.unlock()
3404
def push(self, overwrite=False, stop_revision=None,
3391
def push(self, overwrite=False, stop_revision=None, lossy=False,
3405
3392
_override_hook_source_branch=None):
3406
3393
"""See InterBranch.push.
3412
3399
This is for use of RemoteBranch, where push is delegated to the
3413
3400
underlying vfs-based Branch.
3403
raise errors.LossyPushToSameVCS(self.source, self.target)
3415
3404
# TODO: Public option to disable running hooks - should be trivial but
3417
3406
self.source.lock_read()
3419
3408
return _run_with_write_locked_target(
3420
3409
self.target, self._push_with_bound_branches, overwrite,
3422
3411
_override_hook_source_branch=_override_hook_source_branch)
3424
3413
self.source.unlock()