~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Martin Pool
  • Date: 2009-06-19 09:06:56 UTC
  • mfrom: (4463 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4464.
  • Revision ID: mbp@sourcefrog.net-20090619090656-d5weqeecyscv8kqp
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
451
451
            path = self.id2path(file_id)
452
452
        file_obj = self.get_file_byname(path, filtered=False)
453
453
        stat_value = _fstat(file_obj.fileno())
454
 
        if self.supports_content_filtering() and filtered:
 
454
        if filtered and self.supports_content_filtering():
455
455
            filters = self._content_filter_stack(path)
456
456
            file_obj = filtered_input_file(file_obj, filters)
457
457
        return (file_obj, stat_value)
462
462
    def get_file_byname(self, filename, filtered=True):
463
463
        path = self.abspath(filename)
464
464
        f = file(path, 'rb')
465
 
        if self.supports_content_filtering() and filtered:
 
465
        if filtered and self.supports_content_filtering():
466
466
            filters = self._content_filter_stack(filename)
467
467
            return filtered_input_file(f, filters)
468
468
        else:
1115
1115
    def _kind(self, relpath):
1116
1116
        return osutils.file_kind(self.abspath(relpath))
1117
1117
 
1118
 
    def list_files(self, include_root=False):
1119
 
        """Recursively list all files as (path, class, kind, id, entry).
 
1118
    def list_files(self, include_root=False, from_dir=None, recursive=True):
 
1119
        """List all files as (path, class, kind, id, entry).
1120
1120
 
1121
1121
        Lists, but does not descend into unversioned directories.
1122
 
 
1123
1122
        This does not include files that have been deleted in this
1124
 
        tree.
 
1123
        tree. Skips the control directory.
1125
1124
 
1126
 
        Skips the control directory.
 
1125
        :param include_root: if True, do not return an entry for the root
 
1126
        :param from_dir: start from this directory or None for the root
 
1127
        :param recursive: whether to recurse into subdirectories or not
1127
1128
        """
1128
1129
        # list_files is an iterator, so @needs_read_lock doesn't work properly
1129
1130
        # with it. So callers should be careful to always read_lock the tree.
1131
1132
            raise errors.ObjectNotLocked(self)
1132
1133
 
1133
1134
        inv = self.inventory
1134
 
        if include_root is True:
 
1135
        if from_dir is None and include_root is True:
1135
1136
            yield ('', 'V', 'directory', inv.root.file_id, inv.root)
1136
1137
        # Convert these into local objects to save lookup times
1137
1138
        pathjoin = osutils.pathjoin
1144
1145
        fk_entries = {'directory':TreeDirectory, 'file':TreeFile, 'symlink':TreeLink}
1145
1146
 
1146
1147
        # directory file_id, relative path, absolute path, reverse sorted children
1147
 
        children = os.listdir(self.basedir)
 
1148
        if from_dir is not None:
 
1149
            from_dir_id = inv.path2id(from_dir)
 
1150
            if from_dir_id is None:
 
1151
                # Directory not versioned
 
1152
                return
 
1153
            from_dir_abspath = pathjoin(self.basedir, from_dir)
 
1154
        else:
 
1155
            from_dir_id = inv.root.file_id
 
1156
            from_dir_abspath = self.basedir
 
1157
        children = os.listdir(from_dir_abspath)
1148
1158
        children.sort()
1149
1159
        # jam 20060527 The kernel sized tree seems equivalent whether we
1150
1160
        # use a deque and popleft to keep them sorted, or if we use a plain
1151
1161
        # list and just reverse() them.
1152
1162
        children = collections.deque(children)
1153
 
        stack = [(inv.root.file_id, u'', self.basedir, children)]
 
1163
        stack = [(from_dir_id, u'', from_dir_abspath, children)]
1154
1164
        while stack:
1155
1165
            from_dir_id, from_dir_relpath, from_dir_abspath, children = stack[-1]
1156
1166
 
1214
1224
                if fk != 'directory':
1215
1225
                    continue
1216
1226
 
1217
 
                # But do this child first
1218
 
                new_children = os.listdir(fap)
1219
 
                new_children.sort()
1220
 
                new_children = collections.deque(new_children)
1221
 
                stack.append((f_ie.file_id, fp, fap, new_children))
1222
 
                # Break out of inner loop,
1223
 
                # so that we start outer loop with child
1224
 
                break
 
1227
                # But do this child first if recursing down
 
1228
                if recursive:
 
1229
                    new_children = os.listdir(fap)
 
1230
                    new_children.sort()
 
1231
                    new_children = collections.deque(new_children)
 
1232
                    stack.append((f_ie.file_id, fp, fap, new_children))
 
1233
                    # Break out of inner loop,
 
1234
                    # so that we start outer loop with child
 
1235
                    break
1225
1236
            else:
1226
1237
                # if we finished all children, pop it off the stack
1227
1238
                stack.pop()