703
703
self.set_parent_ids(parents, allow_leftmost_as_ghost=True)
705
def path_content_summary(self, path, _lstat=osutils.lstat,
706
_mapper=osutils.file_kind_from_stat_mode):
707
"""See Tree.path_content_summary."""
708
abspath = self.abspath(path)
710
stat_result = _lstat(abspath)
712
if getattr(e, 'errno', None) == errno.ENOENT:
714
return ('missing', None, None, None)
715
# propagate other errors
717
kind = _mapper(stat_result.st_mode)
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.
724
mode = stat_result.st_mode
725
executable = bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
726
return (kind, size, executable, self._sha_from_stat(
728
elif kind == 'directory':
729
# perhaps it looks like a plain directory, but it's really a
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))
737
return (kind, None, None, None)
705
739
@deprecated_method(zero_eleven)
707
741
def pending_merges(self):
799
833
yield Stanza(file_id=file_id.decode('utf8'), hash=hash)
800
834
self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
836
def _sha_from_stat(self, path, stat_result):
837
"""Get a sha digest from the tree's stat cache.
839
The default implementation assumes no stat cache is present.
841
:param path: The path.
842
:param stat_result: The stat result being looked up.
802
846
def _put_rio(self, filename, stanzas, header):
803
847
self._must_be_locked()
804
848
my_file = rio_file(stanzas, header)
943
987
other_tree.unlock()
944
988
other_tree.bzrdir.retire_bzrdir()
990
def _directory_is_tree_reference(self, relpath):
991
# as a special case, if a directory contains control files then
992
# it's a tree reference, except that the root of the tree is not
993
return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr")
994
# TODO: We could ask all the control formats whether they
995
# recognize this directory, but at the moment there's no cheap api
996
# to do that. Since we probably can only nest bzr checkouts and
997
# they always use this name it's ok for now. -- mbp 20060306
999
# FIXME: There is an unhandled case here of a subdirectory
1000
# containing .bzr but not a branch; that will probably blow up
1001
# when you try to commit it. It might happen if there is a
1002
# checkout in a subdirectory. This can be avoided by not adding
946
1005
@needs_tree_write_lock
947
1006
def extract(self, file_id, format=None):
948
1007
"""Extract a subtree from this tree.