99
99
def _open_hook(self):
100
100
"""Called by init to allow simpler extension of the base class."""
102
def _activate_fallback_location(self, url):
102
def _activate_fallback_location(self, url, lock_style):
103
103
"""Activate the branch/repository from url as a fallback repository."""
104
self.repository.add_fallback_repository(
105
self._get_fallback_repository(url))
104
repo = self._get_fallback_repository(url)
105
if lock_style == 'write':
107
elif lock_style == 'read':
109
self.repository.add_fallback_repository(repo)
107
111
def break_lock(self):
108
112
"""Break a lock if one is present from another instance.
608
612
url = urlutils.relative_url(self.base, url)
609
613
self._set_parent_location(url)
611
616
def set_stacked_on_url(self, url):
612
617
"""Set the URL this branch is stacked against.
626
631
errors.UnstackableRepositoryFormat):
634
# XXX: Lock correctness - should unlock our old repo if we were
629
636
# repositories don't offer an interface to remove fallback
630
637
# repositories today; take the conceptually simpler option and just
632
639
self.repository = self.bzrdir.find_repository()
640
self.repository.lock_write()
633
641
# for every revision reference the branch has, ensure it is pulled
635
643
source_repository = self._get_fallback_repository(old_url)
638
646
self.repository.fetch(source_repository, revision_id,
639
647
find_ghosts=True)
641
self._activate_fallback_location(url)
649
self._activate_fallback_location(url, 'write')
642
650
# write this out after the repository is stacked to avoid setting a
643
651
# stacked config that doesn't work.
644
652
self._set_config_location('stacked_on_location', url)
997
1005
be truncated to end with revision_id.
999
1007
result = to_bzrdir.create_branch()
1000
if repository_policy is not None:
1001
repository_policy.configure_branch(result)
1002
self.copy_content_into(result, revision_id=revision_id)
1010
if repository_policy is not None:
1011
repository_policy.configure_branch(result)
1012
self.copy_content_into(result, revision_id=revision_id)
1005
1017
@needs_read_lock
1006
1018
def sprout(self, to_bzrdir, revision_id=None, repository_policy=None):
1012
1024
be truncated to end with revision_id.
1014
1026
result = to_bzrdir.create_branch()
1015
if repository_policy is not None:
1016
repository_policy.configure_branch(result)
1017
self.copy_content_into(result, revision_id=revision_id)
1018
result.set_parent(self.bzrdir.root_transport.base)
1029
if repository_policy is not None:
1030
repository_policy.configure_branch(result)
1031
self.copy_content_into(result, revision_id=revision_id)
1032
result.set_parent(self.bzrdir.root_transport.base)
1021
1037
def _synchronize_history(self, destination, revision_id):
1914
1930
return self.control_files.is_locked()
1916
1932
def lock_write(self, token=None):
1917
repo_token = self.repository.lock_write()
1933
# All-in-one needs to always unlock/lock.
1934
repo_control = getattr(self.repository, 'control_files', None)
1935
if self.control_files == repo_control or not self.is_locked():
1936
self.repository.lock_write()
1919
token = self.control_files.lock_write(token=token)
1941
return self.control_files.lock_write(token=token)
1921
self.repository.unlock()
1944
self.repository.unlock()
1925
1947
def lock_read(self):
1926
self.repository.lock_read()
1948
# All-in-one needs to always unlock/lock.
1949
repo_control = getattr(self.repository, 'control_files', None)
1950
if self.control_files == repo_control or not self.is_locked():
1951
self.repository.lock_read()
1928
1956
self.control_files.lock_read()
1930
self.repository.unlock()
1959
self.repository.unlock()
1933
1962
def unlock(self):
1934
# TODO: test for failed two phase locks. This is known broken.
1936
1964
self.control_files.unlock()
1938
self.repository.unlock()
1939
if not self.control_files.is_locked():
1940
# we just released the lock
1941
self._clear_cached_state()
1966
# All-in-one needs to always unlock/lock.
1967
repo_control = getattr(self.repository, 'control_files', None)
1968
if (self.control_files == repo_control or
1969
not self.control_files.is_locked()):
1970
self.repository.unlock()
1971
if not self.control_files.is_locked():
1972
# we just released the lock
1973
self._clear_cached_state()
1943
1975
def peek_lock_mode(self):
1944
1976
if self.control_files._lock_count == 0:
2363
2395
raise AssertionError(
2364
2396
"'transform_fallback_location' hook %s returned "
2365
2397
"None, not a URL." % hook_name)
2366
self._activate_fallback_location(url)
2398
self._activate_fallback_location(url, None)
2368
2400
def __init__(self, *args, **kwargs):
2369
2401
self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)