709
709
"""Synchronize last revision and revision history between branches.
711
711
This version is most efficient when the destination is also a
712
BzrBranch5, but works for BzrBranch6 as long as the revision
713
history is the true lefthand parent history, and all of the revisions
714
are in the destination's repository. If not, set_revision_history
712
BzrBranch6, but works for BzrBranch5, as long as the destination's
713
repository contains all the lefthand ancestors of the intended
714
last_revision. If not, set_last_revision_info will fail.
717
716
:param destination: The branch to copy the history into
718
717
:param revision_id: The revision-id to truncate history at. May
719
718
be None to copy complete history.
721
if revision_id == _mod_revision.NULL_REVISION:
720
source_revno, source_revision_id = self.last_revision_info()
721
if revision_id is None:
722
revno, revision_id = source_revno, source_revision_id
723
elif source_revision_id == revision_id:
724
# we know the revno without needing to walk all of history
724
new_history = self.revision_history()
725
if revision_id is not None and new_history != []:
727
new_history = new_history[:new_history.index(revision_id) + 1]
729
rev = self.repository.get_revision(revision_id)
730
new_history = rev.get_history(self.repository)[1:]
731
destination.set_revision_history(new_history)
727
# To figure out the revno for a random revision, we need to build
728
# the revision history, and count its length.
729
# We don't care about the order, just how long it is.
730
# Alternatively, we could start at the current location, and count
731
# backwards. But there is no guarantee that we will find it since
732
# it may be a merged revision.
733
revno = len(list(self.repository.iter_reverse_revision_history(
735
destination.set_last_revision_info(revno, revision_id)
734
738
def copy_content_into(self, destination, revision_id=None):
735
739
"""Copy the content of self into destination.
1594
1598
if Branch.hooks['post_change_branch_tip']:
1595
1599
self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1601
def _synchronize_history(self, destination, revision_id):
1602
"""Synchronize last revision and revision history between branches.
1604
This version is most efficient when the destination is also a
1605
BzrBranch5, but works for BzrBranch6 as long as the revision
1606
history is the true lefthand parent history, and all of the revisions
1607
are in the destination's repository. If not, set_revision_history
1610
:param destination: The branch to copy the history into
1611
:param revision_id: The revision-id to truncate history at. May
1612
be None to copy complete history.
1614
if revision_id == _mod_revision.NULL_REVISION:
1617
new_history = self.revision_history()
1618
if revision_id is not None and new_history != []:
1620
new_history = new_history[:new_history.index(revision_id) + 1]
1622
rev = self.repository.get_revision(revision_id)
1623
new_history = rev.get_history(self.repository)[1:]
1624
destination.set_revision_history(new_history)
1597
1626
def _run_pre_change_branch_tip_hooks(self, new_revno, new_revid):
1598
1627
"""Run the pre_change_branch_tip hooks."""
1599
1628
hooks = Branch.hooks['pre_change_branch_tip']
2098
2127
self._last_revision_info_cache = revno, revision_id
2099
2128
self._run_post_change_branch_tip_hooks(old_revno, old_revid)
2130
def _synchronize_history(self, destination, revision_id):
2131
"""Synchronize last revision and revision history between branches.
2133
:see: Branch._synchronize_history
2135
# XXX: The base Branch has a fast implementation of this method based
2136
# on set_last_revision_info, but BzrBranch/BzrBranch5 have a slower one
2137
# that uses set_revision_history. This class inherits from BzrBranch5,
2138
# but wants the fast implementation, so it calls
2139
# Branch._synchronize_history directly.
2140
Branch._synchronize_history(self, destination, revision_id)
2101
2142
def _check_history_violation(self, revision_id):
2102
2143
last_revision = _mod_revision.ensure_null(self.last_revision())
2103
2144
if _mod_revision.is_null(last_revision):
2252
2293
value = self.get_config().get_user_option('append_revisions_only')
2253
2294
return value == 'True'
2255
def _synchronize_history(self, destination, revision_id):
2256
"""Synchronize last revision and revision history between branches.
2258
This version is most efficient when the destination is also a
2259
BzrBranch6, but works for BzrBranch5, as long as the destination's
2260
repository contains all the lefthand ancestors of the intended
2261
last_revision. If not, set_last_revision_info will fail.
2263
:param destination: The branch to copy the history into
2264
:param revision_id: The revision-id to truncate history at. May
2265
be None to copy complete history.
2267
source_revno, source_revision_id = self.last_revision_info()
2268
if revision_id is None:
2269
revno, revision_id = source_revno, source_revision_id
2270
elif source_revision_id == revision_id:
2271
# we know the revno without needing to walk all of history
2272
revno = source_revno
2274
# To figure out the revno for a random revision, we need to build
2275
# the revision history, and count its length.
2276
# We don't care about the order, just how long it is.
2277
# Alternatively, we could start at the current location, and count
2278
# backwards. But there is no guarantee that we will find it since
2279
# it may be a merged revision.
2280
revno = len(list(self.repository.iter_reverse_revision_history(
2282
destination.set_last_revision_info(revno, revision_id)
2284
2296
def _make_tags(self):
2285
2297
return BasicTags(self)