~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: 2009-01-13 05:14:24 UTC
  • mfrom: (3936.1.3 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090113051424-nrk3zkfe09h46i9y
(mbp) merge 1.11 and advance to 1.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
 
23
23
from copy import deepcopy
 
24
import os
24
25
 
25
 
from bzrlib import errors, mutabletree
 
26
from bzrlib import (
 
27
    errors,
 
28
    mutabletree,
 
29
    osutils,
 
30
    revision as _mod_revision,
 
31
    )
26
32
from bzrlib.decorators import needs_read_lock, needs_write_lock
27
33
from bzrlib.osutils import sha_file
28
34
from bzrlib.mutabletree import needs_tree_write_lock
63
69
    @staticmethod
64
70
    def create_on_branch(branch):
65
71
        """Create a MemoryTree for branch, using the last-revision of branch."""
66
 
        return MemoryTree(branch, branch.last_revision())
 
72
        revision_id = _mod_revision.ensure_null(branch.last_revision())
 
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
    @needs_tree_write_lock
 
105
    def rename_one(self, from_rel, to_rel):
 
106
        file_id = self.path2id(from_rel)
 
107
        to_dir, to_tail = os.path.split(to_rel)
 
108
        to_parent_id = self.path2id(to_dir)
 
109
        self._file_transport.move(from_rel, to_rel)
 
110
        self._inventory.rename(file_id, to_parent_id, to_tail)
 
111
 
 
112
    def path_content_summary(self, path):
 
113
        """See Tree.path_content_summary."""
 
114
        id = self.path2id(path)
 
115
        if id is None:
 
116
            return 'missing', None, None, None
 
117
        kind = self.kind(id)
 
118
        if kind == 'file':
 
119
            bytes = self._file_transport.get_bytes(path)
 
120
            size = len(bytes)
 
121
            executable = self._inventory[id].executable
 
122
            sha1 = None # no stat cache
 
123
            return (kind, size, executable, sha1)
 
124
        elif kind == 'directory':
 
125
            # memory tree does not support nested trees yet.
 
126
            return kind, None, None, None
 
127
        elif kind == 'symlink':
 
128
            raise NotImplementedError('symlink support')
 
129
        else:
 
130
            raise NotImplementedError('unknown kind')
 
131
 
 
132
    def _file_size(self, entry, stat_value):
 
133
        """See Tree._file_size."""
 
134
        if entry is None:
 
135
            return 0
 
136
        return entry.text_size
 
137
 
86
138
    @needs_read_lock
87
139
    def get_parent_ids(self):
88
140
        """See Tree.get_parent_ids.
99
151
    def is_executable(self, file_id, path=None):
100
152
        return self._inventory[file_id].executable
101
153
 
 
154
    def kind(self, file_id):
 
155
        return self._inventory[file_id].kind
 
156
 
102
157
    def mkdir(self, path, file_id=None):
103
158
        """See MutableTree.mkdir()."""
104
159
        self.add(path, file_id, 'directory')
159
214
        """Populate the in-tree state from the branch."""
160
215
        self._basis_tree = self.branch.repository.revision_tree(
161
216
            self._branch_revision_id)
162
 
        if self._branch_revision_id is None:
 
217
        if self._branch_revision_id == _mod_revision.NULL_REVISION:
163
218
            self._parent_ids = []
164
219
        else:
165
220
            self._parent_ids = [self._branch_revision_id]
219
274
            else:
220
275
                raise errors.NoSuchId(self, file_id)
221
276
 
 
277
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
 
278
        """See MutableTree.set_parent_trees()."""
 
279
        for revision_id in revision_ids:
 
280
            _mod_revision.check_not_reserved_id(revision_id)
 
281
        if len(revision_ids) == 0:
 
282
            self._parent_ids = []
 
283
            self._basis_tree = self.branch.repository.revision_tree(
 
284
                                    _mod_revision.NULL_REVISION)
 
285
        else:
 
286
            self._parent_ids = revision_ids
 
287
            self._basis_tree = self.branch.repository.revision_tree(
 
288
                                    revision_ids[0])
 
289
            self._branch_revision_id = revision_ids[0]
 
290
 
222
291
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
223
292
        """See MutableTree.set_parent_trees()."""
224
293
        if len(parents_list) == 0:
225
294
            self._parent_ids = []
226
 
            self._basis_tree = self.branch.repository.revisiontree(None)
 
295
            self._basis_tree = self.branch.repository.revision_tree(
 
296
                                   _mod_revision.NULL_REVISION)
227
297
        else:
228
298
            if parents_list[0][1] is None and not allow_leftmost_as_ghost:
229
299
                # a ghost in the left most parent
230
300
                raise errors.GhostRevisionUnusableHere(parents_list[0][0])
231
301
            self._parent_ids = [parent_id for parent_id, tree in parents_list]
232
 
            if parents_list[0][1] is None:
233
 
                self._basis_tree = self.branch.repository.revisiontree(None)
 
302
            if parents_list[0][1] is None or parents_list[0][1] == 'null:':
 
303
                self._basis_tree = self.branch.repository.revision_tree(
 
304
                                       _mod_revision.NULL_REVISION)
234
305
            else:
235
306
                self._basis_tree = parents_list[0][1]
236
307
            self._branch_revision_id = parents_list[0][0]