~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: 2007-02-13 11:48:14 UTC
  • mfrom: (2241.1.20 repoformats)
  • Revision ID: pqm@pqm.ubuntu.com-20070213114814-9606106906ac312f
(mbp) split repository formats into repofmt (r=john)

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.
266
222
            else:
267
223
                raise errors.NoSuchId(self, file_id)
268
224
 
269
 
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
270
 
        """See MutableTree.set_parent_trees()."""
271
 
        for revision_id in revision_ids:
272
 
            _mod_revision.check_not_reserved_id(revision_id)
273
 
        if len(revision_ids) == 0:
274
 
            self._parent_ids = []
275
 
            self._basis_tree = self.branch.repository.revision_tree(None)
276
 
        else:
277
 
            self._parent_ids = revision_ids
278
 
            self._basis_tree = self.branch.repository.revision_tree(
279
 
                                    revision_ids[0])
280
 
            self._branch_revision_id = revision_ids[0]
281
 
 
282
225
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
283
226
        """See MutableTree.set_parent_trees()."""
284
227
        if len(parents_list) == 0:
285
228
            self._parent_ids = []
286
 
            self._basis_tree = self.branch.repository.revision_tree(None)
 
229
            self._basis_tree = self.branch.repository.revisiontree(None)
287
230
        else:
288
231
            if parents_list[0][1] is None and not allow_leftmost_as_ghost:
289
232
                # a ghost in the left most parent
290
233
                raise errors.GhostRevisionUnusableHere(parents_list[0][0])
291
234
            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()
294
 
                self._basis_tree = self.branch.repository.revision_tree(None)
 
235
            if parents_list[0][1] is None:
 
236
                self._basis_tree = self.branch.repository.revisiontree(None)
295
237
            else:
296
238
                self._basis_tree = parents_list[0][1]
297
239
            self._branch_revision_id = parents_list[0][0]