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
# XXX: doesn't really belong here, and seems to have the strange
368
# side effect of making it return a bunch of files, not the whole
369
# tree -- mbp 20100716
370
if tree.supports_views() and apply_view:
371
view_files = tree.views.lookup_view()
373
file_list = view_files
374
view_str = views.view_display_str(view_files)
375
note("Ignoring files outside view. View is %s" % view_str)
376
return tree, file_list
377
tree = WorkingTree.open_containing(file_list[0])[0]
378
return tree, tree.safe_relpath_files(file_list, canonicalize,
379
apply_view=apply_view)
381
def safe_relpath_files(self, file_list, canonicalize=True, apply_view=True):
382
"""Convert file_list into a list of relpaths in tree.
384
:param self: A tree to operate on.
385
:param file_list: A list of user provided paths or None.
386
:param apply_view: if True and a view is set, apply it or check that
387
specified files are within it
388
:return: A list of relative paths.
389
:raises errors.PathNotChild: When a provided path is in a different self
392
if file_list is None:
394
if self.supports_views() and apply_view:
395
view_files = self.views.lookup_view()
399
# self.relpath exists as a "thunk" to osutils, but canonical_relpath
400
# doesn't - fix that up here before we enter the loop.
402
fixer = lambda p: osutils.canonical_relpath(self.basedir, p)
405
for filename in file_list:
406
relpath = fixer(osutils.dereference_path(filename))
407
if view_files and not osutils.is_inside_any(view_files, relpath):
408
raise errors.FileOutsideView(filename, view_files)
409
new_list.append(relpath)
356
413
def open_downlevel(path=None):
357
414
"""Open an unsupported working tree.