~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/memorytree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-01-02 08:23:44 UTC
  • mfrom: (3140.1.9 find-branches)
  • Revision ID: pqm@pqm.ubuntu.com-20080102082344-qret383z2bdk1ud4
Optimize find_branches for standalone repositories (abentley)

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 errors, mutabletree
 
25
from bzrlib import (
 
26
    errors,
 
27
    mutabletree,
 
28
    revision as _mod_revision,
 
29
    )
26
30
from bzrlib.decorators import needs_read_lock, needs_write_lock
27
31
from bzrlib.osutils import sha_file
28
32
from bzrlib.mutabletree import needs_tree_write_lock
63
67
    @staticmethod
64
68
    def create_on_branch(branch):
65
69
        """Create a MemoryTree for branch, using the last-revision of branch."""
66
 
        return MemoryTree(branch, branch.last_revision())
 
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)
67
74
 
68
75
    def _gather_kinds(self, files, kinds):
69
76
        """See MutableTree._gather_kinds.
72
79
        missing files, so is a no-op.
73
80
        """
74
81
 
75
 
    def get_file(self, file_id):
 
82
    def get_file(self, file_id, path=None):
76
83
        """See Tree.get_file."""
77
 
        return self._file_transport.get(self.id2path(file_id))
 
84
        if path is None:
 
85
            path = self.id2path(file_id)
 
86
        return self._file_transport.get(path)
78
87
 
79
 
    def get_file_sha1(self, file_id, path=None):
 
88
    def get_file_sha1(self, file_id, path=None, stat_value=None):
80
89
        """See Tree.get_file_sha1()."""
81
90
        if path is None:
82
91
            path = self.id2path(file_id)
83
92
        stream = self._file_transport.get(path)
84
93
        return sha_file(stream)
85
94
 
 
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
 
86
130
    @needs_read_lock
87
131
    def get_parent_ids(self):
88
132
        """See Tree.get_parent_ids.
224
268
 
225
269
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
226
270
        """See MutableTree.set_parent_trees()."""
 
271
        for revision_id in revision_ids:
 
272
            _mod_revision.check_not_reserved_id(revision_id)
227
273
        if len(revision_ids) == 0:
228
274
            self._parent_ids = []
229
275
            self._basis_tree = self.branch.repository.revision_tree(None)
243
289
                # a ghost in the left most parent
244
290
                raise errors.GhostRevisionUnusableHere(parents_list[0][0])
245
291
            self._parent_ids = [parent_id for parent_id, tree in parents_list]
246
 
            if parents_list[0][1] is None:
 
292
            if parents_list[0][1] is None or parents_list[0][1] == 'null:':
 
293
                import pdb; pdb.set_trace()
247
294
                self._basis_tree = self.branch.repository.revision_tree(None)
248
295
            else:
249
296
                self._basis_tree = parents_list[0][1]