350
350
path = osutils.getcwd()
351
351
control, relpath = bzrdir.BzrDir.open_containing(path)
353
352
return control.open_workingtree(), relpath
355
def open_containing_paths(file_list, default_directory='.',
356
canonicalize=True, apply_view=True):
357
"""Open the WorkingTree that contains a set of paths.
359
Fail if the paths given are not all in a single tree.
361
This is used for the many command-line interfaces that take a list of
362
any number of files and that require they all be in the same tree.
364
# recommended replacement for builtins.internal_tree_files
365
if file_list is None or len(file_list) == 0:
366
tree = WorkingTree.open_containing(default_directory)[0]
367
if tree.supports_views() and apply_view:
368
view_files = tree.views.lookup_view()
370
file_list = view_files
371
view_str = views.view_display_str(view_files)
372
note("Ignoring files outside view. View is %s" % view_str)
373
return tree, file_list
374
tree = WorkingTree.open_containing(file_list[0])[0]
375
return tree, tree.safe_relpath_files(file_list, canonicalize,
376
apply_view=apply_view)
378
def safe_relpath_files(self, file_list, canonicalize=True, apply_view=True):
379
"""Convert file_list into a list of relpaths in tree.
381
:param self: A tree to operate on.
382
:param file_list: A list of user provided paths or None.
383
:param apply_view: if True and a view is set, apply it or check that
384
specified files are within it
385
:return: A list of relative paths.
386
:raises errors.PathNotChild: When a provided path is in a different self
389
if file_list is None:
391
if self.supports_views() and apply_view:
392
view_files = self.views.lookup_view()
396
# self.relpath exists as a "thunk" to osutils, but canonical_relpath
397
# doesn't - fix that up here before we enter the loop.
399
fixer = lambda p: osutils.canonical_relpath(self.basedir, p)
402
for filename in file_list:
404
relpath = fixer(osutils.dereference_path(filename))
405
if view_files and not osutils.is_inside_any(view_files, relpath):
406
raise errors.FileOutsideView(filename, view_files)
407
new_list.append(relpath)
408
except errors.PathNotChild:
409
raise errors.FileInWrongBranch(self.branch, filename)
356
414
def open_downlevel(path=None):
357
415
"""Open an unsupported working tree.