86
def _get_branch_location(control_dir):
87
"""Return location of branch for this control dir."""
89
this_branch = control_dir.open_branch()
90
# This may be a heavy checkout, where we want the master branch
91
master_location = this_branch.get_bound_location()
92
if master_location is not None:
93
return master_location
94
# If not, use a local sibling
95
return this_branch.base
96
except errors.NotBranchError:
97
format = control_dir.find_branch_format()
98
if getattr(format, 'get_reference', None) is not None:
99
return format.get_reference(control_dir)
101
return control_dir.root_transport.base
104
def lookup_new_sibling_branch(control_dir, location):
105
"""Lookup the location for a new sibling branch.
107
:param control_dir: Control directory relative to which to look up
109
:param location: Name of the new branch
110
:return: Full location to the new branch
112
location = directory_service.directories.dereference(location)
113
if '/' not in location and '\\' not in location:
114
# This path is meant to be relative to the existing branch
115
this_url = _get_branch_location(control_dir)
116
# Perhaps the target control dir supports colocated branches?
118
root = controldir.ControlDir.open(this_url,
119
possible_transports=[control_dir.user_transport])
120
except errors.NotBranchError:
123
colocated = root._format.colocated_branches
126
return urlutils.join_segment_parameters(this_url,
127
{"branch": urlutils.escape(location)})
129
return urlutils.join(this_url, '..', urlutils.escape(location))
133
def lookup_sibling_branch(control_dir, location):
134
"""Lookup sibling branch.
136
:param control_dir: Control directory relative to which to lookup the
138
:param location: Location to look up
139
:return: branch to open
142
# Perhaps it's a colocated branch?
143
return control_dir.open_branch(location)
144
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
146
return Branch.open(location)
147
except errors.NotBranchError:
148
this_url = _get_branch_location(control_dir)
151
this_url, '..', urlutils.escape(location)))
86
154
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
87
155
def tree_files(file_list, default_branch=u'.', canonicalize=True,
6147
6215
had_explicit_nick = False
6148
6216
if create_branch:
6149
6217
if branch is None:
6150
raise errors.BzrCommandError(gettext('cannot create branch without'
6152
to_location = directory_service.directories.dereference(
6154
if '/' not in to_location and '\\' not in to_location:
6155
# This path is meant to be relative to the existing branch
6156
this_url = self._get_branch_location(control_dir)
6157
# Perhaps the target control dir supports colocated branches?
6159
root = controldir.ControlDir.open(this_url,
6160
possible_transports=[control_dir.user_transport])
6161
except errors.NotBranchError:
6164
colocated = root._format.colocated_branches
6166
to_location = urlutils.join_segment_parameters(this_url,
6167
{"branch": urlutils.escape(to_location)})
6169
to_location = urlutils.join(
6170
this_url, '..', urlutils.escape(to_location))
6218
raise errors.BzrCommandError(
6219
gettext('cannot create branch without source branch'))
6220
to_location = lookup_new_sibling_branch(control_dir, to_location)
6171
6221
to_branch = branch.bzrdir.sprout(to_location,
6172
possible_transports=[branch.bzrdir.root_transport],
6173
source_branch=branch).open_branch()
6222
possible_transports=[branch.bzrdir.root_transport],
6223
source_branch=branch).open_branch()
6175
# Perhaps it's a colocated branch?
6177
to_branch = control_dir.open_branch(to_location)
6178
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
6180
to_branch = Branch.open(to_location)
6181
except errors.NotBranchError:
6182
this_url = self._get_branch_location(control_dir)
6183
to_branch = Branch.open(
6185
this_url, '..', urlutils.escape(to_location)))
6225
to_branch = lookup_sibling_branch(control_dir, to_location)
6186
6226
if revision is not None:
6187
6227
revision = revision.as_revision_id(to_branch)
6188
6228
switch.switch(control_dir, to_branch, force, revision_id=revision)
6192
6232
note(gettext('Switched to branch: %s'),
6193
6233
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6195
def _get_branch_location(self, control_dir):
6196
"""Return location of branch for this control dir."""
6198
this_branch = control_dir.open_branch()
6199
# This may be a heavy checkout, where we want the master branch
6200
master_location = this_branch.get_bound_location()
6201
if master_location is not None:
6202
return master_location
6203
# If not, use a local sibling
6204
return this_branch.base
6205
except errors.NotBranchError:
6206
format = control_dir.find_branch_format()
6207
if getattr(format, 'get_reference', None) is not None:
6208
return format.get_reference(control_dir)
6210
return control_dir.root_transport.base
6213
6237
class cmd_view(Command):