235
258
t = _mod_transport.get_transport(url)
262
def find_bzrdirs(transport, evaluate=None, list_current=None):
263
"""Find bzrdirs recursively from current location.
265
This is intended primarily as a building block for more sophisticated
266
functionality, like finding trees under a directory, or finding
267
branches that use a given repository.
269
:param evaluate: An optional callable that yields recurse, value,
270
where recurse controls whether this bzrdir is recursed into
271
and value is the value to yield. By default, all bzrdirs
272
are recursed into, and the return value is the bzrdir.
273
:param list_current: if supplied, use this function to list the current
274
directory, instead of Transport.list_dir
275
:return: a generator of found bzrdirs, or whatever evaluate returns.
277
if list_current is None:
278
def list_current(transport):
279
return transport.list_dir('')
281
def evaluate(bzrdir):
284
pending = [transport]
285
while len(pending) > 0:
286
current_transport = pending.pop()
289
bzrdir = BzrDir.open_from_transport(current_transport)
290
except (errors.NotBranchError, errors.PermissionDenied):
293
recurse, value = evaluate(bzrdir)
296
subdirs = list_current(current_transport)
297
except (errors.NoSuchFile, errors.PermissionDenied):
300
for subdir in sorted(subdirs, reverse=True):
301
pending.append(current_transport.clone(subdir))
304
def find_branches(transport):
305
"""Find all branches under a transport.
307
This will find all branches below the transport, including branches
308
inside other branches. Where possible, it will use
309
Repository.find_branches.
311
To list all the branches that use a particular Repository, see
312
Repository.find_branches
314
def evaluate(bzrdir):
316
repository = bzrdir.open_repository()
317
except errors.NoRepositoryPresent:
320
return False, ([], repository)
321
return True, (bzrdir.list_branches(), None)
323
for branches, repo in BzrDir.find_bzrdirs(transport,
326
ret.extend(repo.find_branches())
327
if branches is not None:
332
def create_branch_and_repo(base, force_new_repo=False, format=None):
333
"""Create a new BzrDir, Branch and Repository at the url 'base'.
335
This will use the current default BzrDirFormat unless one is
336
specified, and use whatever
337
repository format that that uses via bzrdir.create_branch and
338
create_repository. If a shared repository is available that is used
341
The created Branch object is returned.
343
:param base: The URL to create the branch at.
344
:param force_new_repo: If True a new repository is always created.
345
:param format: If supplied, the format of branch to create. If not
346
supplied, the default is used.
348
bzrdir = BzrDir.create(base, format)
349
bzrdir._find_or_create_repository(force_new_repo)
350
return bzrdir.create_branch()
238
352
def determine_repository_policy(self, force_new_repo=False, stack_on=None,
239
353
stack_on_pwd=None, require_stacking=False):
240
354
"""Return an object representing a policy to use.
575
def create_branch_convenience(base, force_new_repo=False,
576
force_new_tree=None, format=None,
577
possible_transports=None):
578
"""Create a new BzrDir, Branch and Repository at the url 'base'.
580
This is a convenience function - it will use an existing repository
581
if possible, can be told explicitly whether to create a working tree or
584
This will use the current default BzrDirFormat unless one is
585
specified, and use whatever
586
repository format that that uses via bzrdir.create_branch and
587
create_repository. If a shared repository is available that is used
588
preferentially. Whatever repository is used, its tree creation policy
591
The created Branch object is returned.
592
If a working tree cannot be made due to base not being a file:// url,
593
no error is raised unless force_new_tree is True, in which case no
594
data is created on disk and NotLocalUrl is raised.
596
:param base: The URL to create the branch at.
597
:param force_new_repo: If True a new repository is always created.
598
:param force_new_tree: If True or False force creation of a tree or
599
prevent such creation respectively.
600
:param format: Override for the bzrdir format to create.
601
:param possible_transports: An optional reusable transports list.
604
# check for non local urls
605
t = _mod_transport.get_transport(base, possible_transports)
606
if not isinstance(t, local.LocalTransport):
607
raise errors.NotLocalUrl(base)
608
bzrdir = BzrDir.create(base, format, possible_transports)
609
repo = bzrdir._find_or_create_repository(force_new_repo)
610
result = bzrdir.create_branch()
611
if force_new_tree or (repo.make_working_trees() and
612
force_new_tree is None):
614
bzrdir.create_workingtree()
615
except errors.NotLocalUrl:
620
def create_standalone_workingtree(base, format=None):
621
"""Create a new BzrDir, WorkingTree, Branch and Repository at 'base'.
623
'base' must be a local path or a file:// url.
625
This will use the current default BzrDirFormat unless one is
626
specified, and use whatever
627
repository format that that uses for bzrdirformat.create_workingtree,
628
create_branch and create_repository.
630
:param format: Override for the bzrdir format to create.
631
:return: The WorkingTree object.
633
t = _mod_transport.get_transport(base)
634
if not isinstance(t, local.LocalTransport):
635
raise errors.NotLocalUrl(base)
636
bzrdir = BzrDir.create_branch_and_repo(base,
638
format=format).bzrdir
639
return bzrdir.create_workingtree()
468
641
@deprecated_method(deprecated_in((2, 3, 0)))
469
642
def generate_backup_name(self, base):
470
643
return self._available_backup_name(base)
667
839
# add new tests for it to the appropriate place.
668
840
return filename == '.bzr' or filename.startswith('.bzr/')
843
def open_unsupported(base):
844
"""Open a branch which is not supported."""
845
return BzrDir.open(base, _unsupported=True)
848
def open(base, _unsupported=False, possible_transports=None):
849
"""Open an existing bzrdir, rooted at 'base' (url).
851
:param _unsupported: a private parameter to the BzrDir class.
853
t = _mod_transport.get_transport(base, possible_transports)
854
return BzrDir.open_from_transport(t, _unsupported=_unsupported)
857
def open_from_transport(transport, _unsupported=False,
858
_server_formats=True):
859
"""Open a bzrdir within a particular directory.
861
:param transport: Transport containing the bzrdir.
862
:param _unsupported: private.
864
for hook in BzrDir.hooks['pre_open']:
866
# Keep initial base since 'transport' may be modified while following
868
base = transport.base
869
def find_format(transport):
870
return transport, controldir.ControlDirFormat.find_format(
871
transport, _server_formats=_server_formats)
873
def redirected(transport, e, redirection_notice):
874
redirected_transport = transport._redirected_to(e.source, e.target)
875
if redirected_transport is None:
876
raise errors.NotBranchError(base)
877
note('%s is%s redirected to %s',
878
transport.base, e.permanently, redirected_transport.base)
879
return redirected_transport
882
transport, format = do_catching_redirections(find_format,
885
except errors.TooManyRedirections:
886
raise errors.NotBranchError(base)
888
format.check_support_status(_unsupported)
889
return format.open(transport, _found=True)
892
def open_containing(url, possible_transports=None):
893
"""Open an existing branch which contains url.
895
:param url: url to search from.
897
See open_containing_from_transport for more detail.
899
transport = _mod_transport.get_transport(url, possible_transports)
900
return BzrDir.open_containing_from_transport(transport)
903
def open_containing_from_transport(a_transport):
904
"""Open an existing branch which contains a_transport.base.
906
This probes for a branch at a_transport, and searches upwards from there.
908
Basically we keep looking up until we find the control directory or
909
run into the root. If there isn't one, raises NotBranchError.
910
If there is one and it is either an unrecognised format or an unsupported
911
format, UnknownFormatError or UnsupportedFormatError are raised.
912
If there is one, it is returned, along with the unused portion of url.
914
:return: The BzrDir that contains the path, and a Unicode path
915
for the rest of the URL.
917
# this gets the normalised url back. I.e. '.' -> the full path.
918
url = a_transport.base
921
result = BzrDir.open_from_transport(a_transport)
922
return result, urlutils.unescape(a_transport.relpath(url))
923
except errors.NotBranchError, e:
926
new_t = a_transport.clone('..')
927
except errors.InvalidURLJoin:
928
# reached the root, whatever that may be
929
raise errors.NotBranchError(path=url)
930
if new_t.base == a_transport.base:
931
# reached the root, whatever that may be
932
raise errors.NotBranchError(path=url)
936
def open_tree_or_branch(klass, location):
937
"""Return the branch and working tree at a location.
939
If there is no tree at the location, tree will be None.
940
If there is no branch at the location, an exception will be
942
:return: (tree, branch)
944
bzrdir = klass.open(location)
945
return bzrdir._get_tree_branch()
948
def open_containing_tree_or_branch(klass, location):
949
"""Return the branch and working tree contained by a location.
951
Returns (tree, branch, relpath).
952
If there is no tree at containing the location, tree will be None.
953
If there is no branch containing the location, an exception will be
955
relpath is the portion of the path that is contained by the branch.
957
bzrdir, relpath = klass.open_containing(location)
958
tree, branch = bzrdir._get_tree_branch()
959
return tree, branch, relpath
962
def open_containing_tree_branch_or_repository(klass, location):
963
"""Return the working tree, branch and repo contained by a location.
965
Returns (tree, branch, repository, relpath).
966
If there is no tree containing the location, tree will be None.
967
If there is no branch containing the location, branch will be None.
968
If there is no repository containing the location, repository will be
970
relpath is the portion of the path that is contained by the innermost
973
If no tree, branch or repository is found, a NotBranchError is raised.
975
bzrdir, relpath = klass.open_containing(location)
977
tree, branch = bzrdir._get_tree_branch()
978
except errors.NotBranchError:
980
repo = bzrdir.find_repository()
981
return None, None, repo, relpath
982
except (errors.NoRepositoryPresent):
983
raise errors.NotBranchError(location)
984
return tree, branch, branch.repository, relpath
670
986
def _cloning_metadir(self):
671
987
"""Produce a metadir suitable for cloning with.
770
1104
raise NotImplementedError(self.get_workingtree_transport)
773
def create(cls, base, format=None, possible_transports=None):
774
"""Create a new BzrDir at the url 'base'.
776
:param format: If supplied, the format of branch to create. If not
777
supplied, the default is used.
778
:param possible_transports: If supplied, a list of transports that
779
can be reused to share a remote connection.
1107
class BzrDirHooks(hooks.Hooks):
1108
"""Hooks for BzrDir operations."""
1111
"""Create the default hooks."""
1112
hooks.Hooks.__init__(self, "bzrlib.bzrdir", "BzrDir.hooks")
1113
self.add_hook('pre_open',
1114
"Invoked before attempting to open a BzrDir with the transport "
1115
"that the open will use.", (1, 14))
1116
self.add_hook('post_repo_init',
1117
"Invoked after a repository has been initialized. "
1118
"post_repo_init is called with a "
1119
"bzrlib.bzrdir.RepoInitHookParams.",
1122
# install the default hooks
1123
BzrDir.hooks = BzrDirHooks()
1126
class RepoInitHookParams(object):
1127
"""Object holding parameters passed to `*_repo_init` hooks.
1129
There are 4 fields that hooks may wish to access:
1131
:ivar repository: Repository created
1132
:ivar format: Repository format
1133
:ivar bzrdir: The bzrdir for the repository
1134
:ivar shared: The repository is shared
1137
def __init__(self, repository, format, a_bzrdir, shared):
1138
"""Create a group of RepoInitHook parameters.
1140
:param repository: Repository created
1141
:param format: Repository format
1142
:param bzrdir: The bzrdir for the repository
1143
:param shared: The repository is shared
781
if cls is not BzrDir:
782
raise AssertionError("BzrDir.create always creates the "
783
"default format, not one of %r" % cls)
784
return controldir.ControlDir.create(base, format=format,
785
possible_transports=possible_transports)
1145
self.repository = repository
1146
self.format = format
1147
self.bzrdir = a_bzrdir
1148
self.shared = shared
1150
def __eq__(self, other):
1151
return self.__dict__ == other.__dict__
787
1153
def __repr__(self):
788
return "<%s at %r>" % (self.__class__.__name__, self.user_url)
790
def update_feature_flags(self, updated_flags):
791
"""Update the features required by this bzrdir.
793
:param updated_flags: Dictionary mapping feature names to necessities
794
A necessity can be None to indicate the feature should be removed
796
self.control_files.lock_write()
798
self._format._update_feature_flags(updated_flags)
799
self.transport.put_bytes('branch-format', self._format.as_string())
801
self.control_files.unlock()
1155
return "<%s for %s>" % (self.__class__.__name__,
1158
return "<%s for %s>" % (self.__class__.__name__,
804
1162
class BzrDirMeta1(BzrDir):
810
1168
present within a BzrDir.
813
def _get_branch_path(self, name):
814
"""Obtain the branch path to use.
816
This uses the API specified branch name first, and then falls back to
817
the branch name specified in the URL. If neither of those is specified,
818
it uses the default branch.
820
:param name: Optional branch name to use
821
:return: Relative path to branch
825
return urlutils.join('branches', name.encode("utf-8"))
827
def _read_branch_list(self):
828
"""Read the branch list.
830
:return: List of utf-8 encoded branch names.
833
f = self.control_transport.get('branch-list')
834
except errors.NoSuchFile:
840
ret.append(name.rstrip("\n"))
845
def _write_branch_list(self, branches):
846
"""Write out the branch list.
848
:param branches: List of utf-8 branch names to write
850
self.transport.put_bytes('branch-list',
851
"".join([name+"\n" for name in branches]))
853
def __init__(self, _transport, _format):
854
super(BzrDirMeta1, self).__init__(_transport, _format)
855
self.control_files = lockable_files.LockableFiles(
856
self.control_transport, self._format._lock_file_name,
857
self._format._lock_class)
859
1171
def can_convert_format(self):
860
1172
"""See BzrDir.can_convert_format()."""
863
def create_branch(self, name=None, repository=None,
864
append_revisions_only=None):
865
"""See ControlDir.create_branch."""
867
name = self._get_selected_branch()
1175
def create_branch(self, name=None, repository=None):
1176
"""See BzrDir.create_branch."""
868
1177
return self._format.get_branch_format().initialize(self, name=name,
869
repository=repository,
870
append_revisions_only=append_revisions_only)
1178
repository=repository)
872
1180
def destroy_branch(self, name=None):
873
"""See ControlDir.destroy_branch."""
875
name = self._get_selected_branch()
876
path = self._get_branch_path(name)
878
self.control_files.lock_write()
880
branches = self._read_branch_list()
882
branches.remove(name.encode("utf-8"))
884
raise errors.NotBranchError(name)
885
self._write_branch_list(branches)
887
self.control_files.unlock()
889
self.transport.delete_tree(path)
890
except errors.NoSuchFile:
891
raise errors.NotBranchError(path=urlutils.join(self.transport.base,
1181
"""See BzrDir.create_branch."""
1182
if name is not None:
1183
raise errors.NoColocatedBranchSupport(self)
1184
self.transport.delete_tree('branch')
894
1186
def create_repository(self, shared=False):
895
1187
"""See BzrDir.create_repository."""
940
1229
def get_branch_reference(self, name=None):
941
1230
"""See BzrDir.get_branch_reference()."""
942
from bzrlib.branch import BranchFormatMetadir
943
format = BranchFormatMetadir.find_format(self, name=name)
1231
from bzrlib.branch import BranchFormat
1232
format = BranchFormat.find_format(self, name=name)
944
1233
return format.get_reference(self, name=name)
946
def set_branch_reference(self, target_branch, name=None):
947
format = _mod_branch.BranchReferenceFormat()
948
return format.initialize(self, target_branch=target_branch, name=name)
950
1235
def get_branch_transport(self, branch_format, name=None):
951
1236
"""See BzrDir.get_branch_transport()."""
953
name = self._get_selected_branch()
954
path = self._get_branch_path(name)
1237
if name is not None:
1238
raise errors.NoColocatedBranchSupport(self)
955
1239
# XXX: this shouldn't implicitly create the directory if it's just
956
1240
# promising to get a transport -- mbp 20090727
957
1241
if branch_format is None:
958
return self.transport.clone(path)
1242
return self.transport.clone('branch')
960
1244
branch_format.get_format_string()
961
1245
except NotImplementedError:
962
1246
raise errors.IncompatibleFormat(branch_format, self._format)
964
branches = self._read_branch_list()
965
utf8_name = name.encode("utf-8")
966
if not utf8_name in branches:
967
self.control_files.lock_write()
969
branches = self._read_branch_list()
970
dirname = urlutils.dirname(utf8_name)
971
if dirname != "" and dirname in branches:
972
raise errors.ParentBranchExists(name)
974
b.startswith(utf8_name+"/") for b in branches]
975
if any(child_branches):
976
raise errors.AlreadyBranchError(name)
977
branches.append(utf8_name)
978
self._write_branch_list(branches)
980
self.control_files.unlock()
981
branch_transport = self.transport.clone(path)
982
mode = self._get_mkdir_mode()
983
branch_transport.create_prefix(mode=mode)
985
self.transport.mkdir(path, mode=mode)
1248
self.transport.mkdir('branch', mode=self._get_mkdir_mode())
986
1249
except errors.FileExists:
988
return self.transport.clone(path)
1251
return self.transport.clone('branch')
990
1253
def get_repository_transport(self, repository_format):
991
1254
"""See BzrDir.get_repository_transport()."""
1016
1279
return self.transport.clone('checkout')
1018
def get_branches(self):
1019
"""See ControlDir.get_branches."""
1022
ret[""] = self.open_branch(name="")
1023
except (errors.NotBranchError, errors.NoRepositoryPresent):
1026
for name in self._read_branch_list():
1027
ret[name] = self.open_branch(name=name.decode('utf-8'))
1031
1281
def has_workingtree(self):
1032
1282
"""Tell if this bzrdir contains a working tree.
1034
1284
Note: if you're going to open the working tree, you should just go
1035
1285
ahead and try, and not ask permission first.
1037
from bzrlib.workingtree import WorkingTreeFormatMetaDir
1287
from bzrlib.workingtree import WorkingTreeFormat
1039
WorkingTreeFormatMetaDir.find_format_string(self)
1289
WorkingTreeFormat.find_format_string(self)
1040
1290
except errors.NoWorkingTree:
1044
1294
def needs_format_conversion(self, format):
1045
1295
"""See BzrDir.needs_format_conversion()."""
1046
if (not isinstance(self._format, format.__class__) or
1047
self._format.get_format_string() != format.get_format_string()):
1296
if not isinstance(self._format, format.__class__):
1048
1297
# it is not a meta dir format, conversion is needed.
1050
1299
# we might want to push this down to the repository?
1073
1322
def open_branch(self, name=None, unsupported=False,
1074
ignore_fallbacks=False, possible_transports=None):
1075
"""See ControlDir.open_branch."""
1077
name = self._get_selected_branch()
1323
ignore_fallbacks=False):
1324
"""See BzrDir.open_branch."""
1078
1325
format = self.find_branch_format(name=name)
1079
1326
format.check_support_status(unsupported)
1080
1327
return format.open(self, name=name,
1081
_found=True, ignore_fallbacks=ignore_fallbacks,
1082
possible_transports=possible_transports)
1328
_found=True, ignore_fallbacks=ignore_fallbacks)
1084
1330
def open_repository(self, unsupported=False):
1085
1331
"""See BzrDir.open_repository."""
1086
from bzrlib.repository import RepositoryFormatMetaDir
1087
format = RepositoryFormatMetaDir.find_format(self)
1332
from bzrlib.repository import RepositoryFormat
1333
format = RepositoryFormat.find_format(self)
1088
1334
format.check_support_status(unsupported)
1089
1335
return format.open(self, _found=True)
1091
1337
def open_workingtree(self, unsupported=False,
1092
1338
recommend_upgrade=True):
1093
1339
"""See BzrDir.open_workingtree."""
1094
from bzrlib.workingtree import WorkingTreeFormatMetaDir
1095
format = WorkingTreeFormatMetaDir.find_format(self)
1340
from bzrlib.workingtree import WorkingTreeFormat
1341
format = WorkingTreeFormat.find_format(self)
1096
1342
format.check_support_status(unsupported, recommend_upgrade,
1097
1343
basedir=self.root_transport.base)
1098
1344
return format.open(self, _found=True)
1101
1347
return config.TransportConfig(self.transport, 'control.conf')
1104
class BzrFormat(object):
1105
"""Base class for all formats of things living in metadirs.
1107
This class manages the format string that is stored in the 'format'
1108
or 'branch-format' file.
1110
All classes for (branch-, repository-, workingtree-) formats that
1111
live in meta directories and have their own 'format' file
1112
(i.e. different from .bzr/branch-format) derive from this class,
1113
as well as the relevant base class for their kind
1114
(BranchFormat, WorkingTreeFormat, RepositoryFormat).
1116
Each format is identified by a "format" or "branch-format" file with a
1117
single line containing the base format name and then an optional list of
1120
Feature flags are supported as of bzr 2.5. Setting feature flags on formats
1121
will render them inaccessible to older versions of bzr.
1123
:ivar features: Dictionary mapping feature names to their necessity
1126
_present_features = set()
1132
def register_feature(cls, name):
1133
"""Register a feature as being present.
1135
:param name: Name of the feature
1138
raise ValueError("spaces are not allowed in feature names")
1139
if name in cls._present_features:
1140
raise errors.FeatureAlreadyRegistered(name)
1141
cls._present_features.add(name)
1144
def unregister_feature(cls, name):
1145
"""Unregister a feature."""
1146
cls._present_features.remove(name)
1148
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1150
for name, necessity in self.features.iteritems():
1151
if name in self._present_features:
1153
if necessity == "optional":
1154
mutter("ignoring optional missing feature %s", name)
1156
elif necessity == "required":
1157
raise errors.MissingFeature(name)
1159
mutter("treating unknown necessity as require for %s",
1161
raise errors.MissingFeature(name)
1164
def get_format_string(cls):
1165
"""Return the ASCII format string that identifies this format."""
1166
raise NotImplementedError(cls.get_format_string)
1169
def from_string(cls, text):
1170
format_string = cls.get_format_string()
1171
if not text.startswith(format_string):
1172
raise AssertionError("Invalid format header %r for %r" % (text, cls))
1173
lines = text[len(format_string):].splitlines()
1175
for lineno, line in enumerate(lines):
1177
(necessity, feature) = line.split(" ", 1)
1179
raise errors.ParseFormatError(format=cls, lineno=lineno+2,
1180
line=line, text=text)
1181
ret.features[feature] = necessity
1184
def as_string(self):
1185
"""Return the string representation of this format.
1187
lines = [self.get_format_string()]
1188
lines.extend([("%s %s\n" % (item[1], item[0])) for item in
1189
self.features.iteritems()])
1190
return "".join(lines)
1193
def _find_format(klass, registry, kind, format_string):
1195
first_line = format_string[:format_string.index("\n")+1]
1197
first_line = format_string
1199
cls = registry.get(first_line)
1201
raise errors.UnknownFormatError(format=first_line, kind=kind)
1202
return cls.from_string(format_string)
1204
def network_name(self):
1205
"""A simple byte string uniquely identifying this format for RPC calls.
1207
Metadir branch formats use their format string.
1209
return self.as_string()
1211
def __eq__(self, other):
1212
return (self.__class__ is other.__class__ and
1213
self.features == other.features)
1215
def _update_feature_flags(self, updated_flags):
1216
"""Update the feature flags in this format.
1218
:param updated_flags: Updated feature flags
1220
for name, necessity in updated_flags.iteritems():
1221
if necessity is None:
1223
del self.features[name]
1227
self.features[name] = necessity
1230
1350
class BzrProber(controldir.Prober):
1231
1351
"""Prober for formats that use a .bzr/ control directory."""
1763
1856
controldir.ControlDirFormat._default_format = BzrDirMetaFormat1()
1766
class BzrDirMetaFormat1Colo(BzrDirMetaFormat1):
1767
"""BzrDirMeta1 format with support for colocated branches."""
1769
colocated_branches = True
1772
def get_format_string(cls):
1773
"""See BzrDirFormat.get_format_string()."""
1774
return "Bazaar meta directory, format 1 (with colocated branches)\n"
1776
def get_format_description(self):
1777
"""See BzrDirFormat.get_format_description()."""
1778
return "Meta directory format 1 with support for colocated branches"
1780
def _open(self, transport):
1781
"""See BzrDirFormat._open."""
1782
# Create a new format instance because otherwise initialisation of new
1783
# metadirs share the global default format object leading to alias
1785
format = BzrDirMetaFormat1Colo()
1786
self._supply_sub_formats_to(format)
1787
return BzrDirMeta1(transport, format)
1790
BzrProber.formats.register(BzrDirMetaFormat1Colo.get_format_string(),
1791
BzrDirMetaFormat1Colo)
1794
1859
class ConvertMetaToMeta(controldir.Converter):
1795
1860
"""Converts the components of metadirs."""
1869
1934
return to_convert
1872
class ConvertMetaToColo(controldir.Converter):
1873
"""Add colocated branch support."""
1875
def __init__(self, target_format):
1876
"""Create a converter.that upgrades a metadir to the colo format.
1878
:param target_format: The final metadir format that is desired.
1880
self.target_format = target_format
1882
def convert(self, to_convert, pb):
1883
"""See Converter.convert()."""
1884
to_convert.transport.put_bytes('branch-format',
1885
self.target_format.as_string())
1886
return BzrDir.open_from_transport(to_convert.root_transport)
1889
class ConvertMetaToColo(controldir.Converter):
1890
"""Convert a 'development-colo' bzrdir to a '2a' bzrdir."""
1892
def __init__(self, target_format):
1893
"""Create a converter that converts a 'development-colo' metadir
1896
:param target_format: The final metadir format that is desired.
1898
self.target_format = target_format
1900
def convert(self, to_convert, pb):
1901
"""See Converter.convert()."""
1902
to_convert.transport.put_bytes('branch-format',
1903
self.target_format.as_string())
1904
return BzrDir.open_from_transport(to_convert.root_transport)
1907
1937
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
2018
2047
require_stacking)
2019
2048
self._bzrdir = bzrdir
2021
def acquire_repository(self, make_working_trees=None, shared=False,
2022
possible_transports=None):
2050
def acquire_repository(self, make_working_trees=None, shared=False):
2023
2051
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2025
2053
Creates the desired repository in the bzrdir we already have.
2027
if possible_transports is None:
2028
possible_transports = []
2030
possible_transports = list(possible_transports)
2031
possible_transports.append(self._bzrdir.root_transport)
2032
2055
stack_on = self._get_full_stack_on()
2034
2057
format = self._bzrdir._format
2035
2058
format.require_stacking(stack_on=stack_on,
2036
possible_transports=possible_transports)
2059
possible_transports=[self._bzrdir.root_transport])
2037
2060
if not self._require_stacking:
2038
2061
# We have picked up automatic stacking somewhere.
2039
note(gettext('Using default stacking branch {0} at {1}').format(
2040
self._stack_on, self._stack_on_pwd))
2062
note('Using default stacking branch %s at %s', self._stack_on,
2041
2064
repository = self._bzrdir.create_repository(shared=shared)
2042
2065
self._add_fallback(repository,
2043
possible_transports=possible_transports)
2066
possible_transports=[self._bzrdir.transport])
2044
2067
if make_working_trees is not None:
2045
2068
repository.set_make_working_trees(make_working_trees)
2046
2069
return repository, True
2133
2148
deprecated=True)
2134
2149
register_metadir(controldir.format_registry, 'dirstate',
2135
2150
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2136
help='Format using dirstate for working trees. '
2137
'Compatible with bzr 0.8 and '
2138
'above when accessed over the network. Introduced in bzr 0.15.',
2151
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2152
'above when accessed over the network.',
2139
2153
branch_format='bzrlib.branch.BzrBranchFormat5',
2140
2154
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2142
2156
deprecated=True)
2143
2157
register_metadir(controldir.format_registry, 'dirstate-tags',
2144
2158
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2145
help='Variant of dirstate with support for tags. '
2146
'Introduced in bzr 0.15.',
2159
help='New in 0.15: Fast local operations and improved scaling for '
2160
'network operations. Additionally adds support for tags.'
2161
' Incompatible with bzr < 0.15.',
2147
2162
branch_format='bzrlib.branch.BzrBranchFormat6',
2148
2163
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2150
2165
deprecated=True)
2151
2166
register_metadir(controldir.format_registry, 'rich-root',
2152
2167
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
2153
help='Variant of dirstate with better handling of tree roots. '
2154
'Introduced in bzr 1.0',
2168
help='New in 1.0. Better handling of tree roots. Incompatible with'
2155
2170
branch_format='bzrlib.branch.BzrBranchFormat6',
2156
2171
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2158
2173
deprecated=True)
2159
2174
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
2160
2175
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2161
help='Variant of dirstate with support for nested trees. '
2162
'Introduced in 0.15.',
2176
help='New in 0.15: Fast local operations and improved scaling for '
2177
'network operations. Additionally adds support for versioning nested '
2178
'bzr branches. Incompatible with bzr < 0.15.',
2163
2179
branch_format='bzrlib.branch.BzrBranchFormat6',
2164
2180
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2165
2181
experimental=True,
2168
2184
register_metadir(controldir.format_registry, 'pack-0.92',
2169
2185
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack1',
2170
help='Pack-based format used in 1.x series. Introduced in 0.92. '
2171
'Interoperates with bzr repositories before 0.92 but cannot be '
2172
'read by bzr < 0.92. '
2186
help='New in 0.92: Pack-based format with data compatible with '
2187
'dirstate-tags format repositories. Interoperates with '
2188
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2174
2190
branch_format='bzrlib.branch.BzrBranchFormat6',
2175
2191
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2178
2193
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
2179
2194
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack3',
2180
help='Pack-based format used in 1.x series, with subtree support. '
2181
'Introduced in 0.92. Interoperates with '
2195
help='New in 0.92: Pack-based format with data compatible with '
2196
'dirstate-with-subtree format repositories. Interoperates with '
2182
2197
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2184
2199
branch_format='bzrlib.branch.BzrBranchFormat6',
2185
2200
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2188
2202
experimental=True,
2190
2204
register_metadir(controldir.format_registry, 'rich-root-pack',
2191
2205
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack4',
2192
help='A variant of pack-0.92 that supports rich-root data '
2193
'(needed for bzr-svn and bzr-git). Introduced in 1.0.',
2206
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
2207
'(needed for bzr-svn and bzr-git).',
2194
2208
branch_format='bzrlib.branch.BzrBranchFormat6',
2195
2209
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2199
2212
register_metadir(controldir.format_registry, '1.6',
2200
2213
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
2286
register_metadir(controldir.format_registry, 'development-colo',
2287
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2288
help='The 2a format with experimental support for colocated branches.\n',
2289
branch_format='bzrlib.branch.BzrBranchFormat7',
2290
tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
2292
bzrdir_format=BzrDirMetaFormat1Colo,
2296
2291
# And the development formats above will have aliased one of the following:
2298
2293
# Finally, the current format.
2299
2294
register_metadir(controldir.format_registry, '2a',
2300
2295
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2301
help='Format for the bzr 2.0 series.\n'
2296
help='First format for bzr 2.0 series.\n'
2302
2297
'Uses group-compress storage.\n'
2303
2298
'Provides rich roots which are a one-way transition.\n',
2304
2299
# 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '