~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robert Collins
  • Date: 2007-09-04 10:08:58 UTC
  • mto: (2592.3.126 repository)
  • mto: This revision was merged to the branch mainline in revision 2862.
  • Revision ID: robertc@robertcollins.net-20070904100858-971b6sssddwfmwrw
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
 tuple containing the key information about a path for commit processing
 to complete. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
702
702
        if updated:
703
703
            self.set_parent_ids(parents, allow_leftmost_as_ghost=True)
704
704
 
 
705
    def path_content_summary(self, path, _lstat=os.lstat,
 
706
        _mapper=osutils.file_kind_from_stat_mode):
 
707
        """See Tree.path_content_summary."""
 
708
        abspath = self.abspath(path)
 
709
        try:
 
710
            stat_result = _lstat(abspath)
 
711
        except OSError, e:
 
712
            if getattr(e, 'errno', None) == errno.ENOENT:
 
713
                # no file.
 
714
                return ('missing', None, None, None)
 
715
            # propogate other errors
 
716
            raise
 
717
        kind = _mapper(stat_result.st_mode)
 
718
        if kind == 'file':
 
719
            size = stat_result.st_size
 
720
            # try for a stat cache lookup
 
721
            if not supports_executable():
 
722
                executable = None # caller can decide policy.
 
723
            else:
 
724
                mode = stat_result.st_mode
 
725
                executable = bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
 
726
            sha1 = None # 'stat-hit-check' here
 
727
            return (kind, size, executable, sha1)
 
728
        elif kind == 'directory':
 
729
            # perhaps it looks like a plain directory, but it's really a
 
730
            # reference.
 
731
            if self._directory_is_tree_reference(path):
 
732
                kind = 'tree-reference'
 
733
            return kind, None, None, None
 
734
        elif kind == 'symlink':
 
735
            return ('symlink', None, None, os.readlink(abspath))
 
736
        else:
 
737
            return (kind, None, None, None)
 
738
 
705
739
    @deprecated_method(zero_eleven)
706
740
    @needs_read_lock
707
741
    def pending_merges(self):
943
977
            other_tree.unlock()
944
978
        other_tree.bzrdir.retire_bzrdir()
945
979
 
 
980
    def _directory_is_tree_reference(self, relpath):
 
981
        # as a special case, if a directory contains control files then 
 
982
        # it's a tree reference, except that the root of the tree is not
 
983
        return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr")
 
984
        # TODO: We could ask all the control formats whether they
 
985
        # recognize this directory, but at the moment there's no cheap api
 
986
        # to do that.  Since we probably can only nest bzr checkouts and
 
987
        # they always use this name it's ok for now.  -- mbp 20060306
 
988
        #
 
989
        # FIXME: There is an unhandled case here of a subdirectory
 
990
        # containing .bzr but not a branch; that will probably blow up
 
991
        # when you try to commit it.  It might happen if there is a
 
992
        # checkout in a subdirectory.  This can be avoided by not adding
 
993
        # it.  mbp 20070306
 
994
 
946
995
    @needs_tree_write_lock
947
996
    def extract(self, file_id, format=None):
948
997
        """Extract a subtree from this tree.