75
75
from bzrlib.trace import mutter, note, warning, is_quiet, get_verbosity_level
78
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
78
79
def tree_files(file_list, default_branch=u'.', canonicalize=True,
80
81
return internal_tree_files(file_list, default_branch, canonicalize,
149
150
# XXX: Bad function name; should possibly also be a class method of
150
151
# WorkingTree rather than a function.
152
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
151
153
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
152
154
apply_view=True):
153
155
"""Convert command-line paths to a WorkingTree and relative paths.
157
Deprecated: use WorkingTree.open_containing_paths instead.
155
159
This is typically used for command-line processors that take one or
156
160
more filenames, and infer the workingtree that contains them.
168
172
:return: workingtree, [relative_paths]
170
if file_list is None or len(file_list) == 0:
171
tree = WorkingTree.open_containing(default_branch)[0]
172
if tree.supports_views() and apply_view:
173
view_files = tree.views.lookup_view()
175
file_list = view_files
176
view_str = views.view_display_str(view_files)
177
note("Ignoring files outside view. View is %s" % view_str)
178
return tree, file_list
179
tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
180
return tree, safe_relpath_files(tree, file_list, canonicalize,
181
apply_view=apply_view)
184
def safe_relpath_files(tree, file_list, canonicalize=True, apply_view=True):
185
"""Convert file_list into a list of relpaths in tree.
187
:param tree: A tree to operate on.
188
:param file_list: A list of user provided paths or None.
189
:param apply_view: if True and a view is set, apply it or check that
190
specified files are within it
191
:return: A list of relative paths.
192
:raises errors.PathNotChild: When a provided path is in a different tree
195
if file_list is None:
197
if tree.supports_views() and apply_view:
198
view_files = tree.views.lookup_view()
202
# tree.relpath exists as a "thunk" to osutils, but canonical_relpath
203
# doesn't - fix that up here before we enter the loop.
205
fixer = lambda p: osutils.canonical_relpath(tree.basedir, p)
208
for filename in file_list:
209
relpath = fixer(osutils.dereference_path(filename))
210
if view_files and not osutils.is_inside_any(view_files, relpath):
211
raise errors.FileOutsideView(filename, view_files)
212
new_list.append(relpath)
174
return WorkingTree.open_containing_paths(
175
file_list, default_directory='.',
216
180
def _get_view_info_for_change_reporter(tree):
316
280
raise errors.BzrCommandError('bzr status --revision takes exactly'
317
281
' one or two revision specifiers')
319
tree, relfile_list = tree_files(file_list)
283
tree, relfile_list = WorkingTree.open_containing_paths(file_list)
320
284
# Avoid asking for specific files when that is not needed.
321
285
if relfile_list == ['']:
322
286
relfile_list = None
754
718
raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
756
720
revision = _get_one_revision('inventory', revision)
757
work_tree, file_list = tree_files(file_list)
721
work_tree, file_list = WorkingTree.open_containing_paths(file_list)
758
722
self.add_cleanup(work_tree.lock_read().unlock)
759
723
if revision is not None:
760
724
tree = revision.as_tree(work_tree.branch)
826
790
if len(names_list) < 2:
827
791
raise errors.BzrCommandError("missing file argument")
828
tree, rel_names = tree_files(names_list, canonicalize=False)
792
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
829
793
self.add_cleanup(tree.lock_tree_write().unlock)
830
794
self._run(tree, names_list, rel_names, after)
837
801
raise errors.BzrCommandError('--after cannot be specified with'
839
work_tree, file_list = tree_files(names_list, default_branch='.')
803
work_tree, file_list = WorkingTree.open_containing_paths(
804
names_list, default_directory='.')
840
805
self.add_cleanup(work_tree.lock_tree_write().unlock)
841
806
rename_map.RenameMap.guess_renames(work_tree, dry_run)
1520
1485
def run(self, file_list, verbose=False, new=False,
1521
1486
file_deletion_strategy='safe'):
1522
tree, file_list = tree_files(file_list)
1487
tree, file_list = WorkingTree.open_containing_paths(file_list)
1524
1489
if file_list is not None:
1525
1490
file_list = [f for f in file_list]
3103
3068
properties = {}
3105
tree, selected_list = tree_files(selected_list)
3070
tree, selected_list = WorkingTree.open_containing_paths(selected_list)
3106
3071
if selected_list == ['']:
3107
3072
# workaround - commit of root of tree should be exactly the same
3108
3073
# as just default commit in that tree, and succeed even though
3182
3147
reporter=None, verbose=verbose, revprops=properties,
3183
3148
authors=author, timestamp=commit_stamp,
3184
3149
timezone=offset,
3185
exclude=safe_relpath_files(tree, exclude))
3150
exclude=tree.safe_relpath_files(exclude))
3186
3151
except PointlessCommit:
3187
3152
raise errors.BzrCommandError("No changes to commit."
3188
3153
" Use --unchanged to commit anyhow.")
4084
4049
from bzrlib.conflicts import restore
4085
4050
if merge_type is None:
4086
4051
merge_type = _mod_merge.Merge3Merger
4087
tree, file_list = tree_files(file_list)
4052
tree, file_list = WorkingTree.open_containing_paths(file_list)
4088
4053
self.add_cleanup(tree.lock_write().unlock)
4089
4054
parents = tree.get_parent_ids()
4090
4055
if len(parents) != 2:
4201
4166
def run(self, revision=None, no_backup=False, file_list=None,
4202
4167
forget_merges=None):
4203
tree, file_list = tree_files(file_list)
4168
tree, file_list = WorkingTree.open_containing_paths(file_list)
4204
4169
self.add_cleanup(tree.lock_tree_write().unlock)
4205
4170
if forget_merges:
4206
4171
tree.set_parent_ids(tree.get_parent_ids()[:1])
5705
tree, file_list = tree_files(file_list, apply_view=False)
5670
tree, file_list = WorkingTree.open_containing_paths(file_list,
5706
5672
current_view, view_dict = tree.views.get_view_info()
5707
5673
if name is None:
5708
5674
name = current_view