710
710
"""Synchronize last revision and revision history between branches.
712
712
This version is most efficient when the destination is also a
713
BzrBranch5, but works for BzrBranch6 as long as the revision
714
history is the true lefthand parent history, and all of the revisions
715
are in the destination's repository. If not, set_revision_history
713
BzrBranch6, but works for BzrBranch5, as long as the destination's
714
repository contains all the lefthand ancestors of the intended
715
last_revision. If not, set_last_revision_info will fail.
718
717
:param destination: The branch to copy the history into
719
718
:param revision_id: The revision-id to truncate history at. May
720
719
be None to copy complete history.
722
if revision_id == _mod_revision.NULL_REVISION:
721
source_revno, source_revision_id = self.last_revision_info()
722
if revision_id is None:
723
revno, revision_id = source_revno, source_revision_id
724
elif source_revision_id == revision_id:
725
# we know the revno without needing to walk all of history
725
new_history = self.revision_history()
726
if revision_id is not None and new_history != []:
728
new_history = new_history[:new_history.index(revision_id) + 1]
730
rev = self.repository.get_revision(revision_id)
731
new_history = rev.get_history(self.repository)[1:]
732
destination.set_revision_history(new_history)
728
# To figure out the revno for a random revision, we need to build
729
# the revision history, and count its length.
730
# We don't care about the order, just how long it is.
731
# Alternatively, we could start at the current location, and count
732
# backwards. But there is no guarantee that we will find it since
733
# it may be a merged revision.
734
revno = len(list(self.repository.iter_reverse_revision_history(
736
destination.set_last_revision_info(revno, revision_id)
735
739
def copy_content_into(self, destination, revision_id=None):
736
740
"""Copy the content of self into destination.
1595
1599
if Branch.hooks['post_change_branch_tip']:
1596
1600
self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1602
def _synchronize_history(self, destination, revision_id):
1603
"""Synchronize last revision and revision history between branches.
1605
This version is most efficient when the destination is also a
1606
BzrBranch5, but works for BzrBranch6 as long as the revision
1607
history is the true lefthand parent history, and all of the revisions
1608
are in the destination's repository. If not, set_revision_history
1611
:param destination: The branch to copy the history into
1612
:param revision_id: The revision-id to truncate history at. May
1613
be None to copy complete history.
1615
if revision_id == _mod_revision.NULL_REVISION:
1618
new_history = self.revision_history()
1619
if revision_id is not None and new_history != []:
1621
new_history = new_history[:new_history.index(revision_id) + 1]
1623
rev = self.repository.get_revision(revision_id)
1624
new_history = rev.get_history(self.repository)[1:]
1625
destination.set_revision_history(new_history)
1598
1627
def _run_pre_change_branch_tip_hooks(self, new_revno, new_revid):
1599
1628
"""Run the pre_change_branch_tip hooks."""
1600
1629
hooks = Branch.hooks['pre_change_branch_tip']
2099
2128
self._last_revision_info_cache = revno, revision_id
2100
2129
self._run_post_change_branch_tip_hooks(old_revno, old_revid)
2131
def _synchronize_history(self, destination, revision_id):
2132
"""Synchronize last revision and revision history between branches.
2134
:see: Branch._synchronize_history
2136
# XXX: The base Branch has a fast implementation of this method based
2137
# on set_last_revision_info, but BzrBranch/BzrBranch5 have a slower one
2138
# that uses set_revision_history. This class inherits from BzrBranch5,
2139
# but wants the fast implementation, so it calls
2140
# Branch._synchronize_history directly.
2141
Branch._synchronize_history(self, destination, revision_id)
2102
2143
def _check_history_violation(self, revision_id):
2103
2144
last_revision = _mod_revision.ensure_null(self.last_revision())
2104
2145
if _mod_revision.is_null(last_revision):
2253
2294
value = self.get_config().get_user_option('append_revisions_only')
2254
2295
return value == 'True'
2256
def _synchronize_history(self, destination, revision_id):
2257
"""Synchronize last revision and revision history between branches.
2259
This version is most efficient when the destination is also a
2260
BzrBranch6, but works for BzrBranch5, as long as the destination's
2261
repository contains all the lefthand ancestors of the intended
2262
last_revision. If not, set_last_revision_info will fail.
2264
:param destination: The branch to copy the history into
2265
:param revision_id: The revision-id to truncate history at. May
2266
be None to copy complete history.
2268
source_revno, source_revision_id = self.last_revision_info()
2269
if revision_id is None:
2270
revno, revision_id = source_revno, source_revision_id
2271
elif source_revision_id == revision_id:
2272
# we know the revno without needing to walk all of history
2273
revno = source_revno
2275
# To figure out the revno for a random revision, we need to build
2276
# the revision history, and count its length.
2277
# We don't care about the order, just how long it is.
2278
# Alternatively, we could start at the current location, and count
2279
# backwards. But there is no guarantee that we will find it since
2280
# it may be a merged revision.
2281
revno = len(list(self.repository.iter_reverse_revision_history(
2283
destination.set_last_revision_info(revno, revision_id)
2285
2297
def _make_tags(self):
2286
2298
return BasicTags(self)