~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/memorytree.py

  • Committer: John Arbash Meinel
  • Date: 2007-05-04 18:59:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070504185936-1mjdoqmtz74xe5mg
A C implementation of _fields_to_entry_0_parents drops the time from 400ms to 330ms for a 21k-entry tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from copy import deepcopy
24
24
 
25
 
from bzrlib import (
26
 
    errors,
27
 
    mutabletree,
28
 
    revision as _mod_revision,
29
 
    )
 
25
from bzrlib import errors, mutabletree
30
26
from bzrlib.decorators import needs_read_lock, needs_write_lock
31
27
from bzrlib.osutils import sha_file
32
28
from bzrlib.mutabletree import needs_tree_write_lock
67
63
    @staticmethod
68
64
    def create_on_branch(branch):
69
65
        """Create a MemoryTree for branch, using the last-revision of branch."""
70
 
        revision_id = _mod_revision.ensure_null(branch.last_revision())
71
 
        if _mod_revision.is_null(revision_id):
72
 
            revision_id = None
73
 
        return MemoryTree(branch, revision_id)
 
66
        return MemoryTree(branch, branch.last_revision())
74
67
 
75
68
    def _gather_kinds(self, files, kinds):
76
69
        """See MutableTree._gather_kinds.
79
72
        missing files, so is a no-op.
80
73
        """
81
74
 
82
 
    def get_file(self, file_id, path=None):
 
75
    def get_file(self, file_id):
83
76
        """See Tree.get_file."""
84
 
        if path is None:
85
 
            path = self.id2path(file_id)
86
 
        return self._file_transport.get(path)
 
77
        return self._file_transport.get(self.id2path(file_id))
87
78
 
88
 
    def get_file_sha1(self, file_id, path=None, stat_value=None):
 
79
    def get_file_sha1(self, file_id, path=None):
89
80
        """See Tree.get_file_sha1()."""
90
81
        if path is None:
91
82
            path = self.id2path(file_id)
92
83
        stream = self._file_transport.get(path)
93
84
        return sha_file(stream)
94
85
 
95
 
    def get_root_id(self):
96
 
        return self.path2id('')
97
 
 
98
 
    def _comparison_data(self, entry, path):
99
 
        """See Tree._comparison_data."""
100
 
        if entry is None:
101
 
            return None, False, None
102
 
        return entry.kind, entry.executable, None
103
 
 
104
 
    def path_content_summary(self, path):
105
 
        """See Tree.path_content_summary."""
106
 
        id = self.path2id(path)
107
 
        if id is None:
108
 
            return 'missing', None, None, None
109
 
        kind = self.kind(id)
110
 
        if kind == 'file':
111
 
            bytes = self._file_transport.get_bytes(path)
112
 
            size = len(bytes)
113
 
            executable = self._inventory[id].executable
114
 
            sha1 = None # no stat cache
115
 
            return (kind, size, executable, sha1)
116
 
        elif kind == 'directory':
117
 
            # memory tree does not support nested trees yet.
118
 
            return kind, None, None, None
119
 
        elif kind == 'symlink':
120
 
            raise NotImplementedError('symlink support')
121
 
        else:
122
 
            raise NotImplementedError('unknown kind')
123
 
 
124
 
    def _file_size(self, entry, stat_value):
125
 
        """See Tree._file_size."""
126
 
        if entry is None:
127
 
            return 0
128
 
        return entry.text_size
129
 
 
130
86
    @needs_read_lock
131
87
    def get_parent_ids(self):
132
88
        """See Tree.get_parent_ids.
268
224
 
269
225
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
270
226
        """See MutableTree.set_parent_trees()."""
271
 
        for revision_id in revision_ids:
272
 
            _mod_revision.check_not_reserved_id(revision_id)
273
227
        if len(revision_ids) == 0:
274
228
            self._parent_ids = []
275
229
            self._basis_tree = self.branch.repository.revision_tree(None)
289
243
                # a ghost in the left most parent
290
244
                raise errors.GhostRevisionUnusableHere(parents_list[0][0])
291
245
            self._parent_ids = [parent_id for parent_id, tree in parents_list]
292
 
            if parents_list[0][1] is None or parents_list[0][1] == 'null:':
293
 
                import pdb; pdb.set_trace()
 
246
            if parents_list[0][1] is None:
294
247
                self._basis_tree = self.branch.repository.revision_tree(None)
295
248
            else:
296
249
                self._basis_tree = parents_list[0][1]