370
370
if revision_id is not None:
371
371
fetch_spec_factory.add_revision_ids([revision_id])
372
372
fetch_spec_factory.source_branch_stop_revision_id = revision_id
373
if possible_transports is None:
374
possible_transports = []
376
possible_transports = list(possible_transports) + [
373
378
target_transport = _mod_transport.get_transport(url,
374
379
possible_transports)
375
380
target_transport.ensure_base()
376
381
cloning_format = self.cloning_metadir(stacked)
377
382
# Create/update the result branch
378
result = cloning_format.initialize_on_transport(target_transport)
384
result = controldir.ControlDir.open_from_transport(target_transport)
385
except errors.NotBranchError:
386
result = cloning_format.initialize_on_transport(target_transport)
379
387
source_branch, source_repository = self._find_source_repo(
380
388
add_cleanup, source_branch)
381
389
fetch_spec_factory.source_branch = source_branch
387
395
stacked_branch_url = None
388
396
repository_policy = result.determine_repository_policy(
389
397
force_new_repo, stacked_branch_url, require_stacking=stacked)
390
result_repo, is_new_repo = repository_policy.acquire_repository()
398
result_repo, is_new_repo = repository_policy.acquire_repository(
399
possible_transports=possible_transports)
391
400
add_cleanup(result_repo.lock_write().unlock)
392
401
fetch_spec_factory.source_repo = source_repository
393
402
fetch_spec_factory.target_repo = result_repo
414
423
mutter("created new branch %r" % (result_branch,))
416
425
# Create/update the result working tree
417
if (create_tree_if_local and
426
if (create_tree_if_local and not result.has_workingtree() and
418
427
isinstance(target_transport, local.LocalTransport) and
419
428
(result_repo is None or result_repo.make_working_trees())):
420
429
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
771
780
return controldir.ControlDir.create(base, format=format,
772
781
possible_transports=possible_transports)
784
return "<%s at %r>" % (self.__class__.__name__, self.user_url)
775
787
class BzrDirMeta1(BzrDir):
776
788
"""A .bzr meta version 1 control object.
788
800
def create_branch(self, name=None, repository=None,
789
801
append_revisions_only=None):
790
802
"""See BzrDir.create_branch."""
804
name = self._get_selected_branch()
791
805
return self._format.get_branch_format().initialize(self, name=name,
792
806
repository=repository,
793
807
append_revisions_only=append_revisions_only)
805
819
def destroy_repository(self):
806
820
"""See BzrDir.destroy_repository."""
807
self.transport.delete_tree('repository')
822
self.transport.delete_tree('repository')
823
except errors.NoSuchFile:
824
raise errors.NoRepositoryPresent(self)
809
826
def create_workingtree(self, revision_id=None, from_branch=None,
810
827
accelerator_tree=None, hardlink=False):
938
955
def open_branch(self, name=None, unsupported=False,
939
ignore_fallbacks=False):
940
"""See BzrDir.open_branch."""
956
ignore_fallbacks=False, possible_transports=None):
957
"""See ControlDir.open_branch."""
959
name = self._get_selected_branch()
941
960
format = self.find_branch_format(name=name)
942
961
format.check_support_status(unsupported)
943
962
return format.open(self, name=name,
944
_found=True, ignore_fallbacks=ignore_fallbacks)
963
_found=True, ignore_fallbacks=ignore_fallbacks,
964
possible_transports=possible_transports)
946
966
def open_repository(self, unsupported=False):
947
967
"""See BzrDir.open_repository."""
983
1003
it uses the default branch.
985
1005
:param name: Optional branch name to use
986
:return: Relative path to branch, branch name
1006
:return: Relative path to branch
988
1008
if name is None:
989
name = self._get_selected_branch()
991
return 'branch', None
992
return urlutils.join('branches', name), name
1010
return urlutils.join('branches', name.encode("utf-8"))
994
1012
def _read_branch_list(self):
995
1013
"""Read the branch list.
1020
1038
def destroy_branch(self, name=None):
1021
1039
"""See BzrDir.create_branch."""
1022
path, name = self._get_branch_path(name)
1041
name = self._get_selected_branch()
1042
path = self._get_branch_path(name)
1023
1043
if name is not None:
1024
1044
self.control_files.lock_write()
1026
1046
branches = self._read_branch_list()
1028
branches.remove(name)
1048
branches.remove(name.encode("utf-8"))
1029
1049
except ValueError:
1030
1050
raise errors.NotBranchError(name)
1031
self._write_branch_list(name)
1051
self._write_branch_list(branches)
1033
1053
self.control_files.unlock()
1034
1054
self.transport.delete_tree(path)
1045
1065
# colocated branches
1046
ret.extend([self.open_branch(name) for name in
1066
ret.extend([self.open_branch(name.decode("utf-8")) for name in
1047
1067
self._read_branch_list()])
1051
1071
def get_branch_transport(self, branch_format, name=None):
1052
1072
"""See BzrDir.get_branch_transport()."""
1053
path, name = self._get_branch_path(name)
1073
path = self._get_branch_path(name)
1054
1074
# XXX: this shouldn't implicitly create the directory if it's just
1055
1075
# promising to get a transport -- mbp 20090727
1056
1076
if branch_format is None:
1065
1085
except errors.FileExists:
1067
1087
branches = self._read_branch_list()
1068
if not name in branches:
1088
utf8_name = name.encode("utf-8")
1089
if not utf8_name in branches:
1069
1090
self.control_files.lock_write()
1071
1092
branches = self._read_branch_list()
1072
branches.append(name)
1093
branches.append(utf8_name)
1073
1094
self._write_branch_list(branches)
1075
1096
self.control_files.unlock()
1832
1853
self._require_stacking = True
1834
def acquire_repository(self, make_working_trees=None, shared=False):
1855
def acquire_repository(self, make_working_trees=None, shared=False,
1856
possible_transports=None):
1835
1857
"""Acquire a repository for this bzrdir.
1837
1859
Implementations may create a new repository or use a pre-exising
1862
1884
require_stacking)
1863
1885
self._bzrdir = bzrdir
1865
def acquire_repository(self, make_working_trees=None, shared=False):
1887
def acquire_repository(self, make_working_trees=None, shared=False,
1888
possible_transports=None):
1866
1889
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
1868
1891
Creates the desired repository in the bzrdir we already have.
1893
if possible_transports is None:
1894
possible_transports = []
1896
possible_transports = list(possible_transports)
1897
possible_transports.append(self._bzrdir.root_transport)
1870
1898
stack_on = self._get_full_stack_on()
1872
1900
format = self._bzrdir._format
1873
1901
format.require_stacking(stack_on=stack_on,
1874
possible_transports=[self._bzrdir.root_transport])
1902
possible_transports=possible_transports)
1875
1903
if not self._require_stacking:
1876
1904
# We have picked up automatic stacking somewhere.
1877
1905
note(gettext('Using default stacking branch {0} at {1}').format(
1878
1906
self._stack_on, self._stack_on_pwd))
1879
1907
repository = self._bzrdir.create_repository(shared=shared)
1880
1908
self._add_fallback(repository,
1881
possible_transports=[self._bzrdir.transport])
1909
possible_transports=possible_transports)
1882
1910
if make_working_trees is not None:
1883
1911
repository.set_make_working_trees(make_working_trees)
1884
1912
return repository, True
1900
1928
require_stacking)
1901
1929
self._repository = repository
1903
def acquire_repository(self, make_working_trees=None, shared=False):
1931
def acquire_repository(self, make_working_trees=None, shared=False,
1932
possible_transports=None):
1904
1933
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
1906
1935
Returns an existing repository to use.
1937
if possible_transports is None:
1938
possible_transports = []
1940
possible_transports = list(possible_transports)
1941
possible_transports.append(self._repository.bzrdir.transport)
1908
1942
self._add_fallback(self._repository,
1909
possible_transports=[self._repository.bzrdir.transport])
1943
possible_transports=possible_transports)
1910
1944
return self._repository, False
1965
1999
deprecated=True)
1966
2000
register_metadir(controldir.format_registry, 'dirstate',
1967
2001
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
1968
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
1969
'above when accessed over the network.',
2002
help='Format using dirstate for working trees. '
2003
'Compatible with bzr 0.8 and '
2004
'above when accessed over the network. Introduced in bzr 0.15.',
1970
2005
branch_format='bzrlib.branch.BzrBranchFormat5',
1971
2006
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
1973
2008
deprecated=True)
1974
2009
register_metadir(controldir.format_registry, 'dirstate-tags',
1975
2010
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
1976
help='New in 0.15: Fast local operations and improved scaling for '
1977
'network operations. Additionally adds support for tags.'
1978
' Incompatible with bzr < 0.15.',
2011
help='Variant of dirstate with support for tags. '
2012
'Introduced in bzr 0.15.',
1979
2013
branch_format='bzrlib.branch.BzrBranchFormat6',
1980
2014
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
1982
2016
deprecated=True)
1983
2017
register_metadir(controldir.format_registry, 'rich-root',
1984
2018
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
1985
help='New in 1.0. Better handling of tree roots. Incompatible with'
2019
help='Variant of dirstate with better handling of tree roots. '
2020
'Introduced in bzr 1.0',
1987
2021
branch_format='bzrlib.branch.BzrBranchFormat6',
1988
2022
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
1990
2024
deprecated=True)
1991
2025
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
1992
2026
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
1993
help='New in 0.15: Fast local operations and improved scaling for '
1994
'network operations. Additionally adds support for versioning nested '
1995
'bzr branches. Incompatible with bzr < 0.15.',
2027
help='Variant of dirstate with support for nested trees. '
2028
'Introduced in 0.15.',
1996
2029
branch_format='bzrlib.branch.BzrBranchFormat6',
1997
2030
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
1998
2031
experimental=True,
2001
2034
register_metadir(controldir.format_registry, 'pack-0.92',
2002
2035
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack1',
2003
help='New in 0.92: Pack-based format with data compatible with '
2004
'dirstate-tags format repositories. Interoperates with '
2005
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2036
help='Pack-based format used in 1.x series. Introduced in 0.92. '
2037
'Interoperates with bzr repositories before 0.92 but cannot be '
2038
'read by bzr < 0.92. '
2007
2040
branch_format='bzrlib.branch.BzrBranchFormat6',
2008
2041
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2010
2044
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
2011
2045
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack3',
2012
help='New in 0.92: Pack-based format with data compatible with '
2013
'dirstate-with-subtree format repositories. Interoperates with '
2046
help='Pack-based format used in 1.x series, with subtree support. '
2047
'Introduced in 0.92. Interoperates with '
2014
2048
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2016
2050
branch_format='bzrlib.branch.BzrBranchFormat6',
2017
2051
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2019
2054
experimental=True,
2021
2056
register_metadir(controldir.format_registry, 'rich-root-pack',
2022
2057
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack4',
2023
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
2024
'(needed for bzr-svn and bzr-git).',
2058
help='A variant of pack-0.92 that supports rich-root data '
2059
'(needed for bzr-svn and bzr-git). Introduced in 1.0.',
2025
2060
branch_format='bzrlib.branch.BzrBranchFormat6',
2026
2061
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2029
2065
register_metadir(controldir.format_registry, '1.6',
2030
2066
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
2034
2070
branch_format='bzrlib.branch.BzrBranchFormat7',
2035
2071
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2038
2075
register_metadir(controldir.format_registry, '1.6.1-rich-root',
2039
2076
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5RichRoot',
2042
2079
branch_format='bzrlib.branch.BzrBranchFormat7',
2043
2080
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2046
2084
register_metadir(controldir.format_registry, '1.9',
2047
2085
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
2051
2089
branch_format='bzrlib.branch.BzrBranchFormat7',
2052
2090
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2055
2094
register_metadir(controldir.format_registry, '1.9-rich-root',
2056
2095
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
2059
2098
branch_format='bzrlib.branch.BzrBranchFormat7',
2060
2099
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2063
2103
register_metadir(controldir.format_registry, '1.14',
2064
2104
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
2065
2105
help='A working-tree format that supports content filtering.',
2066
2106
branch_format='bzrlib.branch.BzrBranchFormat7',
2067
2107
tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
2069
2111
register_metadir(controldir.format_registry, '1.14-rich-root',
2070
2112
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
2072
2114
'(needed for bzr-svn and bzr-git).',
2073
2115
branch_format='bzrlib.branch.BzrBranchFormat7',
2074
2116
tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
2076
2120
# The following un-numbered 'development' formats should always just be aliases.
2077
2121
register_metadir(controldir.format_registry, 'development-subtree',
2110
2154
help='The 2a format with experimental support for colocated branches.\n',
2111
2155
branch_format='bzrlib.branch.BzrBranchFormat7',
2112
2156
tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
2114
2158
bzrdir_format=BzrDirMetaFormat1Colo,
2120
2164
# Finally, the current format.
2121
2165
register_metadir(controldir.format_registry, '2a',
2122
2166
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2123
help='First format for bzr 2.0 series.\n'
2167
help='Format for the bzr 2.0 series.\n'
2124
2168
'Uses group-compress storage.\n'
2125
2169
'Provides rich roots which are a one-way transition.\n',
2126
2170
# 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '