/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-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

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