233
233
t = _mod_transport.get_transport(url)
237
def find_bzrdirs(transport, evaluate=None, list_current=None):
237
def find_bzrdirs(cls, transport, evaluate=None, list_current=None):
238
238
"""Find bzrdirs recursively from current location.
240
240
This is intended primarily as a building block for more sophisticated
261
261
current_transport = pending.pop()
264
bzrdir = BzrDir.open_from_transport(current_transport)
264
bzrdir = cls.open_from_transport(current_transport)
265
265
except (errors.NotBranchError, errors.PermissionDenied):
275
275
for subdir in sorted(subdirs, reverse=True):
276
276
pending.append(current_transport.clone(subdir))
279
def find_branches(transport):
279
def find_branches(cls, transport):
280
280
"""Find all branches under a transport.
282
282
This will find all branches below the transport, including branches
303
303
ret.extend(branches)
307
def create_branch_and_repo(base, force_new_repo=False, format=None):
308
"""Create a new BzrDir, Branch and Repository at the url 'base'.
307
def create_branch_and_repo(cls, base, force_new_repo=False, format=None):
308
"""Create a new ControlDir, Branch and Repository at the url 'base'.
310
310
This will use the current default BzrDirFormat unless one is
311
311
specified, and use whatever
320
320
:param format: If supplied, the format of branch to create. If not
321
321
supplied, the default is used.
323
bzrdir = BzrDir.create(base, format)
323
bzrdir = cls.create(base, format)
324
324
bzrdir._find_or_create_repository(force_new_repo)
325
325
return bzrdir.create_branch()
548
def create_branch_convenience(base, force_new_repo=False,
548
def create_branch_convenience(cls, base, force_new_repo=False,
549
549
force_new_tree=None, format=None,
550
550
possible_transports=None):
551
"""Create a new BzrDir, Branch and Repository at the url 'base'.
551
"""Create a new ControlDir, Branch and Repository at the url 'base'.
553
553
This is a convenience function - it will use an existing repository
554
554
if possible, can be told explicitly whether to create a working tree or
557
This will use the current default BzrDirFormat unless one is
557
This will use the current default ControlDirFormat unless one is
558
558
specified, and use whatever
559
559
repository format that that uses via bzrdir.create_branch and
560
560
create_repository. If a shared repository is available that is used
578
578
t = _mod_transport.get_transport(base, possible_transports)
579
579
if not isinstance(t, local.LocalTransport):
580
580
raise errors.NotLocalUrl(base)
581
bzrdir = BzrDir.create(base, format, possible_transports)
581
bzrdir = cls.create(base, format, possible_transports)
582
582
repo = bzrdir._find_or_create_repository(force_new_repo)
583
583
result = bzrdir.create_branch()
584
584
if force_new_tree or (repo.make_working_trees() and
593
def create_standalone_workingtree(base, format=None):
594
"""Create a new BzrDir, WorkingTree, Branch and Repository at 'base'.
593
def create_standalone_workingtree(cls, base, format=None):
594
"""Create a new ControlDir, WorkingTree, Branch and Repository at 'base'.
596
596
'base' must be a local path or a file:// url.
598
This will use the current default BzrDirFormat unless one is
598
This will use the current default ControlDirFormat unless one is
599
599
specified, and use whatever
600
600
repository format that that uses for bzrdirformat.create_workingtree,
601
601
create_branch and create_repository.
606
606
t = _mod_transport.get_transport(base)
607
607
if not isinstance(t, local.LocalTransport):
608
608
raise errors.NotLocalUrl(base)
609
bzrdir = BzrDir.create_branch_and_repo(base,
609
bzrdir = cls.create_branch_and_repo(base,
610
610
force_new_repo=True,
611
611
format=format).bzrdir
612
612
return bzrdir.create_workingtree()
813
813
# add new tests for it to the appropriate place.
814
814
return filename == '.bzr' or filename.startswith('.bzr/')
817
def open_unsupported(base):
817
def open_unsupported(cls, base):
818
818
"""Open a branch which is not supported."""
819
return BzrDir.open(base, _unsupported=True)
819
return cls.open(base, _unsupported=True)
822
def open(base, _unsupported=False, possible_transports=None):
822
def open(cls, base, _unsupported=False, possible_transports=None):
823
823
"""Open an existing bzrdir, rooted at 'base' (url).
825
:param _unsupported: a private parameter to the BzrDir class.
825
:param _unsupported: a private parameter to the ControlDir class.
827
827
t = _mod_transport.get_transport(base, possible_transports)
828
return BzrDir.open_from_transport(t, _unsupported=_unsupported)
828
return cls.open_from_transport(t, _unsupported=_unsupported)
831
def open_from_transport(transport, _unsupported=False,
831
def open_from_transport(cls, transport, _unsupported=False,
832
832
_server_formats=True):
833
833
"""Open a bzrdir within a particular directory.
835
835
:param transport: Transport containing the bzrdir.
836
836
:param _unsupported: private.
838
for hook in BzrDir.hooks['pre_open']:
838
for hook in cls.hooks['pre_open']:
840
840
# Keep initial base since 'transport' may be modified while following
841
841
# the redirections.
862
862
format.check_support_status(_unsupported)
863
863
return format.open(transport, _found=True)
866
def open_containing(url, possible_transports=None):
866
def open_containing(cls, url, possible_transports=None):
867
867
"""Open an existing branch which contains url.
869
869
:param url: url to search from.
871
871
See open_containing_from_transport for more detail.
873
873
transport = _mod_transport.get_transport(url, possible_transports)
874
return BzrDir.open_containing_from_transport(transport)
874
return cls.open_containing_from_transport(transport)
877
def open_containing_from_transport(a_transport):
877
def open_containing_from_transport(cls, a_transport):
878
878
"""Open an existing branch which contains a_transport.base.
880
880
This probes for a branch at a_transport, and searches upwards from there.
885
885
format, UnknownFormatError or UnsupportedFormatError are raised.
886
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
888
:return: The ControlDir that contains the path, and a Unicode path
889
889
for the rest of the URL.
891
891
# this gets the normalised url back. I.e. '.' -> the full path.
892
892
url = a_transport.base
895
result = BzrDir.open_from_transport(a_transport)
895
result = cls.open_from_transport(a_transport)
896
896
return result, urlutils.unescape(a_transport.relpath(url))
897
897
except errors.NotBranchError, e:
1003
1003
:require_stacking: If True, non-stackable formats will be upgraded
1004
1004
to similar stackable formats.
1005
:returns: a BzrDirFormat with all component formats either set
1005
:returns: a ControlDirFormat with all component formats either set
1006
1006
appropriately or set to None if that component should not be
1024
1024
def create(cls, base, format=None, possible_transports=None):
1025
"""Create a new BzrDir at the url 'base'.
1025
"""Create a new ControlDir at the url 'base'.
1027
1027
:param format: If supplied, the format of branch to create. If not
1028
1028
supplied, the default is used.