/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: Martin
  • Date: 2018-11-18 19:48:57 UTC
  • mto: This revision was merged to the branch mainline in revision 7205.
  • Revision ID: gzlist@googlemail.com-20181118194857-mqty4xka790jf934
Fix remaining whitespace lint in codebase

Enables rules W191, W291, W293, and W391 for flake8.

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:
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
 
159
147
    def is_executable(self, path):
160
148
        return self._inventory.get_entry_by_path(path).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()."""
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
232
                self._file_transport.put_file(
245
233
                    path, self._basis_tree.get_file(path))
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)
 
279
            else:
 
280
                for file_id in file_ids:
 
281
                    if not self._inventory.has_id(file_id):
 
282
                        raise errors.NoSuchId(self, file_id)
290
283
            for file_id in file_ids:
291
284
                if self._inventory.has_id(file_id):
292
285
                    self._inventory.remove_recursive_id(file_id)
315
308
            else:
316
309
                raise
317
310
 
318
 
    def get_symlink_target(self, path):
319
 
        with self.lock_read():
320
 
            return self._file_transport.readlink(path)
321
 
 
322
311
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
323
312
        """See MutableTree.set_parent_trees()."""
324
313
        if len(parents_list) == 0: