86
def _get_branch_location(control_dir, possible_transports=None):
87
"""Return location of branch for this control dir."""
89
this_branch = control_dir.open_branch(
90
possible_transports=possible_transports)
91
# This may be a heavy checkout, where we want the master branch
92
master_location = this_branch.get_bound_location()
93
if master_location is not None:
94
return master_location
95
# If not, use a local sibling
96
return this_branch.base
97
except errors.NotBranchError:
98
format = control_dir.find_branch_format()
99
if getattr(format, 'get_reference', None) is not None:
100
return format.get_reference(control_dir)
102
return control_dir.root_transport.base
105
def _is_colocated(control_dir, possible_transports=None):
106
"""Check if the branch in control_dir is colocated.
108
:param control_dir: Control directory
109
:return: Boolean indicating whether
111
# This path is meant to be relative to the existing branch
112
this_url = _get_branch_location(control_dir,
113
possible_transports=possible_transports)
114
# Perhaps the target control dir supports colocated branches?
116
root = controldir.ControlDir.open(this_url,
117
possible_transports=possible_transports)
118
except errors.NotBranchError:
119
return (False, this_url)
122
wt = control_dir.open_workingtree()
123
except (errors.NoWorkingTree, errors.NotLocalUrl):
124
return (False, this_url)
127
root._format.colocated_branches and
128
control_dir.control_url == root.control_url,
132
def lookup_new_sibling_branch(control_dir, location, possible_transports=None):
133
"""Lookup the location for a new sibling branch.
135
:param control_dir: Control directory relative to which to look up
137
:param location: Name of the new branch
138
:return: Full location to the new branch
140
location = directory_service.directories.dereference(location)
141
if '/' not in location and '\\' not in location:
142
(colocated, this_url) = _is_colocated(control_dir, possible_transports)
145
return urlutils.join_segment_parameters(this_url,
146
{"branch": urlutils.escape(location)})
148
return urlutils.join(this_url, '..', urlutils.escape(location))
152
def lookup_sibling_branch(control_dir, location, possible_transports=None):
153
"""Lookup sibling branch.
155
:param control_dir: Control directory relative to which to lookup the
157
:param location: Location to look up
158
:return: branch to open
161
# Perhaps it's a colocated branch?
162
return control_dir.open_branch(location,
163
possible_transports=possible_transports)
164
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
166
return Branch.open(location)
167
except errors.NotBranchError:
168
this_url = _get_branch_location(control_dir)
171
this_url, '..', urlutils.escape(location)))
174
86
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
175
87
def tree_files(file_list, default_branch=u'.', canonicalize=True,
940
self.add_cleanup(tree.lock_read().unlock)
941
852
if file_list is not None:
942
853
file_ids = tree.paths2ids(file_list, trees=extra_trees,
943
854
require_versioned=True)
944
855
# find_ids_across_trees may include some paths that don't
945
856
# exist in 'tree'.
946
entries = tree.iter_entries_by_dir(specific_file_ids=file_ids)
858
(tree.id2path(file_id), tree.inventory[file_id])
859
for file_id in file_ids if tree.has_id(file_id))
948
entries = tree.iter_entries_by_dir()
861
entries = tree.inventory.entries()
950
for path, entry in sorted(entries):
864
for path, entry in entries:
951
865
if kind and kind != entry.kind:
956
868
self.outf.write('%-50s %s\n' % (path, entry.file_id))
2415
2323
self.add_cleanup(wt.lock_read().unlock)
2416
2324
basis = wt.basis_tree()
2417
2325
self.add_cleanup(basis.lock_read().unlock)
2418
root_id = wt.get_root_id()
2419
for file_id in wt.all_file_ids():
2420
if basis.has_id(file_id):
2422
if root_id == file_id:
2424
path = wt.id2path(file_id)
2326
basis_inv = basis.inventory
2329
if basis_inv.has_id(file_id):
2331
if inv.is_root(file_id) and len(basis_inv) == 0:
2333
path = inv.id2path(file_id)
2425
2334
if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
6219
6128
from bzrlib import switch
6220
6129
tree_location = directory
6221
6130
revision = _get_one_revision('switch', revision)
6222
possible_transports = []
6223
control_dir = controldir.ControlDir.open_containing(tree_location,
6224
possible_transports=possible_transports)[0]
6131
control_dir = controldir.ControlDir.open_containing(tree_location)[0]
6225
6132
if to_location is None:
6226
6133
if revision is None:
6227
6134
raise errors.BzrCommandError(gettext('You must supply either a'
6228
6135
' revision or a location'))
6229
6136
to_location = tree_location
6231
branch = control_dir.open_branch(
6232
possible_transports=possible_transports)
6138
branch = control_dir.open_branch()
6233
6139
had_explicit_nick = branch.get_config().has_explicit_nickname()
6234
6140
except errors.NotBranchError:
6236
6142
had_explicit_nick = False
6237
6143
if create_branch:
6238
6144
if branch is None:
6239
raise errors.BzrCommandError(
6240
gettext('cannot create branch without source branch'))
6241
to_location = lookup_new_sibling_branch(control_dir, to_location,
6242
possible_transports=possible_transports)
6145
raise errors.BzrCommandError(gettext('cannot create branch without'
6147
to_location = directory_service.directories.dereference(
6149
if '/' not in to_location and '\\' not in to_location:
6150
# This path is meant to be relative to the existing branch
6151
this_url = self._get_branch_location(control_dir)
6152
# Perhaps the target control dir supports colocated branches?
6154
root = controldir.ControlDir.open(this_url,
6155
possible_transports=[control_dir.user_transport])
6156
except errors.NotBranchError:
6159
colocated = root._format.colocated_branches
6161
to_location = urlutils.join_segment_parameters(this_url,
6162
{"branch": urlutils.escape(to_location)})
6164
to_location = urlutils.join(
6165
this_url, '..', urlutils.escape(to_location))
6243
6166
to_branch = branch.bzrdir.sprout(to_location,
6244
possible_transports=possible_transports,
6245
source_branch=branch).open_branch()
6167
possible_transports=[branch.bzrdir.root_transport],
6168
source_branch=branch).open_branch()
6247
to_branch = lookup_sibling_branch(control_dir, to_location)
6170
# Perhaps it's a colocated branch?
6172
to_branch = control_dir.open_branch(to_location)
6173
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
6175
to_branch = Branch.open(to_location)
6176
except errors.NotBranchError:
6177
this_url = self._get_branch_location(control_dir)
6178
to_branch = Branch.open(
6180
this_url, '..', urlutils.escape(to_location)))
6248
6181
if revision is not None:
6249
6182
revision = revision.as_revision_id(to_branch)
6250
6183
switch.switch(control_dir, to_branch, force, revision_id=revision)
6254
6187
note(gettext('Switched to branch: %s'),
6255
6188
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6190
def _get_branch_location(self, control_dir):
6191
"""Return location of branch for this control dir."""
6193
this_branch = control_dir.open_branch()
6194
# This may be a heavy checkout, where we want the master branch
6195
master_location = this_branch.get_bound_location()
6196
if master_location is not None:
6197
return master_location
6198
# If not, use a local sibling
6199
return this_branch.base
6200
except errors.NotBranchError:
6201
format = control_dir.find_branch_format()
6202
if getattr(format, 'get_reference', None) is not None:
6203
return format.get_reference(control_dir)
6205
return control_dir.root_transport.base
6259
6208
class cmd_view(Command):