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)))
86
174
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
87
175
def tree_files(file_list, default_branch=u'.', canonicalize=True,
940
self.add_cleanup(tree.lock_read().unlock)
852
941
if file_list is not None:
853
942
file_ids = tree.paths2ids(file_list, trees=extra_trees,
854
943
require_versioned=True)
855
944
# find_ids_across_trees may include some paths that don't
856
945
# exist in 'tree'.
858
(tree.id2path(file_id), tree.inventory[file_id])
859
for file_id in file_ids if tree.has_id(file_id))
946
entries = tree.iter_entries_by_dir(specific_file_ids=file_ids)
861
entries = tree.inventory.entries()
948
entries = tree.iter_entries_by_dir()
864
for path, entry in entries:
950
for path, entry in sorted(entries):
865
951
if kind and kind != entry.kind:
868
956
self.outf.write('%-50s %s\n' % (path, entry.file_id))
1558
1650
def run(self, dir=u'.'):
1559
1651
tree = WorkingTree.open_containing(dir)[0]
1560
1652
self.add_cleanup(tree.lock_read().unlock)
1561
new_inv = tree.inventory
1653
new_inv = tree.root_inventory
1562
1654
old_tree = tree.basis_tree()
1563
1655
self.add_cleanup(old_tree.lock_read().unlock)
1564
old_inv = old_tree.inventory
1656
old_inv = old_tree.root_inventory
1566
1658
iterator = tree.iter_changes(old_tree, include_unchanged=True)
1567
1659
for f, paths, c, v, p, n, k, e in iterator:
2325
2417
self.add_cleanup(wt.lock_read().unlock)
2326
2418
basis = wt.basis_tree()
2327
2419
self.add_cleanup(basis.lock_read().unlock)
2328
basis_inv = basis.inventory
2331
if basis_inv.has_id(file_id):
2333
if inv.is_root(file_id) and len(basis_inv) == 0:
2335
path = inv.id2path(file_id)
2420
root_id = wt.get_root_id()
2421
for file_id in wt.all_file_ids():
2422
if basis.has_id(file_id):
2424
if root_id == file_id:
2426
path = wt.id2path(file_id)
2336
2427
if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
6135
6227
from bzrlib import switch
6136
6228
tree_location = directory
6137
6229
revision = _get_one_revision('switch', revision)
6138
control_dir = controldir.ControlDir.open_containing(tree_location)[0]
6230
possible_transports = []
6231
control_dir = controldir.ControlDir.open_containing(tree_location,
6232
possible_transports=possible_transports)[0]
6139
6233
if to_location is None:
6140
6234
if revision is None:
6141
6235
raise errors.BzrCommandError(gettext('You must supply either a'
6142
6236
' revision or a location'))
6143
6237
to_location = tree_location
6145
branch = control_dir.open_branch()
6239
branch = control_dir.open_branch(
6240
possible_transports=possible_transports)
6146
6241
had_explicit_nick = branch.get_config().has_explicit_nickname()
6147
6242
except errors.NotBranchError:
6149
6244
had_explicit_nick = False
6150
6245
if create_branch:
6151
6246
if branch is None:
6152
raise errors.BzrCommandError(gettext('cannot create branch without'
6154
to_location = directory_service.directories.dereference(
6156
if '/' not in to_location and '\\' not in to_location:
6157
# This path is meant to be relative to the existing branch
6158
this_url = self._get_branch_location(control_dir)
6159
# Perhaps the target control dir supports colocated branches?
6161
root = controldir.ControlDir.open(this_url,
6162
possible_transports=[control_dir.user_transport])
6163
except errors.NotBranchError:
6166
colocated = root._format.colocated_branches
6168
to_location = urlutils.join_segment_parameters(this_url,
6169
{"branch": urlutils.escape(to_location)})
6171
to_location = urlutils.join(
6172
this_url, '..', urlutils.escape(to_location))
6247
raise errors.BzrCommandError(
6248
gettext('cannot create branch without source branch'))
6249
to_location = lookup_new_sibling_branch(control_dir, to_location,
6250
possible_transports=possible_transports)
6173
6251
to_branch = branch.bzrdir.sprout(to_location,
6174
possible_transports=[branch.bzrdir.root_transport],
6175
source_branch=branch).open_branch()
6252
possible_transports=possible_transports,
6253
source_branch=branch).open_branch()
6177
# Perhaps it's a colocated branch?
6179
to_branch = control_dir.open_branch(to_location)
6180
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
6182
to_branch = Branch.open(to_location)
6183
except errors.NotBranchError:
6184
this_url = self._get_branch_location(control_dir)
6185
to_branch = Branch.open(
6187
this_url, '..', urlutils.escape(to_location)))
6255
to_branch = lookup_sibling_branch(control_dir, to_location)
6188
6256
if revision is not None:
6189
6257
revision = revision.as_revision_id(to_branch)
6190
6258
switch.switch(control_dir, to_branch, force, revision_id=revision)
6194
6262
note(gettext('Switched to branch: %s'),
6195
6263
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
6197
def _get_branch_location(self, control_dir):
6198
"""Return location of branch for this control dir."""
6200
this_branch = control_dir.open_branch()
6201
# This may be a heavy checkout, where we want the master branch
6202
master_location = this_branch.get_bound_location()
6203
if master_location is not None:
6204
return master_location
6205
# If not, use a local sibling
6206
return this_branch.base
6207
except errors.NotBranchError:
6208
format = control_dir.find_branch_format()
6209
if getattr(format, 'get_reference', None) is not None:
6210
return format.get_reference(control_dir)
6212
return control_dir.root_transport.base
6215
6267
class cmd_view(Command):