153
153
# XXX: Bad function name; should possibly also be a class method of
154
154
# WorkingTree rather than a function.
155
# @symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
155
156
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
156
157
apply_view=True):
157
158
"""Convert command-line paths to a WorkingTree and relative paths.
160
Deprecated: use WorkingTree.open_containing_paths instead.
159
162
This is typically used for command-line processors that take one or
160
163
more filenames, and infer the workingtree that contains them.
172
175
:return: workingtree, [relative_paths]
174
if file_list is None or len(file_list) == 0:
175
tree = WorkingTree.open_containing(default_branch)[0]
176
if tree.supports_views() and apply_view:
177
view_files = tree.views.lookup_view()
179
file_list = view_files
180
view_str = views.view_display_str(view_files)
181
note("Ignoring files outside view. View is %s" % view_str)
182
return tree, file_list
183
tree = WorkingTree.open_containing(file_list[0])[0]
184
return tree, safe_relpath_files(tree, file_list, canonicalize,
185
apply_view=apply_view)
188
def safe_relpath_files(tree, file_list, canonicalize=True, apply_view=True):
189
"""Convert file_list into a list of relpaths in tree.
191
:param tree: A tree to operate on.
192
:param file_list: A list of user provided paths or None.
193
:param apply_view: if True and a view is set, apply it or check that
194
specified files are within it
195
:return: A list of relative paths.
196
:raises errors.PathNotChild: When a provided path is in a different tree
199
if file_list is None:
201
if tree.supports_views() and apply_view:
202
view_files = tree.views.lookup_view()
206
# tree.relpath exists as a "thunk" to osutils, but canonical_relpath
207
# doesn't - fix that up here before we enter the loop.
209
fixer = lambda p: osutils.canonical_relpath(tree.basedir, p)
212
for filename in file_list:
214
relpath = fixer(osutils.dereference_path(filename))
215
if view_files and not osutils.is_inside_any(view_files, relpath):
216
raise errors.FileOutsideView(filename, view_files)
217
new_list.append(relpath)
218
except errors.PathNotChild:
219
raise errors.FileInWrongBranch(tree.branch, filename)
177
return WorkingTree.open_containing_paths(
178
file_list, default_directory='.',
223
183
def _get_view_info_for_change_reporter(tree):
3189
3149
reporter=None, verbose=verbose, revprops=properties,
3190
3150
authors=author, timestamp=commit_stamp,
3191
3151
timezone=offset,
3192
exclude=safe_relpath_files(tree, exclude))
3152
exclude=tree.safe_relpath_files(exclude))
3193
3153
except PointlessCommit:
3194
3154
raise errors.BzrCommandError("No changes to commit."
3195
3155
" Use --unchanged to commit anyhow.")