/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/plugins/git/memorytree.py

Merge test-run support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
    osutils,
38
38
    revision as _mod_revision,
39
39
    tree as _mod_tree,
40
 
    urlutils,
41
40
    )
42
41
from breezy.transport.memory import MemoryTransport
43
42
 
 
43
from .mapping import GitFileIdMap
44
44
from .tree import MutableGitIndexTree
45
45
 
46
 
 
47
 
class GitMemoryTree(MutableGitIndexTree, _mod_tree.Tree):
 
46
class GitMemoryTree(MutableGitIndexTree,_mod_tree.Tree):
48
47
    """A Git memory tree."""
49
48
 
50
49
    def __init__(self, branch, store, head):
57
56
        self._lock_mode = None
58
57
        self._populate_from_branch()
59
58
 
60
 
    def _supports_executable(self):
61
 
        return True
62
 
 
63
59
    @property
64
60
    def controldir(self):
65
61
        return self.branch.controldir
75
71
                if kinds[pos] is None:
76
72
                    kinds[pos] = self.kind(f)
77
73
 
78
 
    def put_file_bytes_non_atomic(self, path, bytes):
 
74
    def put_file_bytes_non_atomic(self, path, bytes, file_id=None):
79
75
        """See MutableTree.put_file_bytes_non_atomic."""
80
76
        self._file_transport.put_bytes(path, bytes)
81
77
 
88
84
        self._file_transport = MemoryTransport()
89
85
        if self.branch.head is None:
90
86
            tree = Tree()
 
87
            self._basis_fileid_map = GitFileIdMap({}, self.mapping)
91
88
        else:
92
89
            tree_id = self.store[self.branch.head].tree
 
90
            self._basis_fileid_map = self.mapping.get_fileid_map(
 
91
                self.store.__getitem__, tree_id)
93
92
            tree = self.store[tree_id]
 
93
        self._fileid_map = self._basis_fileid_map.copy()
94
94
 
95
95
        trees = [("", tree)]
96
96
        while trees:
97
97
            (path, tree) = trees.pop()
98
98
            for name, mode, sha in tree.iteritems():
99
 
                subpath = posixpath.join(path, name.decode('utf-8'))
 
99
                subpath = posixpath.join(path, name)
100
100
                if stat.S_ISDIR(mode):
101
101
                    self._file_transport.mkdir(subpath)
102
102
                    trees.append((subpath, self.store[sha]))
103
103
                elif stat.S_ISREG(mode):
104
 
                    self._file_transport.put_bytes(
105
 
                        subpath, self.store[sha].data)
 
104
                    self._file_transport.put_bytes(subpath, self.store[sha].data)
106
105
                    self._index_add_entry(subpath, 'file')
107
106
                else:
108
107
                    raise NotImplementedError(self._populate_from_branch)
119
118
                self._lock_mode = "r"
120
119
                self._populate_from_branch()
121
120
            return lock.LogicalLockResult(self.unlock)
122
 
        except BaseException:
 
121
        except:
123
122
            self._locks -= 1
124
123
            raise
125
124
 
133
132
                self._populate_from_branch()
134
133
            elif self._lock_mode == "r":
135
134
                raise errors.ReadOnlyError(self)
136
 
        except BaseException:
 
135
        except:
137
136
            self._locks -= 1
138
137
            raise
139
138
        return lock.LogicalLockResult(self.unlock)
149
148
            elif self._lock_mode == "r":
150
149
                raise errors.ReadOnlyError(self)
151
150
            return lock.LogicalLockResult(self.unlock)
152
 
        except BaseException:
 
151
        except:
153
152
            self._locks -= 1
154
153
            raise
155
154
 
177
176
        return stat_val
178
177
 
179
178
    def _live_entry(self, path):
180
 
        path = urlutils.quote_from_bytes(path)
181
179
        stat_val = self._lstat(path)
182
180
        if stat.S_ISDIR(stat_val.st_mode):
183
181
            return None
184
182
        elif stat.S_ISLNK(stat_val.st_mode):
185
 
            blob = Blob.from_string(
186
 
                self._file_transport.readlink(path).encode('utf-8'))
 
183
            blob = Blob.from_string(self._file_transport.readlink(path))
187
184
        elif stat.S_ISREG(stat_val.st_mode):
188
185
            blob = Blob.from_string(self._file_transport.get_bytes(path))
189
186
        else:
190
187
            raise AssertionError('unknown type %d' % stat_val.st_mode)
191
188
        return index_entry_from_stat(stat_val, blob.id, 0)
192
189
 
193
 
    def get_file_with_stat(self, path):
194
 
        return (self.get_file(path), self._lstat(path))
 
190
    def get_file_with_stat(self, path, file_id=None):
 
191
        return (self.get_file(path, file_id), self._lstat(path))
195
192
 
196
 
    def get_file(self, path):
 
193
    def get_file(self, path, file_id=None):
197
194
        """See Tree.get_file."""
198
195
        return self._file_transport.get(path)
199
196
 
200
 
    def get_file_sha1(self, path, stat_value=None):
 
197
    def get_file_sha1(self, path, file_id=None, stat_value=None):
201
198
        """See Tree.get_file_sha1()."""
202
199
        stream = self._file_transport.get(path)
203
200
        return osutils.sha_file(stream)
216
213
        with self.lock_read():
217
214
            if self.branch.head is None:
218
215
                return _mod_revision.NULL_REVISION
219
 
            return self.branch.repository.lookup_foreign_revision_id(
220
 
                self.branch.head)
 
216
            return self.branch.repository.lookup_foreign_revision_id(self.branch.head)
221
217
 
222
218
    def basis_tree(self):
223
219
        """See Tree.basis_tree()."""
242
238
            self.branch.head = None
243
239
        else:
244
240
            self._parent_ids = parent_ids
245
 
            self.branch.head = self.branch.repository.lookup_bzr_revision_id(
246
 
                parent_ids[0])[0]
 
241
            self.branch.head = self.branch.repository.lookup_bzr_revision_id(parent_ids[0])[0]
247
242
 
248
243
    def mkdir(self, path, file_id=None):
249
244
        """See MutableTree.mkdir()."""
256
251
    def kind(self, p):
257
252
        stat_value = self._file_transport.stat(p)
258
253
        return osutils.file_kind_from_stat_mode(stat_value.st_mode)
259
 
 
260
 
    def get_symlink_target(self, path):
261
 
        with self.lock_read():
262
 
            return self._file_transport.readlink(path)