/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/memorytree.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
See MemoryTree for more details.
20
20
"""
21
21
 
 
22
from __future__ import absolute_import
 
23
 
22
24
import os
23
 
import stat
24
25
 
25
26
from . import (
26
27
    errors,
49
50
        self._locks = 0
50
51
        self._lock_mode = None
51
52
 
52
 
    def supports_symlinks(self):
53
 
        return True
54
 
 
55
 
    def supports_tree_reference(self):
56
 
        return False
57
 
 
58
53
    def get_config_stack(self):
59
54
        return self.branch.get_config_stack()
60
55
 
67
62
        with self.lock_tree_write():
68
63
            for f, file_id, kind in zip(files, ids, kinds):
69
64
                if kind is None:
70
 
                    st_mode = self._file_transport.stat(f).st_mode
71
 
                    if stat.S_ISREG(st_mode):
72
 
                        kind = 'file'
73
 
                    elif stat.S_ISLNK(st_mode):
74
 
                        kind = 'symlink'
75
 
                    elif stat.S_ISDIR(st_mode):
76
 
                        kind = 'directory'
77
 
                    else:
78
 
                        raise AssertionError('Unknown file kind')
 
65
                    kind = 'file'
79
66
                if file_id is None:
80
67
                    self._inventory.add_path(f, kind=kind)
81
68
                else:
98
85
        missing files, so is a no-op.
99
86
        """
100
87
 
101
 
    def get_file(self, path):
 
88
    def get_file(self, path, file_id=None):
102
89
        """See Tree.get_file."""
103
90
        return self._file_transport.get(path)
104
91
 
105
 
    def get_file_sha1(self, path, stat_value=None):
 
92
    def get_file_sha1(self, path, file_id=None, stat_value=None):
106
93
        """See Tree.get_file_sha1()."""
107
94
        stream = self._file_transport.get(path)
108
95
        return sha_file(stream)
109
96
 
 
97
    def get_root_id(self):
 
98
        return self.path2id('')
 
99
 
110
100
    def _comparison_data(self, entry, path):
111
101
        """See Tree._comparison_data."""
112
102
        if entry is None:
131
121
            bytes = self._file_transport.get_bytes(path)
132
122
            size = len(bytes)
133
123
            executable = self._inventory[id].executable
134
 
            sha1 = None  # no stat cache
 
124
            sha1 = None # no stat cache
135
125
            return (kind, size, executable, sha1)
136
126
        elif kind == 'directory':
137
127
            # memory tree does not support nested trees yet.
138
128
            return kind, None, None, None
139
129
        elif kind == 'symlink':
140
 
            return kind, None, None, self._inventory[id].symlink_target
 
130
            raise NotImplementedError('symlink support')
141
131
        else:
142
132
            raise NotImplementedError('unknown kind')
143
133
 
 
134
    def _file_size(self, entry, stat_value):
 
135
        """See Tree._file_size."""
 
136
        if entry is None:
 
137
            return 0
 
138
        return entry.text_size
 
139
 
144
140
    def get_parent_ids(self):
145
141
        """See Tree.get_parent_ids.
146
142
 
154
150
        """See Tree.has_filename()."""
155
151
        return self._file_transport.has(filename)
156
152
 
157
 
    def is_executable(self, path):
158
 
        return self._inventory.get_entry_by_path(path).executable
 
153
    def is_executable(self, path, file_id=None):
 
154
        return self._inventory[file_id].executable
159
155
 
160
 
    def kind(self, path):
161
 
        return self._inventory.get_entry_by_path(path).kind
 
156
    def kind(self, path, file_id=None):
 
157
        if file_id is None:
 
158
            file_id = self.path2id(path)
 
159
        return self._inventory[file_id].kind
162
160
 
163
161
    def mkdir(self, path, file_id=None):
164
162
        """See MutableTree.mkdir()."""
185
183
                self._lock_mode = "r"
186
184
                self._populate_from_branch()
187
185
            return lock.LogicalLockResult(self.unlock)
188
 
        except BaseException:
 
186
        except:
189
187
            self._locks -= 1
190
188
            raise
191
189
 
199
197
                self._populate_from_branch()
200
198
            elif self._lock_mode == "r":
201
199
                raise errors.ReadOnlyError(self)
202
 
        except BaseException:
 
200
        except:
203
201
            self._locks -= 1
204
202
            raise
205
203
        return lock.LogicalLockResult(self.unlock)
215
213
            elif self._lock_mode == "r":
216
214
                raise errors.ReadOnlyError(self)
217
215
            return lock.LogicalLockResult(self.unlock)
218
 
        except BaseException:
 
216
        except:
219
217
            self._locks -= 1
220
218
            raise
221
219
 
236
234
                continue
237
235
            if entry.kind == 'directory':
238
236
                self._file_transport.mkdir(path)
239
 
            elif entry.kind == 'symlink':
240
 
                self._file_transport.symlink(entry.symlink_target, path)
241
237
            elif entry.kind == 'file':
242
 
                self._file_transport.put_file(
243
 
                    path, self._basis_tree.get_file(path))
 
238
                self._file_transport.put_file(path,
 
239
                    self._basis_tree.get_file(path, entry.file_id))
244
240
            else:
245
241
                raise NotImplementedError(self._populate_from_branch)
246
242
 
247
 
    def put_file_bytes_non_atomic(self, path, bytes):
 
243
    def put_file_bytes_non_atomic(self, path, bytes, file_id=None):
248
244
        """See MutableTree.put_file_bytes_non_atomic."""
249
245
        self._file_transport.put_bytes(path, bytes)
250
246
 
266
262
        else:
267
263
            self._locks -= 1
268
264
 
269
 
    def unversion(self, paths):
 
265
    def unversion(self, paths, file_ids=None):
270
266
        """Remove the paths from the current versioned set.
271
267
 
272
268
        When a file_id is unversioned, all of its children are automatically
279
275
            # XXX: This should be in mutabletree, but the inventory-save action
280
276
            # is not relevant to memory tree. Until that is done in unlock by
281
277
            # working tree, we cannot share the implementation.
282
 
            file_ids = set()
283
 
            for path in paths:
284
 
                file_id = self.path2id(path)
285
 
                if file_id is None:
286
 
                    raise errors.NoSuchFile(path)
287
 
                file_ids.add(file_id)
 
278
            if file_ids is None:
 
279
                file_ids = {self.path2id(path) for path in paths}
288
280
            for file_id in file_ids:
289
281
                if self._inventory.has_id(file_id):
290
282
                    self._inventory.remove_recursive_id(file_id)
 
283
                else:
 
284
                    raise errors.NoSuchId(self, file_id)
291
285
 
292
286
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
293
287
        """See MutableTree.set_parent_trees()."""
313
307
            else:
314
308
                raise
315
309
 
316
 
    def get_symlink_target(self, path):
317
 
        with self.lock_read():
318
 
            return self._file_transport.readlink(path)
319
 
 
320
310
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
321
311
        """See MutableTree.set_parent_trees()."""
322
312
        if len(parents_list) == 0:
323
313
            self._parent_ids = []
324
314
            self._basis_tree = self.branch.repository.revision_tree(
325
 
                _mod_revision.NULL_REVISION)
 
315
                                   _mod_revision.NULL_REVISION)
326
316
        else:
327
317
            if parents_list[0][1] is None and not allow_leftmost_as_ghost:
328
318
                # a ghost in the left most parent
329
319
                raise errors.GhostRevisionUnusableHere(parents_list[0][0])
330
320
            self._parent_ids = [parent_id for parent_id, tree in parents_list]
331
 
            if parents_list[0][1] is None or parents_list[0][1] == b'null:':
 
321
            if parents_list[0][1] is None or parents_list[0][1] == 'null:':
332
322
                self._basis_tree = self.branch.repository.revision_tree(
333
 
                    _mod_revision.NULL_REVISION)
 
323
                                       _mod_revision.NULL_REVISION)
334
324
            else:
335
325
                self._basis_tree = parents_list[0][1]
336
326
            self._branch_revision_id = parents_list[0][0]