806
801
if len(old_repository._fallback_repositories) != 1:
807
802
raise AssertionError("can't cope with fallback repositories "
808
803
"of %r" % (self.repository,))
809
# Open the new repository object.
810
# Repositories don't offer an interface to remove fallback
811
# repositories today; take the conceptually simpler option and just
812
# reopen it. We reopen it starting from the URL so that we
813
# get a separate connection for RemoteRepositories and can
814
# stream from one of them to the other. This does mean doing
815
# separate SSH connection setup, but unstacking is not a
816
# common operation so it's tolerable.
817
new_bzrdir = bzrdir.BzrDir.open(self.bzrdir.root_transport.base)
818
new_repository = new_bzrdir.find_repository()
819
if new_repository._fallback_repositories:
820
raise AssertionError("didn't expect %r to have "
821
"fallback_repositories"
822
% (self.repository,))
823
# Replace self.repository with the new repository.
824
# Do our best to transfer the lock state (i.e. lock-tokens and
825
# lock count) of self.repository to the new repository.
826
lock_token = old_repository.lock_write().repository_token
827
self.repository = new_repository
828
if isinstance(self, remote.RemoteBranch):
829
# Remote branches can have a second reference to the old
830
# repository that need to be replaced.
831
if self._real_branch is not None:
832
self._real_branch.repository = new_repository
833
self.repository.lock_write(token=lock_token)
834
if lock_token is not None:
835
old_repository.leave_lock_in_place()
804
# unlock it, including unlocking the fallback
836
805
old_repository.unlock()
837
if lock_token is not None:
838
# XXX: self.repository.leave_lock_in_place() before this
839
# function will not be preserved. Fortunately that doesn't
840
# affect the current default format (2a), and would be a
841
# corner-case anyway.
842
# - Andrew Bennetts, 2010/06/30
843
self.repository.dont_leave_lock_in_place()
847
old_repository.unlock()
848
except errors.LockNotHeld:
851
if old_lock_count == 0:
852
raise AssertionError(
853
'old_repository should have been locked at least once.')
854
for i in range(old_lock_count-1):
806
old_repository.lock_read()
808
# Repositories don't offer an interface to remove fallback
809
# repositories today; take the conceptually simpler option and just
810
# reopen it. We reopen it starting from the URL so that we
811
# get a separate connection for RemoteRepositories and can
812
# stream from one of them to the other. This does mean doing
813
# separate SSH connection setup, but unstacking is not a
814
# common operation so it's tolerable.
815
new_bzrdir = bzrdir.BzrDir.open(self.bzrdir.root_transport.base)
816
new_repository = new_bzrdir.find_repository()
817
self.repository = new_repository
818
if self.repository._fallback_repositories:
819
raise AssertionError("didn't expect %r to have "
820
"fallback_repositories"
821
% (self.repository,))
822
# this is not paired with an unlock because it's just restoring
823
# the previous state; the lock's released when set_stacked_on_url
855
825
self.repository.lock_write()
856
# Fetch from the old repository into the new.
857
old_repository.lock_read()
859
826
# XXX: If you unstack a branch while it has a working tree
860
827
# with a pending merge, the pending-merged revisions will no
861
828
# longer be present. You can (probably) revert and remerge.
1862
1829
"all are called with the url returned from the previous hook."
1863
1830
"The order is however undefined.", (1, 9), None))
1864
1831
self.create_hook(HookPoint('automatic_tag_name',
1865
"Called to determine an automatic tag name for a revision. "
1832
"Called to determine an automatic tag name for a revision."
1866
1833
"automatic_tag_name is called with (branch, revision_id) and "
1867
1834
"should return a tag name or None if no tag name could be "
1868
1835
"determined. The first non-None tag name returned will be used.",