~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Martin Pool
  • Date: 2010-07-16 13:29:07 UTC
  • mto: This revision was merged to the branch mainline in revision 5351.
  • Revision ID: mbp@canonical.com-20100716132907-0iffip1m4qt5vvif
Move internal_tree_files and safe_relpath_files onto WorkingTree

Show diffs side-by-side

added added

removed removed

Lines of Context:
349
349
        if path is None:
350
350
            path = osutils.getcwd()
351
351
        control, relpath = bzrdir.BzrDir.open_containing(path)
352
 
 
353
352
        return control.open_workingtree(), relpath
354
353
 
355
354
    @staticmethod
 
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.
 
358
 
 
359
        Fail if the paths given are not all in a single tree.
 
360
 
 
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.
 
363
        """
 
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()
 
369
                if view_files:
 
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)
 
377
 
 
378
    def safe_relpath_files(self, file_list, canonicalize=True, apply_view=True):
 
379
        """Convert file_list into a list of relpaths in tree.
 
380
 
 
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
 
387
            than self.
 
388
        """
 
389
        if file_list is None:
 
390
            return None
 
391
        if self.supports_views() and apply_view:
 
392
            view_files = self.views.lookup_view()
 
393
        else:
 
394
            view_files = []
 
395
        new_list = []
 
396
        # self.relpath exists as a "thunk" to osutils, but canonical_relpath
 
397
        # doesn't - fix that up here before we enter the loop.
 
398
        if canonicalize:
 
399
            fixer = lambda p: osutils.canonical_relpath(self.basedir, p)
 
400
        else:
 
401
            fixer = self.relpath
 
402
        for filename in file_list:
 
403
            try:
 
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)
 
410
        return new_list
 
411
 
 
412
 
 
413
    @staticmethod
356
414
    def open_downlevel(path=None):
357
415
        """Open an unsupported working tree.
358
416