/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: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

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