232
236
t = _mod_transport.get_transport(url)
236
def find_bzrdirs(transport, evaluate=None, list_current=None):
237
"""Find bzrdirs recursively from current location.
239
This is intended primarily as a building block for more sophisticated
240
functionality, like finding trees under a directory, or finding
241
branches that use a given repository.
242
:param evaluate: An optional callable that yields recurse, value,
243
where recurse controls whether this bzrdir is recursed into
244
and value is the value to yield. By default, all bzrdirs
245
are recursed into, and the return value is the bzrdir.
246
:param list_current: if supplied, use this function to list the current
247
directory, instead of Transport.list_dir
248
:return: a generator of found bzrdirs, or whatever evaluate returns.
250
if list_current is None:
251
def list_current(transport):
252
return transport.list_dir('')
254
def evaluate(bzrdir):
257
pending = [transport]
258
while len(pending) > 0:
259
current_transport = pending.pop()
262
bzrdir = BzrDir.open_from_transport(current_transport)
263
except (errors.NotBranchError, errors.PermissionDenied):
266
recurse, value = evaluate(bzrdir)
269
subdirs = list_current(current_transport)
270
except (errors.NoSuchFile, errors.PermissionDenied):
273
for subdir in sorted(subdirs, reverse=True):
274
pending.append(current_transport.clone(subdir))
277
def find_branches(transport):
278
"""Find all branches under a transport.
280
This will find all branches below the transport, including branches
281
inside other branches. Where possible, it will use
282
Repository.find_branches.
284
To list all the branches that use a particular Repository, see
285
Repository.find_branches
287
def evaluate(bzrdir):
289
repository = bzrdir.open_repository()
290
except errors.NoRepositoryPresent:
293
return False, ([], repository)
294
return True, (bzrdir.list_branches(), None)
296
for branches, repo in BzrDir.find_bzrdirs(transport,
299
ret.extend(repo.find_branches())
300
if branches is not None:
305
def create_branch_and_repo(base, force_new_repo=False, format=None):
306
"""Create a new BzrDir, Branch and Repository at the url 'base'.
308
This will use the current default BzrDirFormat unless one is
309
specified, and use whatever
310
repository format that that uses via bzrdir.create_branch and
311
create_repository. If a shared repository is available that is used
314
The created Branch object is returned.
316
:param base: The URL to create the branch at.
317
:param force_new_repo: If True a new repository is always created.
318
:param format: If supplied, the format of branch to create. If not
319
supplied, the default is used.
321
bzrdir = BzrDir.create(base, format)
322
bzrdir._find_or_create_repository(force_new_repo)
323
return bzrdir.create_branch()
325
239
def determine_repository_policy(self, force_new_repo=False, stack_on=None,
326
240
stack_on_pwd=None, require_stacking=False):
327
241
"""Return an object representing a policy to use.
547
def create_branch_convenience(base, force_new_repo=False,
548
force_new_tree=None, format=None,
549
possible_transports=None):
550
"""Create a new BzrDir, Branch and Repository at the url 'base'.
552
This is a convenience function - it will use an existing repository
553
if possible, can be told explicitly whether to create a working tree or
556
This will use the current default BzrDirFormat unless one is
557
specified, and use whatever
558
repository format that that uses via bzrdir.create_branch and
559
create_repository. If a shared repository is available that is used
560
preferentially. Whatever repository is used, its tree creation policy
563
The created Branch object is returned.
564
If a working tree cannot be made due to base not being a file:// url,
565
no error is raised unless force_new_tree is True, in which case no
566
data is created on disk and NotLocalUrl is raised.
568
:param base: The URL to create the branch at.
569
:param force_new_repo: If True a new repository is always created.
570
:param force_new_tree: If True or False force creation of a tree or
571
prevent such creation respectively.
572
:param format: Override for the bzrdir format to create.
573
:param possible_transports: An optional reusable transports list.
576
# check for non local urls
577
t = _mod_transport.get_transport(base, possible_transports)
578
if not isinstance(t, local.LocalTransport):
579
raise errors.NotLocalUrl(base)
580
bzrdir = BzrDir.create(base, format, possible_transports)
581
repo = bzrdir._find_or_create_repository(force_new_repo)
582
result = bzrdir.create_branch()
583
if force_new_tree or (repo.make_working_trees() and
584
force_new_tree is None):
586
bzrdir.create_workingtree()
587
except errors.NotLocalUrl:
592
def create_standalone_workingtree(base, format=None):
593
"""Create a new BzrDir, WorkingTree, Branch and Repository at 'base'.
595
'base' must be a local path or a file:// url.
597
This will use the current default BzrDirFormat unless one is
598
specified, and use whatever
599
repository format that that uses for bzrdirformat.create_workingtree,
600
create_branch and create_repository.
602
:param format: Override for the bzrdir format to create.
603
:return: The WorkingTree object.
605
t = _mod_transport.get_transport(base)
606
if not isinstance(t, local.LocalTransport):
607
raise errors.NotLocalUrl(base)
608
bzrdir = BzrDir.create_branch_and_repo(base,
610
format=format).bzrdir
611
return bzrdir.create_workingtree()
613
@deprecated_method(deprecated_in((2, 3, 0)))
614
def generate_backup_name(self, base):
615
return self._available_backup_name(base)
617
469
def _available_backup_name(self, base):
618
470
"""Find a non-existing backup file name based on base.
811
664
# add new tests for it to the appropriate place.
812
665
return filename == '.bzr' or filename.startswith('.bzr/')
815
def open_unsupported(base):
816
"""Open a branch which is not supported."""
817
return BzrDir.open(base, _unsupported=True)
820
def open(base, _unsupported=False, possible_transports=None):
821
"""Open an existing bzrdir, rooted at 'base' (url).
823
:param _unsupported: a private parameter to the BzrDir class.
825
t = _mod_transport.get_transport(base, possible_transports)
826
return BzrDir.open_from_transport(t, _unsupported=_unsupported)
829
def open_from_transport(transport, _unsupported=False,
830
_server_formats=True):
831
"""Open a bzrdir within a particular directory.
833
:param transport: Transport containing the bzrdir.
834
:param _unsupported: private.
836
for hook in BzrDir.hooks['pre_open']:
838
# Keep initial base since 'transport' may be modified while following
840
base = transport.base
841
def find_format(transport):
842
return transport, controldir.ControlDirFormat.find_format(
843
transport, _server_formats=_server_formats)
845
def redirected(transport, e, redirection_notice):
846
redirected_transport = transport._redirected_to(e.source, e.target)
847
if redirected_transport is None:
848
raise errors.NotBranchError(base)
849
note('%s is%s redirected to %s',
850
transport.base, e.permanently, redirected_transport.base)
851
return redirected_transport
854
transport, format = do_catching_redirections(find_format,
857
except errors.TooManyRedirections:
858
raise errors.NotBranchError(base)
860
format.check_support_status(_unsupported)
861
return format.open(transport, _found=True)
864
def open_containing(url, possible_transports=None):
865
"""Open an existing branch which contains url.
867
:param url: url to search from.
868
See open_containing_from_transport for more detail.
870
transport = _mod_transport.get_transport(url, possible_transports)
871
return BzrDir.open_containing_from_transport(transport)
874
def open_containing_from_transport(a_transport):
875
"""Open an existing branch which contains a_transport.base.
877
This probes for a branch at a_transport, and searches upwards from there.
879
Basically we keep looking up until we find the control directory or
880
run into the root. If there isn't one, raises NotBranchError.
881
If there is one and it is either an unrecognised format or an unsupported
882
format, UnknownFormatError or UnsupportedFormatError are raised.
883
If there is one, it is returned, along with the unused portion of url.
885
:return: The BzrDir that contains the path, and a Unicode path
886
for the rest of the URL.
888
# this gets the normalised url back. I.e. '.' -> the full path.
889
url = a_transport.base
892
result = BzrDir.open_from_transport(a_transport)
893
return result, urlutils.unescape(a_transport.relpath(url))
894
except errors.NotBranchError, e:
897
new_t = a_transport.clone('..')
898
except errors.InvalidURLJoin:
899
# reached the root, whatever that may be
900
raise errors.NotBranchError(path=url)
901
if new_t.base == a_transport.base:
902
# reached the root, whatever that may be
903
raise errors.NotBranchError(path=url)
907
def open_tree_or_branch(klass, location):
908
"""Return the branch and working tree at a location.
910
If there is no tree at the location, tree will be None.
911
If there is no branch at the location, an exception will be
913
:return: (tree, branch)
915
bzrdir = klass.open(location)
916
return bzrdir._get_tree_branch()
919
def open_containing_tree_or_branch(klass, location):
920
"""Return the branch and working tree contained by a location.
922
Returns (tree, branch, relpath).
923
If there is no tree at containing the location, tree will be None.
924
If there is no branch containing the location, an exception will be
926
relpath is the portion of the path that is contained by the branch.
928
bzrdir, relpath = klass.open_containing(location)
929
tree, branch = bzrdir._get_tree_branch()
930
return tree, branch, relpath
933
def open_containing_tree_branch_or_repository(klass, location):
934
"""Return the working tree, branch and repo contained by a location.
936
Returns (tree, branch, repository, relpath).
937
If there is no tree containing the location, tree will be None.
938
If there is no branch containing the location, branch will be None.
939
If there is no repository containing the location, repository will be
941
relpath is the portion of the path that is contained by the innermost
944
If no tree, branch or repository is found, a NotBranchError is raised.
946
bzrdir, relpath = klass.open_containing(location)
948
tree, branch = bzrdir._get_tree_branch()
949
except errors.NotBranchError:
951
repo = bzrdir.find_repository()
952
return None, None, repo, relpath
953
except (errors.NoRepositoryPresent):
954
raise errors.NotBranchError(location)
955
return tree, branch, branch.repository, relpath
957
667
def _cloning_metadir(self):
958
668
"""Produce a metadir suitable for cloning with.
1075
767
raise NotImplementedError(self.get_workingtree_transport)
1078
class BzrDirHooks(hooks.Hooks):
1079
"""Hooks for BzrDir operations."""
1082
"""Create the default hooks."""
1083
hooks.Hooks.__init__(self, "bzrlib.bzrdir", "BzrDir.hooks")
1084
self.add_hook('pre_open',
1085
"Invoked before attempting to open a BzrDir with the transport "
1086
"that the open will use.", (1, 14))
1087
self.add_hook('post_repo_init',
1088
"Invoked after a repository has been initialized. "
1089
"post_repo_init is called with a "
1090
"bzrlib.bzrdir.RepoInitHookParams.",
1093
# install the default hooks
1094
BzrDir.hooks = BzrDirHooks()
1097
class RepoInitHookParams(object):
1098
"""Object holding parameters passed to *_repo_init hooks.
1100
There are 4 fields that hooks may wish to access:
1102
:ivar repository: Repository created
1103
:ivar format: Repository format
1104
:ivar bzrdir: The bzrdir for the repository
1105
:ivar shared: The repository is shared
1108
def __init__(self, repository, format, a_bzrdir, shared):
1109
"""Create a group of RepoInitHook parameters.
1111
:param repository: Repository created
1112
:param format: Repository format
1113
:param bzrdir: The bzrdir for the repository
1114
:param shared: The repository is shared
770
def create(cls, base, format=None, possible_transports=None):
771
"""Create a new BzrDir at the url 'base'.
773
:param format: If supplied, the format of branch to create. If not
774
supplied, the default is used.
775
:param possible_transports: If supplied, a list of transports that
776
can be reused to share a remote connection.
1116
self.repository = repository
1117
self.format = format
1118
self.bzrdir = a_bzrdir
1119
self.shared = shared
1121
def __eq__(self, other):
1122
return self.__dict__ == other.__dict__
778
if cls is not BzrDir:
779
raise AssertionError("BzrDir.create always creates the "
780
"default format, not one of %r" % cls)
781
return controldir.ControlDir.create(base, format=format,
782
possible_transports=possible_transports)
1124
784
def __repr__(self):
1126
return "<%s for %s>" % (self.__class__.__name__,
1129
return "<%s for %s>" % (self.__class__.__name__,
785
return "<%s at %r>" % (self.__class__.__name__, self.user_url)
787
def update_feature_flags(self, updated_flags):
788
"""Update the features required by this bzrdir.
790
:param updated_flags: Dictionary mapping feature names to necessities
791
A necessity can be None to indicate the feature should be removed
793
self.control_files.lock_write()
795
self._format._update_feature_flags(updated_flags)
796
self.transport.put_bytes('branch-format', self._format.as_string())
798
self.control_files.unlock()
1133
801
class BzrDirMeta1(BzrDir):
1139
807
present within a BzrDir.
810
def _get_branch_path(self, name):
811
"""Obtain the branch path to use.
813
This uses the API specified branch name first, and then falls back to
814
the branch name specified in the URL. If neither of those is specified,
815
it uses the default branch.
817
:param name: Optional branch name to use
818
:return: Relative path to branch
822
return urlutils.join('branches', name.encode("utf-8"))
824
def _read_branch_list(self):
825
"""Read the branch list.
827
:return: List of utf-8 encoded branch names.
830
f = self.control_transport.get('branch-list')
831
except errors.NoSuchFile:
837
ret.append(name.rstrip("\n"))
842
def _write_branch_list(self, branches):
843
"""Write out the branch list.
845
:param branches: List of utf-8 branch names to write
847
self.transport.put_bytes('branch-list',
848
"".join([name+"\n" for name in branches]))
850
def __init__(self, _transport, _format):
851
super(BzrDirMeta1, self).__init__(_transport, _format)
852
self.control_files = lockable_files.LockableFiles(
853
self.control_transport, self._format._lock_file_name,
854
self._format._lock_class)
1142
856
def can_convert_format(self):
1143
857
"""See BzrDir.can_convert_format()."""
1146
def create_branch(self, name=None, repository=None):
1147
"""See BzrDir.create_branch."""
860
def create_branch(self, name=None, repository=None,
861
append_revisions_only=None):
862
"""See ControlDir.create_branch."""
864
name = self._get_selected_branch()
1148
865
return self._format.get_branch_format().initialize(self, name=name,
1149
repository=repository)
866
repository=repository,
867
append_revisions_only=append_revisions_only)
1151
869
def destroy_branch(self, name=None):
1152
"""See BzrDir.create_branch."""
1153
if name is not None:
1154
raise errors.NoColocatedBranchSupport(self)
1155
self.transport.delete_tree('branch')
870
"""See ControlDir.destroy_branch."""
872
name = self._get_selected_branch()
873
path = self._get_branch_path(name)
875
self.control_files.lock_write()
877
branches = self._read_branch_list()
879
branches.remove(name.encode("utf-8"))
881
raise errors.NotBranchError(name)
882
self._write_branch_list(branches)
884
self.control_files.unlock()
886
self.transport.delete_tree(path)
887
except errors.NoSuchFile:
888
raise errors.NotBranchError(path=urlutils.join(self.transport.base,
1157
891
def create_repository(self, shared=False):
1158
892
"""See BzrDir.create_repository."""
1200
937
def get_branch_reference(self, name=None):
1201
938
"""See BzrDir.get_branch_reference()."""
1202
from bzrlib.branch import BranchFormat
1203
format = BranchFormat.find_format(self, name=name)
939
from bzrlib.branch import BranchFormatMetadir
940
format = BranchFormatMetadir.find_format(self, name=name)
1204
941
return format.get_reference(self, name=name)
943
def set_branch_reference(self, target_branch, name=None):
944
format = _mod_branch.BranchReferenceFormat()
945
return format.initialize(self, target_branch=target_branch, name=name)
1206
947
def get_branch_transport(self, branch_format, name=None):
1207
948
"""See BzrDir.get_branch_transport()."""
1208
if name is not None:
1209
raise errors.NoColocatedBranchSupport(self)
950
name = self._get_selected_branch()
951
path = self._get_branch_path(name)
1210
952
# XXX: this shouldn't implicitly create the directory if it's just
1211
953
# promising to get a transport -- mbp 20090727
1212
954
if branch_format is None:
1213
return self.transport.clone('branch')
955
return self.transport.clone(path)
1215
957
branch_format.get_format_string()
1216
958
except NotImplementedError:
1217
959
raise errors.IncompatibleFormat(branch_format, self._format)
961
branches = self._read_branch_list()
962
utf8_name = name.encode("utf-8")
963
if not utf8_name in branches:
964
self.control_files.lock_write()
966
branches = self._read_branch_list()
967
dirname = urlutils.dirname(utf8_name)
968
if dirname != "" and dirname in branches:
969
raise errors.ParentBranchExists(name)
971
b.startswith(utf8_name+"/") for b in branches]
972
if any(child_branches):
973
raise errors.AlreadyBranchError(name)
974
branches.append(utf8_name)
975
self._write_branch_list(branches)
977
self.control_files.unlock()
978
branch_transport = self.transport.clone(path)
979
mode = self._get_mkdir_mode()
980
branch_transport.create_prefix(mode=mode)
1219
self.transport.mkdir('branch', mode=self._get_mkdir_mode())
982
self.transport.mkdir(path, mode=mode)
1220
983
except errors.FileExists:
1222
return self.transport.clone('branch')
985
return self.transport.clone(path)
1224
987
def get_repository_transport(self, repository_format):
1225
988
"""See BzrDir.get_repository_transport()."""
1250
1013
return self.transport.clone('checkout')
1015
def get_branches(self):
1016
"""See ControlDir.get_branches."""
1019
ret[""] = self.open_branch(name="")
1020
except (errors.NotBranchError, errors.NoRepositoryPresent):
1023
for name in self._read_branch_list():
1024
ret[name] = self.open_branch(name=name.decode('utf-8'))
1252
1028
def has_workingtree(self):
1253
1029
"""Tell if this bzrdir contains a working tree.
1255
This will still raise an exception if the bzrdir has a workingtree that
1256
is remote & inaccessible.
1258
1031
Note: if you're going to open the working tree, you should just go
1259
1032
ahead and try, and not ask permission first.
1261
from bzrlib.workingtree import WorkingTreeFormat
1034
from bzrlib.workingtree import WorkingTreeFormatMetaDir
1263
WorkingTreeFormat.find_format(self)
1036
WorkingTreeFormatMetaDir.find_format_string(self)
1264
1037
except errors.NoWorkingTree:
1268
1041
def needs_format_conversion(self, format):
1269
1042
"""See BzrDir.needs_format_conversion()."""
1270
if not isinstance(self._format, format.__class__):
1043
if (not isinstance(self._format, format.__class__) or
1044
self._format.get_format_string() != format.get_format_string()):
1271
1045
# it is not a meta dir format, conversion is needed.
1273
1047
# we might want to push this down to the repository?
1296
1070
def open_branch(self, name=None, unsupported=False,
1297
ignore_fallbacks=False):
1298
"""See BzrDir.open_branch."""
1071
ignore_fallbacks=False, possible_transports=None):
1072
"""See ControlDir.open_branch."""
1074
name = self._get_selected_branch()
1299
1075
format = self.find_branch_format(name=name)
1300
1076
format.check_support_status(unsupported)
1301
1077
return format.open(self, name=name,
1302
_found=True, ignore_fallbacks=ignore_fallbacks)
1078
_found=True, ignore_fallbacks=ignore_fallbacks,
1079
possible_transports=possible_transports)
1304
1081
def open_repository(self, unsupported=False):
1305
1082
"""See BzrDir.open_repository."""
1306
from bzrlib.repository import RepositoryFormat
1307
format = RepositoryFormat.find_format(self)
1083
from bzrlib.repository import RepositoryFormatMetaDir
1084
format = RepositoryFormatMetaDir.find_format(self)
1308
1085
format.check_support_status(unsupported)
1309
1086
return format.open(self, _found=True)
1311
1088
def open_workingtree(self, unsupported=False,
1312
1089
recommend_upgrade=True):
1313
1090
"""See BzrDir.open_workingtree."""
1314
from bzrlib.workingtree import WorkingTreeFormat
1315
format = WorkingTreeFormat.find_format(self)
1091
from bzrlib.workingtree import WorkingTreeFormatMetaDir
1092
format = WorkingTreeFormatMetaDir.find_format(self)
1316
1093
format.check_support_status(unsupported, recommend_upgrade,
1317
1094
basedir=self.root_transport.base)
1318
1095
return format.open(self, _found=True)
1321
1098
return config.TransportConfig(self.transport, 'control.conf')
1101
class BzrFormat(object):
1102
"""Base class for all formats of things living in metadirs.
1104
This class manages the format string that is stored in the 'format'
1105
or 'branch-format' file.
1107
All classes for (branch-, repository-, workingtree-) formats that
1108
live in meta directories and have their own 'format' file
1109
(i.e. different from .bzr/branch-format) derive from this class,
1110
as well as the relevant base class for their kind
1111
(BranchFormat, WorkingTreeFormat, RepositoryFormat).
1113
Each format is identified by a "format" or "branch-format" file with a
1114
single line containing the base format name and then an optional list of
1117
Feature flags are supported as of bzr 2.5. Setting feature flags on formats
1118
will render them inaccessible to older versions of bzr.
1120
:ivar features: Dictionary mapping feature names to their necessity
1123
_present_features = set()
1129
def register_feature(cls, name):
1130
"""Register a feature as being present.
1132
:param name: Name of the feature
1135
raise ValueError("spaces are not allowed in feature names")
1136
if name in cls._present_features:
1137
raise errors.FeatureAlreadyRegistered(name)
1138
cls._present_features.add(name)
1141
def unregister_feature(cls, name):
1142
"""Unregister a feature."""
1143
cls._present_features.remove(name)
1145
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1147
for name, necessity in self.features.iteritems():
1148
if name in self._present_features:
1150
if necessity == "optional":
1151
mutter("ignoring optional missing feature %s", name)
1153
elif necessity == "required":
1154
raise errors.MissingFeature(name)
1156
mutter("treating unknown necessity as require for %s",
1158
raise errors.MissingFeature(name)
1161
def get_format_string(cls):
1162
"""Return the ASCII format string that identifies this format."""
1163
raise NotImplementedError(cls.get_format_string)
1166
def from_string(cls, text):
1167
format_string = cls.get_format_string()
1168
if not text.startswith(format_string):
1169
raise AssertionError("Invalid format header %r for %r" % (text, cls))
1170
lines = text[len(format_string):].splitlines()
1172
for lineno, line in enumerate(lines):
1174
(necessity, feature) = line.split(" ", 1)
1176
raise errors.ParseFormatError(format=cls, lineno=lineno+2,
1177
line=line, text=text)
1178
ret.features[feature] = necessity
1181
def as_string(self):
1182
"""Return the string representation of this format.
1184
lines = [self.get_format_string()]
1185
lines.extend([("%s %s\n" % (item[1], item[0])) for item in
1186
self.features.iteritems()])
1187
return "".join(lines)
1190
def _find_format(klass, registry, kind, format_string):
1192
first_line = format_string[:format_string.index("\n")+1]
1194
first_line = format_string
1196
cls = registry.get(first_line)
1198
raise errors.UnknownFormatError(format=first_line, kind=kind)
1199
return cls.from_string(format_string)
1201
def network_name(self):
1202
"""A simple byte string uniquely identifying this format for RPC calls.
1204
Metadir branch formats use their format string.
1206
return self.as_string()
1208
def __eq__(self, other):
1209
return (self.__class__ is other.__class__ and
1210
self.features == other.features)
1212
def _update_feature_flags(self, updated_flags):
1213
"""Update the feature flags in this format.
1215
:param updated_flags: Updated feature flags
1217
for name, necessity in updated_flags.iteritems():
1218
if necessity is None:
1220
del self.features[name]
1224
self.features[name] = necessity
1324
1227
class BzrProber(controldir.Prober):
1325
1228
"""Prober for formats that use a .bzr/ control directory."""
1827
1750
controldir.ControlDirFormat._default_format = BzrDirMetaFormat1()
1753
class BzrDirMetaFormat1Colo(BzrDirMetaFormat1):
1754
"""BzrDirMeta1 format with support for colocated branches."""
1756
colocated_branches = True
1759
def get_format_string(cls):
1760
"""See BzrDirFormat.get_format_string()."""
1761
return "Bazaar meta directory, format 1 (with colocated branches)\n"
1763
def get_format_description(self):
1764
"""See BzrDirFormat.get_format_description()."""
1765
return "Meta directory format 1 with support for colocated branches"
1767
def _open(self, transport):
1768
"""See BzrDirFormat._open."""
1769
# Create a new format instance because otherwise initialisation of new
1770
# metadirs share the global default format object leading to alias
1772
format = BzrDirMetaFormat1Colo()
1773
self._supply_sub_formats_to(format)
1774
return BzrDirMeta1(transport, format)
1777
BzrProber.formats.register(BzrDirMetaFormat1Colo.get_format_string(),
1778
BzrDirMetaFormat1Colo)
1830
1781
class ConvertMetaToMeta(controldir.Converter):
1831
1782
"""Converts the components of metadirs."""
1905
1856
return to_convert
1859
class ConvertMetaToColo(controldir.Converter):
1860
"""Add colocated branch support."""
1862
def __init__(self, target_format):
1863
"""Create a converter.that upgrades a metadir to the colo format.
1865
:param target_format: The final metadir format that is desired.
1867
self.target_format = target_format
1869
def convert(self, to_convert, pb):
1870
"""See Converter.convert()."""
1871
to_convert.transport.put_bytes('branch-format',
1872
self.target_format.as_string())
1873
return BzrDir.open_from_transport(to_convert.root_transport)
1876
class ConvertMetaToColo(controldir.Converter):
1877
"""Convert a 'development-colo' bzrdir to a '2a' bzrdir."""
1879
def __init__(self, target_format):
1880
"""Create a converter that converts a 'development-colo' metadir
1883
:param target_format: The final metadir format that is desired.
1885
self.target_format = target_format
1887
def convert(self, to_convert, pb):
1888
"""See Converter.convert()."""
1889
to_convert.transport.put_bytes('branch-format',
1890
self.target_format.as_string())
1891
return BzrDir.open_from_transport(to_convert.root_transport)
1908
1894
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
2017
2005
require_stacking)
2018
2006
self._bzrdir = bzrdir
2020
def acquire_repository(self, make_working_trees=None, shared=False):
2008
def acquire_repository(self, make_working_trees=None, shared=False,
2009
possible_transports=None):
2021
2010
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2023
2012
Creates the desired repository in the bzrdir we already have.
2014
if possible_transports is None:
2015
possible_transports = []
2017
possible_transports = list(possible_transports)
2018
possible_transports.append(self._bzrdir.root_transport)
2025
2019
stack_on = self._get_full_stack_on()
2027
2021
format = self._bzrdir._format
2028
2022
format.require_stacking(stack_on=stack_on,
2029
possible_transports=[self._bzrdir.root_transport])
2023
possible_transports=possible_transports)
2030
2024
if not self._require_stacking:
2031
2025
# We have picked up automatic stacking somewhere.
2032
note('Using default stacking branch %s at %s', self._stack_on,
2026
note(gettext('Using default stacking branch {0} at {1}').format(
2027
self._stack_on, self._stack_on_pwd))
2034
2028
repository = self._bzrdir.create_repository(shared=shared)
2035
2029
self._add_fallback(repository,
2036
possible_transports=[self._bzrdir.transport])
2030
possible_transports=possible_transports)
2037
2031
if make_working_trees is not None:
2038
2032
repository.set_make_working_trees(make_working_trees)
2039
2033
return repository, True
2112
2114
register_metadir(controldir.format_registry, 'knit',
2113
2115
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2114
2116
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2115
branch_format='bzrlib.branch.BzrBranchFormat5',
2116
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2117
branch_format='bzrlib.branchfmt.fullhistory.BzrBranchFormat5',
2118
tree_format='bzrlib.workingtree_3.WorkingTreeFormat3',
2118
2120
deprecated=True)
2119
2121
register_metadir(controldir.format_registry, 'dirstate',
2120
2122
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2121
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2122
'above when accessed over the network.',
2123
branch_format='bzrlib.branch.BzrBranchFormat5',
2124
# this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
2125
# directly from workingtree_4 triggers a circular import.
2126
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2123
help='Format using dirstate for working trees. '
2124
'Compatible with bzr 0.8 and '
2125
'above when accessed over the network. Introduced in bzr 0.15.',
2126
branch_format='bzrlib.branchfmt.fullhistory.BzrBranchFormat5',
2127
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2128
2129
deprecated=True)
2129
2130
register_metadir(controldir.format_registry, 'dirstate-tags',
2130
2131
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2131
help='New in 0.15: Fast local operations and improved scaling for '
2132
'network operations. Additionally adds support for tags.'
2133
' Incompatible with bzr < 0.15.',
2132
help='Variant of dirstate with support for tags. '
2133
'Introduced in bzr 0.15.',
2134
2134
branch_format='bzrlib.branch.BzrBranchFormat6',
2135
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2135
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2137
2137
deprecated=True)
2138
2138
register_metadir(controldir.format_registry, 'rich-root',
2139
2139
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
2140
help='New in 1.0. Better handling of tree roots. Incompatible with'
2140
help='Variant of dirstate with better handling of tree roots. '
2141
'Introduced in bzr 1.0',
2142
2142
branch_format='bzrlib.branch.BzrBranchFormat6',
2143
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2143
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2145
2145
deprecated=True)
2146
2146
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
2147
2147
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2148
help='New in 0.15: Fast local operations and improved scaling for '
2149
'network operations. Additionally adds support for versioning nested '
2150
'bzr branches. Incompatible with bzr < 0.15.',
2148
help='Variant of dirstate with support for nested trees. '
2149
'Introduced in 0.15.',
2151
2150
branch_format='bzrlib.branch.BzrBranchFormat6',
2152
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2151
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2153
2152
experimental=True,
2156
2155
register_metadir(controldir.format_registry, 'pack-0.92',
2157
2156
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack1',
2158
help='New in 0.92: Pack-based format with data compatible with '
2159
'dirstate-tags format repositories. Interoperates with '
2160
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2157
help='Pack-based format used in 1.x series. Introduced in 0.92. '
2158
'Interoperates with bzr repositories before 0.92 but cannot be '
2159
'read by bzr < 0.92. '
2162
2161
branch_format='bzrlib.branch.BzrBranchFormat6',
2163
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2162
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2165
2165
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
2166
2166
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack3',
2167
help='New in 0.92: Pack-based format with data compatible with '
2168
'dirstate-with-subtree format repositories. Interoperates with '
2167
help='Pack-based format used in 1.x series, with subtree support. '
2168
'Introduced in 0.92. Interoperates with '
2169
2169
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2171
2171
branch_format='bzrlib.branch.BzrBranchFormat6',
2172
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2172
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2174
2175
experimental=True,
2176
2177
register_metadir(controldir.format_registry, 'rich-root-pack',
2177
2178
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack4',
2178
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
2179
'(needed for bzr-svn and bzr-git).',
2179
help='A variant of pack-0.92 that supports rich-root data '
2180
'(needed for bzr-svn and bzr-git). Introduced in 1.0.',
2180
2181
branch_format='bzrlib.branch.BzrBranchFormat6',
2181
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2182
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2184
2186
register_metadir(controldir.format_registry, '1.6',
2185
2187
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
2204
2208
'are smaller in size, have smarter caching and provide faster '
2205
2209
'performance for most operations.',
2206
2210
branch_format='bzrlib.branch.BzrBranchFormat7',
2207
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2211
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2210
2215
register_metadir(controldir.format_registry, '1.9-rich-root',
2211
2216
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
2212
2217
help='A variant of 1.9 that supports rich-root data '
2213
2218
'(needed for bzr-svn and bzr-git).',
2214
2219
branch_format='bzrlib.branch.BzrBranchFormat7',
2215
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2220
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2218
2224
register_metadir(controldir.format_registry, '1.14',
2219
2225
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
2220
2226
help='A working-tree format that supports content filtering.',
2221
2227
branch_format='bzrlib.branch.BzrBranchFormat7',
2222
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
2228
tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
2224
2232
register_metadir(controldir.format_registry, '1.14-rich-root',
2225
2233
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
2226
2234
help='A variant of 1.14 that supports rich-root data '
2227
2235
'(needed for bzr-svn and bzr-git).',
2228
2236
branch_format='bzrlib.branch.BzrBranchFormat7',
2229
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
2237
tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
2231
2241
# The following un-numbered 'development' formats should always just be aliases.
2232
2242
register_metadir(controldir.format_registry, 'development-subtree',
2254
2264
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
2256
2266
branch_format='bzrlib.branch.BzrBranchFormat7',
2257
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
2267
tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
2258
2268
experimental=True,
2273
register_metadir(controldir.format_registry, 'development-colo',
2274
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2275
help='The 2a format with experimental support for colocated branches.\n',
2276
branch_format='bzrlib.branch.BzrBranchFormat7',
2277
tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
2279
bzrdir_format=BzrDirMetaFormat1Colo,
2263
2283
# And the development formats above will have aliased one of the following:
2265
2285
# Finally, the current format.
2266
2286
register_metadir(controldir.format_registry, '2a',
2267
2287
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2268
help='First format for bzr 2.0 series.\n'
2288
help='Format for the bzr 2.0 series.\n'
2269
2289
'Uses group-compress storage.\n'
2270
2290
'Provides rich roots which are a one-way transition.\n',
2271
2291
# 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
2272
2292
# 'rich roots. Supported by bzr 1.16 and later.',
2273
2293
branch_format='bzrlib.branch.BzrBranchFormat7',
2274
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
2294
tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
2275
2295
experimental=False,