232
235
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.
243
:param evaluate: An optional callable that yields recurse, value,
244
where recurse controls whether this bzrdir is recursed into
245
and value is the value to yield. By default, all bzrdirs
246
are recursed into, and the return value is the bzrdir.
247
:param list_current: if supplied, use this function to list the current
248
directory, instead of Transport.list_dir
249
:return: a generator of found bzrdirs, or whatever evaluate returns.
251
if list_current is None:
252
def list_current(transport):
253
return transport.list_dir('')
255
def evaluate(bzrdir):
258
pending = [transport]
259
while len(pending) > 0:
260
current_transport = pending.pop()
263
bzrdir = BzrDir.open_from_transport(current_transport)
264
except (errors.NotBranchError, errors.PermissionDenied):
267
recurse, value = evaluate(bzrdir)
270
subdirs = list_current(current_transport)
271
except (errors.NoSuchFile, errors.PermissionDenied):
274
for subdir in sorted(subdirs, reverse=True):
275
pending.append(current_transport.clone(subdir))
278
def find_branches(transport):
279
"""Find all branches under a transport.
281
This will find all branches below the transport, including branches
282
inside other branches. Where possible, it will use
283
Repository.find_branches.
285
To list all the branches that use a particular Repository, see
286
Repository.find_branches
288
def evaluate(bzrdir):
290
repository = bzrdir.open_repository()
291
except errors.NoRepositoryPresent:
294
return False, ([], repository)
295
return True, (bzrdir.list_branches(), None)
297
for branches, repo in BzrDir.find_bzrdirs(transport,
300
ret.extend(repo.find_branches())
301
if branches is not None:
306
def create_branch_and_repo(base, force_new_repo=False, format=None):
307
"""Create a new BzrDir, Branch and Repository at the url 'base'.
309
This will use the current default BzrDirFormat unless one is
310
specified, and use whatever
311
repository format that that uses via bzrdir.create_branch and
312
create_repository. If a shared repository is available that is used
315
The created Branch object is returned.
317
:param base: The URL to create the branch at.
318
:param force_new_repo: If True a new repository is always created.
319
:param format: If supplied, the format of branch to create. If not
320
supplied, the default is used.
322
bzrdir = BzrDir.create(base, format)
323
bzrdir._find_or_create_repository(force_new_repo)
324
return bzrdir.create_branch()
326
238
def determine_repository_policy(self, force_new_repo=False, stack_on=None,
327
239
stack_on_pwd=None, require_stacking=False):
328
240
"""Return an object representing a policy to use.
549
def create_branch_convenience(base, force_new_repo=False,
550
force_new_tree=None, format=None,
551
possible_transports=None):
552
"""Create a new BzrDir, Branch and Repository at the url 'base'.
554
This is a convenience function - it will use an existing repository
555
if possible, can be told explicitly whether to create a working tree or
558
This will use the current default BzrDirFormat unless one is
559
specified, and use whatever
560
repository format that that uses via bzrdir.create_branch and
561
create_repository. If a shared repository is available that is used
562
preferentially. Whatever repository is used, its tree creation policy
565
The created Branch object is returned.
566
If a working tree cannot be made due to base not being a file:// url,
567
no error is raised unless force_new_tree is True, in which case no
568
data is created on disk and NotLocalUrl is raised.
570
:param base: The URL to create the branch at.
571
:param force_new_repo: If True a new repository is always created.
572
:param force_new_tree: If True or False force creation of a tree or
573
prevent such creation respectively.
574
:param format: Override for the bzrdir format to create.
575
:param possible_transports: An optional reusable transports list.
578
# check for non local urls
579
t = _mod_transport.get_transport(base, possible_transports)
580
if not isinstance(t, local.LocalTransport):
581
raise errors.NotLocalUrl(base)
582
bzrdir = BzrDir.create(base, format, possible_transports)
583
repo = bzrdir._find_or_create_repository(force_new_repo)
584
result = bzrdir.create_branch()
585
if force_new_tree or (repo.make_working_trees() and
586
force_new_tree is None):
588
bzrdir.create_workingtree()
589
except errors.NotLocalUrl:
594
def create_standalone_workingtree(base, format=None):
595
"""Create a new BzrDir, WorkingTree, Branch and Repository at 'base'.
597
'base' must be a local path or a file:// url.
599
This will use the current default BzrDirFormat unless one is
600
specified, and use whatever
601
repository format that that uses for bzrdirformat.create_workingtree,
602
create_branch and create_repository.
604
:param format: Override for the bzrdir format to create.
605
:return: The WorkingTree object.
607
t = _mod_transport.get_transport(base)
608
if not isinstance(t, local.LocalTransport):
609
raise errors.NotLocalUrl(base)
610
bzrdir = BzrDir.create_branch_and_repo(base,
612
format=format).bzrdir
613
return bzrdir.create_workingtree()
615
@deprecated_method(deprecated_in((2, 3, 0)))
616
def generate_backup_name(self, base):
617
return self._available_backup_name(base)
619
468
def _available_backup_name(self, base):
620
469
"""Find a non-existing backup file name based on base.
813
663
# add new tests for it to the appropriate place.
814
664
return filename == '.bzr' or filename.startswith('.bzr/')
817
def open_unsupported(base):
818
"""Open a branch which is not supported."""
819
return BzrDir.open(base, _unsupported=True)
822
def open(base, _unsupported=False, possible_transports=None):
823
"""Open an existing bzrdir, rooted at 'base' (url).
825
:param _unsupported: a private parameter to the BzrDir class.
827
t = _mod_transport.get_transport(base, possible_transports)
828
return BzrDir.open_from_transport(t, _unsupported=_unsupported)
831
def open_from_transport(transport, _unsupported=False,
832
_server_formats=True):
833
"""Open a bzrdir within a particular directory.
835
:param transport: Transport containing the bzrdir.
836
:param _unsupported: private.
838
for hook in BzrDir.hooks['pre_open']:
840
# Keep initial base since 'transport' may be modified while following
842
base = transport.base
843
def find_format(transport):
844
return transport, controldir.ControlDirFormat.find_format(
845
transport, _server_formats=_server_formats)
847
def redirected(transport, e, redirection_notice):
848
redirected_transport = transport._redirected_to(e.source, e.target)
849
if redirected_transport is None:
850
raise errors.NotBranchError(base)
851
note('%s is%s redirected to %s',
852
transport.base, e.permanently, redirected_transport.base)
853
return redirected_transport
856
transport, format = do_catching_redirections(find_format,
859
except errors.TooManyRedirections:
860
raise errors.NotBranchError(base)
862
format.check_support_status(_unsupported)
863
return format.open(transport, _found=True)
866
def open_containing(url, possible_transports=None):
867
"""Open an existing branch which contains url.
869
:param url: url to search from.
871
See open_containing_from_transport for more detail.
873
transport = _mod_transport.get_transport(url, possible_transports)
874
return BzrDir.open_containing_from_transport(transport)
877
def open_containing_from_transport(a_transport):
878
"""Open an existing branch which contains a_transport.base.
880
This probes for a branch at a_transport, and searches upwards from there.
882
Basically we keep looking up until we find the control directory or
883
run into the root. If there isn't one, raises NotBranchError.
884
If there is one and it is either an unrecognised format or an unsupported
885
format, UnknownFormatError or UnsupportedFormatError are raised.
886
If there is one, it is returned, along with the unused portion of url.
888
:return: The BzrDir that contains the path, and a Unicode path
889
for the rest of the URL.
891
# this gets the normalised url back. I.e. '.' -> the full path.
892
url = a_transport.base
895
result = BzrDir.open_from_transport(a_transport)
896
return result, urlutils.unescape(a_transport.relpath(url))
897
except errors.NotBranchError, e:
900
new_t = a_transport.clone('..')
901
except errors.InvalidURLJoin:
902
# reached the root, whatever that may be
903
raise errors.NotBranchError(path=url)
904
if new_t.base == a_transport.base:
905
# reached the root, whatever that may be
906
raise errors.NotBranchError(path=url)
910
def open_tree_or_branch(klass, location):
911
"""Return the branch and working tree at a location.
913
If there is no tree at the location, tree will be None.
914
If there is no branch at the location, an exception will be
916
:return: (tree, branch)
918
bzrdir = klass.open(location)
919
return bzrdir._get_tree_branch()
922
def open_containing_tree_or_branch(klass, location):
923
"""Return the branch and working tree contained by a location.
925
Returns (tree, branch, relpath).
926
If there is no tree at containing the location, tree will be None.
927
If there is no branch containing the location, an exception will be
929
relpath is the portion of the path that is contained by the branch.
931
bzrdir, relpath = klass.open_containing(location)
932
tree, branch = bzrdir._get_tree_branch()
933
return tree, branch, relpath
936
def open_containing_tree_branch_or_repository(klass, location):
937
"""Return the working tree, branch and repo contained by a location.
939
Returns (tree, branch, repository, relpath).
940
If there is no tree containing the location, tree will be None.
941
If there is no branch containing the location, branch will be None.
942
If there is no repository containing the location, repository will be
944
relpath is the portion of the path that is contained by the innermost
947
If no tree, branch or repository is found, a NotBranchError is raised.
949
bzrdir, relpath = klass.open_containing(location)
951
tree, branch = bzrdir._get_tree_branch()
952
except errors.NotBranchError:
954
repo = bzrdir.find_repository()
955
return None, None, repo, relpath
956
except (errors.NoRepositoryPresent):
957
raise errors.NotBranchError(location)
958
return tree, branch, branch.repository, relpath
960
666
def _cloning_metadir(self):
961
667
"""Produce a metadir suitable for cloning with.
1078
766
raise NotImplementedError(self.get_workingtree_transport)
1081
class BzrDirHooks(hooks.Hooks):
1082
"""Hooks for BzrDir operations."""
1085
"""Create the default hooks."""
1086
hooks.Hooks.__init__(self, "bzrlib.bzrdir", "BzrDir.hooks")
1087
self.add_hook('pre_open',
1088
"Invoked before attempting to open a BzrDir with the transport "
1089
"that the open will use.", (1, 14))
1090
self.add_hook('post_repo_init',
1091
"Invoked after a repository has been initialized. "
1092
"post_repo_init is called with a "
1093
"bzrlib.bzrdir.RepoInitHookParams.",
1096
# install the default hooks
1097
BzrDir.hooks = BzrDirHooks()
1100
class RepoInitHookParams(object):
1101
"""Object holding parameters passed to `*_repo_init` hooks.
1103
There are 4 fields that hooks may wish to access:
1105
:ivar repository: Repository created
1106
:ivar format: Repository format
1107
:ivar bzrdir: The bzrdir for the repository
1108
:ivar shared: The repository is shared
1111
def __init__(self, repository, format, a_bzrdir, shared):
1112
"""Create a group of RepoInitHook parameters.
1114
:param repository: Repository created
1115
:param format: Repository format
1116
:param bzrdir: The bzrdir for the repository
1117
:param shared: The repository is shared
769
def create(cls, base, format=None, possible_transports=None):
770
"""Create a new BzrDir at the url 'base'.
772
:param format: If supplied, the format of branch to create. If not
773
supplied, the default is used.
774
:param possible_transports: If supplied, a list of transports that
775
can be reused to share a remote connection.
1119
self.repository = repository
1120
self.format = format
1121
self.bzrdir = a_bzrdir
1122
self.shared = shared
1124
def __eq__(self, other):
1125
return self.__dict__ == other.__dict__
777
if cls is not BzrDir:
778
raise AssertionError("BzrDir.create always creates the "
779
"default format, not one of %r" % cls)
780
return controldir.ControlDir.create(base, format=format,
781
possible_transports=possible_transports)
1127
783
def __repr__(self):
1129
return "<%s for %s>" % (self.__class__.__name__,
1132
return "<%s for %s>" % (self.__class__.__name__,
784
return "<%s at %r>" % (self.__class__.__name__, self.user_url)
786
def update_feature_flags(self, updated_flags):
787
"""Update the features required by this bzrdir.
789
:param updated_flags: Dictionary mapping feature names to necessities
790
A necessity can be None to indicate the feature should be removed
792
self.control_files.lock_write()
794
self._format._update_feature_flags(updated_flags)
795
self.transport.put_bytes('branch-format', self._format.as_string())
797
self.control_files.unlock()
1136
800
class BzrDirMeta1(BzrDir):
1142
806
present within a BzrDir.
809
def _get_branch_path(self, name):
810
"""Obtain the branch path to use.
812
This uses the API specified branch name first, and then falls back to
813
the branch name specified in the URL. If neither of those is specified,
814
it uses the default branch.
816
:param name: Optional branch name to use
817
:return: Relative path to branch
821
return urlutils.join('branches', name.encode("utf-8"))
823
def _read_branch_list(self):
824
"""Read the branch list.
826
:return: List of utf-8 encoded branch names.
829
f = self.control_transport.get('branch-list')
830
except errors.NoSuchFile:
836
ret.append(name.rstrip("\n"))
841
def _write_branch_list(self, branches):
842
"""Write out the branch list.
844
:param branches: List of utf-8 branch names to write
846
self.transport.put_bytes('branch-list',
847
"".join([name+"\n" for name in branches]))
849
def __init__(self, _transport, _format):
850
super(BzrDirMeta1, self).__init__(_transport, _format)
851
self.control_files = lockable_files.LockableFiles(
852
self.control_transport, self._format._lock_file_name,
853
self._format._lock_class)
1145
855
def can_convert_format(self):
1146
856
"""See BzrDir.can_convert_format()."""
1149
def create_branch(self, name=None, repository=None):
1150
"""See BzrDir.create_branch."""
859
def create_branch(self, name=None, repository=None,
860
append_revisions_only=None):
861
"""See ControlDir.create_branch."""
863
name = self._get_selected_branch()
1151
864
return self._format.get_branch_format().initialize(self, name=name,
1152
repository=repository)
865
repository=repository,
866
append_revisions_only=append_revisions_only)
1154
868
def destroy_branch(self, name=None):
1155
"""See BzrDir.create_branch."""
1156
if name is not None:
1157
raise errors.NoColocatedBranchSupport(self)
1158
self.transport.delete_tree('branch')
869
"""See ControlDir.destroy_branch."""
871
name = self._get_selected_branch()
872
path = self._get_branch_path(name)
874
self.control_files.lock_write()
876
branches = self._read_branch_list()
878
branches.remove(name.encode("utf-8"))
880
raise errors.NotBranchError(name)
881
self._write_branch_list(branches)
883
self.control_files.unlock()
885
self.transport.delete_tree(path)
886
except errors.NoSuchFile:
887
raise errors.NotBranchError(path=urlutils.join(self.transport.base,
1160
890
def create_repository(self, shared=False):
1161
891
"""See BzrDir.create_repository."""
1203
936
def get_branch_reference(self, name=None):
1204
937
"""See BzrDir.get_branch_reference()."""
1205
from bzrlib.branch import BranchFormat
1206
format = BranchFormat.find_format(self, name=name)
938
from bzrlib.branch import BranchFormatMetadir
939
format = BranchFormatMetadir.find_format(self, name=name)
1207
940
return format.get_reference(self, name=name)
942
def set_branch_reference(self, target_branch, name=None):
943
format = _mod_branch.BranchReferenceFormat()
944
return format.initialize(self, target_branch=target_branch, name=name)
1209
946
def get_branch_transport(self, branch_format, name=None):
1210
947
"""See BzrDir.get_branch_transport()."""
1211
if name is not None:
1212
raise errors.NoColocatedBranchSupport(self)
949
name = self._get_selected_branch()
950
path = self._get_branch_path(name)
1213
951
# XXX: this shouldn't implicitly create the directory if it's just
1214
952
# promising to get a transport -- mbp 20090727
1215
953
if branch_format is None:
1216
return self.transport.clone('branch')
954
return self.transport.clone(path)
1218
956
branch_format.get_format_string()
1219
957
except NotImplementedError:
1220
958
raise errors.IncompatibleFormat(branch_format, self._format)
960
branches = self._read_branch_list()
961
utf8_name = name.encode("utf-8")
962
if not utf8_name in branches:
963
self.control_files.lock_write()
965
branches = self._read_branch_list()
966
dirname = urlutils.dirname(utf8_name)
967
if dirname != "" and dirname in branches:
968
raise errors.ParentBranchExists(name)
970
b.startswith(utf8_name+"/") for b in branches]
971
if any(child_branches):
972
raise errors.AlreadyBranchError(name)
973
branches.append(utf8_name)
974
self._write_branch_list(branches)
976
self.control_files.unlock()
977
branch_transport = self.transport.clone(path)
978
mode = self._get_mkdir_mode()
979
branch_transport.create_prefix(mode=mode)
1222
self.transport.mkdir('branch', mode=self._get_mkdir_mode())
981
self.transport.mkdir(path, mode=mode)
1223
982
except errors.FileExists:
1225
return self.transport.clone('branch')
984
return self.transport.clone(path)
1227
986
def get_repository_transport(self, repository_format):
1228
987
"""See BzrDir.get_repository_transport()."""
1253
1012
return self.transport.clone('checkout')
1014
def get_branches(self):
1015
"""See ControlDir.get_branches."""
1018
ret[""] = self.open_branch(name="")
1019
except (errors.NotBranchError, errors.NoRepositoryPresent):
1022
for name in self._read_branch_list():
1023
ret[name] = self.open_branch(name=name.decode('utf-8'))
1255
1027
def has_workingtree(self):
1256
1028
"""Tell if this bzrdir contains a working tree.
1258
1030
Note: if you're going to open the working tree, you should just go
1259
1031
ahead and try, and not ask permission first.
1261
from bzrlib.workingtree import WorkingTreeFormat
1033
from bzrlib.workingtree import WorkingTreeFormatMetaDir
1263
WorkingTreeFormat.find_format_string(self)
1035
WorkingTreeFormatMetaDir.find_format_string(self)
1264
1036
except errors.NoWorkingTree:
1268
1040
def needs_format_conversion(self, format):
1269
1041
"""See BzrDir.needs_format_conversion()."""
1270
if not isinstance(self._format, format.__class__):
1042
if (not isinstance(self._format, format.__class__) or
1043
self._format.get_format_string() != format.get_format_string()):
1271
1044
# it is not a meta dir format, conversion is needed.
1273
1046
# we might want to push this down to the repository?
1296
1069
def open_branch(self, name=None, unsupported=False,
1297
ignore_fallbacks=False):
1298
"""See BzrDir.open_branch."""
1070
ignore_fallbacks=False, possible_transports=None):
1071
"""See ControlDir.open_branch."""
1073
name = self._get_selected_branch()
1299
1074
format = self.find_branch_format(name=name)
1300
1075
format.check_support_status(unsupported)
1301
1076
return format.open(self, name=name,
1302
_found=True, ignore_fallbacks=ignore_fallbacks)
1077
_found=True, ignore_fallbacks=ignore_fallbacks,
1078
possible_transports=possible_transports)
1304
1080
def open_repository(self, unsupported=False):
1305
1081
"""See BzrDir.open_repository."""
1306
from bzrlib.repository import RepositoryFormat
1307
format = RepositoryFormat.find_format(self)
1082
from bzrlib.repository import RepositoryFormatMetaDir
1083
format = RepositoryFormatMetaDir.find_format(self)
1308
1084
format.check_support_status(unsupported)
1309
1085
return format.open(self, _found=True)
1311
1087
def open_workingtree(self, unsupported=False,
1312
1088
recommend_upgrade=True):
1313
1089
"""See BzrDir.open_workingtree."""
1314
from bzrlib.workingtree import WorkingTreeFormat
1315
format = WorkingTreeFormat.find_format(self)
1090
from bzrlib.workingtree import WorkingTreeFormatMetaDir
1091
format = WorkingTreeFormatMetaDir.find_format(self)
1316
1092
format.check_support_status(unsupported, recommend_upgrade,
1317
1093
basedir=self.root_transport.base)
1318
1094
return format.open(self, _found=True)
1321
1097
return config.TransportConfig(self.transport, 'control.conf')
1100
class BzrFormat(object):
1101
"""Base class for all formats of things living in metadirs.
1103
This class manages the format string that is stored in the 'format'
1104
or 'branch-format' file.
1106
All classes for (branch-, repository-, workingtree-) formats that
1107
live in meta directories and have their own 'format' file
1108
(i.e. different from .bzr/branch-format) derive from this class,
1109
as well as the relevant base class for their kind
1110
(BranchFormat, WorkingTreeFormat, RepositoryFormat).
1112
Each format is identified by a "format" or "branch-format" file with a
1113
single line containing the base format name and then an optional list of
1116
Feature flags are supported as of bzr 2.5. Setting feature flags on formats
1117
will render them inaccessible to older versions of bzr.
1119
:ivar features: Dictionary mapping feature names to their necessity
1122
_present_features = set()
1128
def register_feature(cls, name):
1129
"""Register a feature as being present.
1131
:param name: Name of the feature
1134
raise ValueError("spaces are not allowed in feature names")
1135
if name in cls._present_features:
1136
raise errors.FeatureAlreadyRegistered(name)
1137
cls._present_features.add(name)
1140
def unregister_feature(cls, name):
1141
"""Unregister a feature."""
1142
cls._present_features.remove(name)
1144
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1146
for name, necessity in self.features.iteritems():
1147
if name in self._present_features:
1149
if necessity == "optional":
1150
mutter("ignoring optional missing feature %s", name)
1152
elif necessity == "required":
1153
raise errors.MissingFeature(name)
1155
mutter("treating unknown necessity as require for %s",
1157
raise errors.MissingFeature(name)
1160
def get_format_string(cls):
1161
"""Return the ASCII format string that identifies this format."""
1162
raise NotImplementedError(cls.get_format_string)
1165
def from_string(cls, text):
1166
format_string = cls.get_format_string()
1167
if not text.startswith(format_string):
1168
raise AssertionError("Invalid format header %r for %r" % (text, cls))
1169
lines = text[len(format_string):].splitlines()
1171
for lineno, line in enumerate(lines):
1173
(necessity, feature) = line.split(" ", 1)
1175
raise errors.ParseFormatError(format=cls, lineno=lineno+2,
1176
line=line, text=text)
1177
ret.features[feature] = necessity
1180
def as_string(self):
1181
"""Return the string representation of this format.
1183
lines = [self.get_format_string()]
1184
lines.extend([("%s %s\n" % (item[1], item[0])) for item in
1185
self.features.iteritems()])
1186
return "".join(lines)
1189
def _find_format(klass, registry, kind, format_string):
1191
first_line = format_string[:format_string.index("\n")+1]
1193
first_line = format_string
1195
cls = registry.get(first_line)
1197
raise errors.UnknownFormatError(format=first_line, kind=kind)
1198
return cls.from_string(format_string)
1200
def network_name(self):
1201
"""A simple byte string uniquely identifying this format for RPC calls.
1203
Metadir branch formats use their format string.
1205
return self.as_string()
1207
def __eq__(self, other):
1208
return (self.__class__ is other.__class__ and
1209
self.features == other.features)
1211
def _update_feature_flags(self, updated_flags):
1212
"""Update the feature flags in this format.
1214
:param updated_flags: Updated feature flags
1216
for name, necessity in updated_flags.iteritems():
1217
if necessity is None:
1219
del self.features[name]
1223
self.features[name] = necessity
1324
1226
class BzrProber(controldir.Prober):
1325
1227
"""Prober for formats that use a .bzr/ control directory."""
1829
1749
controldir.ControlDirFormat._default_format = BzrDirMetaFormat1()
1752
class BzrDirMetaFormat1Colo(BzrDirMetaFormat1):
1753
"""BzrDirMeta1 format with support for colocated branches."""
1755
colocated_branches = True
1758
def get_format_string(cls):
1759
"""See BzrDirFormat.get_format_string()."""
1760
return "Bazaar meta directory, format 1 (with colocated branches)\n"
1762
def get_format_description(self):
1763
"""See BzrDirFormat.get_format_description()."""
1764
return "Meta directory format 1 with support for colocated branches"
1766
def _open(self, transport):
1767
"""See BzrDirFormat._open."""
1768
# Create a new format instance because otherwise initialisation of new
1769
# metadirs share the global default format object leading to alias
1771
format = BzrDirMetaFormat1Colo()
1772
self._supply_sub_formats_to(format)
1773
return BzrDirMeta1(transport, format)
1776
BzrProber.formats.register(BzrDirMetaFormat1Colo.get_format_string(),
1777
BzrDirMetaFormat1Colo)
1832
1780
class ConvertMetaToMeta(controldir.Converter):
1833
1781
"""Converts the components of metadirs."""
1907
1855
return to_convert
1858
class ConvertMetaToColo(controldir.Converter):
1859
"""Add colocated branch support."""
1861
def __init__(self, target_format):
1862
"""Create a converter.that upgrades a metadir to the colo format.
1864
:param target_format: The final metadir format that is desired.
1866
self.target_format = target_format
1868
def convert(self, to_convert, pb):
1869
"""See Converter.convert()."""
1870
to_convert.transport.put_bytes('branch-format',
1871
self.target_format.as_string())
1872
return BzrDir.open_from_transport(to_convert.root_transport)
1875
class ConvertMetaToColo(controldir.Converter):
1876
"""Convert a 'development-colo' bzrdir to a '2a' bzrdir."""
1878
def __init__(self, target_format):
1879
"""Create a converter that converts a 'development-colo' metadir
1882
:param target_format: The final metadir format that is desired.
1884
self.target_format = target_format
1886
def convert(self, to_convert, pb):
1887
"""See Converter.convert()."""
1888
to_convert.transport.put_bytes('branch-format',
1889
self.target_format.as_string())
1890
return BzrDir.open_from_transport(to_convert.root_transport)
1910
1893
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
2020
2004
require_stacking)
2021
2005
self._bzrdir = bzrdir
2023
def acquire_repository(self, make_working_trees=None, shared=False):
2007
def acquire_repository(self, make_working_trees=None, shared=False,
2008
possible_transports=None):
2024
2009
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2026
2011
Creates the desired repository in the bzrdir we already have.
2013
if possible_transports is None:
2014
possible_transports = []
2016
possible_transports = list(possible_transports)
2017
possible_transports.append(self._bzrdir.root_transport)
2028
2018
stack_on = self._get_full_stack_on()
2030
2020
format = self._bzrdir._format
2031
2021
format.require_stacking(stack_on=stack_on,
2032
possible_transports=[self._bzrdir.root_transport])
2022
possible_transports=possible_transports)
2033
2023
if not self._require_stacking:
2034
2024
# We have picked up automatic stacking somewhere.
2035
note('Using default stacking branch %s at %s', self._stack_on,
2025
note(gettext('Using default stacking branch {0} at {1}').format(
2026
self._stack_on, self._stack_on_pwd))
2037
2027
repository = self._bzrdir.create_repository(shared=shared)
2038
2028
self._add_fallback(repository,
2039
possible_transports=[self._bzrdir.transport])
2029
possible_transports=possible_transports)
2040
2030
if make_working_trees is not None:
2041
2031
repository.set_make_working_trees(make_working_trees)
2042
2032
return repository, True
2121
2119
deprecated=True)
2122
2120
register_metadir(controldir.format_registry, 'dirstate',
2123
2121
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2124
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2125
'above when accessed over the network.',
2122
help='Format using dirstate for working trees. '
2123
'Compatible with bzr 0.8 and '
2124
'above when accessed over the network. Introduced in bzr 0.15.',
2126
2125
branch_format='bzrlib.branch.BzrBranchFormat5',
2127
2126
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2129
2128
deprecated=True)
2130
2129
register_metadir(controldir.format_registry, 'dirstate-tags',
2131
2130
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2132
help='New in 0.15: Fast local operations and improved scaling for '
2133
'network operations. Additionally adds support for tags.'
2134
' Incompatible with bzr < 0.15.',
2131
help='Variant of dirstate with support for tags. '
2132
'Introduced in bzr 0.15.',
2135
2133
branch_format='bzrlib.branch.BzrBranchFormat6',
2136
2134
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2138
2136
deprecated=True)
2139
2137
register_metadir(controldir.format_registry, 'rich-root',
2140
2138
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
2141
help='New in 1.0. Better handling of tree roots. Incompatible with'
2139
help='Variant of dirstate with better handling of tree roots. '
2140
'Introduced in bzr 1.0',
2143
2141
branch_format='bzrlib.branch.BzrBranchFormat6',
2144
2142
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2146
2144
deprecated=True)
2147
2145
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
2148
2146
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2149
help='New in 0.15: Fast local operations and improved scaling for '
2150
'network operations. Additionally adds support for versioning nested '
2151
'bzr branches. Incompatible with bzr < 0.15.',
2147
help='Variant of dirstate with support for nested trees. '
2148
'Introduced in 0.15.',
2152
2149
branch_format='bzrlib.branch.BzrBranchFormat6',
2153
2150
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2154
2151
experimental=True,
2157
2154
register_metadir(controldir.format_registry, 'pack-0.92',
2158
2155
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack1',
2159
help='New in 0.92: Pack-based format with data compatible with '
2160
'dirstate-tags format repositories. Interoperates with '
2161
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2156
help='Pack-based format used in 1.x series. Introduced in 0.92. '
2157
'Interoperates with bzr repositories before 0.92 but cannot be '
2158
'read by bzr < 0.92. '
2163
2160
branch_format='bzrlib.branch.BzrBranchFormat6',
2164
2161
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2166
2164
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
2167
2165
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack3',
2168
help='New in 0.92: Pack-based format with data compatible with '
2169
'dirstate-with-subtree format repositories. Interoperates with '
2166
help='Pack-based format used in 1.x series, with subtree support. '
2167
'Introduced in 0.92. Interoperates with '
2170
2168
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2172
2170
branch_format='bzrlib.branch.BzrBranchFormat6',
2173
2171
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2175
2174
experimental=True,
2177
2176
register_metadir(controldir.format_registry, 'rich-root-pack',
2178
2177
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack4',
2179
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
2180
'(needed for bzr-svn and bzr-git).',
2178
help='A variant of pack-0.92 that supports rich-root data '
2179
'(needed for bzr-svn and bzr-git). Introduced in 1.0.',
2181
2180
branch_format='bzrlib.branch.BzrBranchFormat6',
2182
2181
tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2185
2185
register_metadir(controldir.format_registry, '1.6',
2186
2186
'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
2272
register_metadir(controldir.format_registry, 'development-colo',
2273
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2274
help='The 2a format with experimental support for colocated branches.\n',
2275
branch_format='bzrlib.branch.BzrBranchFormat7',
2276
tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
2278
bzrdir_format=BzrDirMetaFormat1Colo,
2264
2282
# And the development formats above will have aliased one of the following:
2266
2284
# Finally, the current format.
2267
2285
register_metadir(controldir.format_registry, '2a',
2268
2286
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2269
help='First format for bzr 2.0 series.\n'
2287
help='Format for the bzr 2.0 series.\n'
2270
2288
'Uses group-compress storage.\n'
2271
2289
'Provides rich roots which are a one-way transition.\n',
2272
2290
# 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '