/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 inventory.py

Update docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
 
24
24
from dulwich.objects import (
25
 
    S_ISGITLINK,
26
25
    Blob,
27
26
    Tree,
28
27
    )
36
35
    urlutils,
37
36
    )
38
37
 
39
 
from bzrlib.plugins.git.mapping import (
40
 
    mode_kind,
41
 
    mode_is_executable,
42
 
    )
43
 
 
44
38
 
45
39
class GitInventoryEntry(inventory.InventoryEntry):
46
40
 
134
128
        return other
135
129
 
136
130
 
137
 
class GitInventoryTreeReference(GitInventoryEntry):
138
 
 
139
 
    _git_class = None
140
 
 
141
 
    def __init__(self, inv, parent_id, hexsha, path, basename, executable):
142
 
        super(GitInventoryTreeReference, self).__init__(inv, parent_id, hexsha, path, basename, executable)
143
 
        self.text_sha1 = None
144
 
        self.text_size = None
145
 
        self.symlink_target = None
146
 
        self.kind = 'tree-reference'
147
 
        self._children = None
148
 
 
149
 
    def kind_character(self):
150
 
        """See InventoryEntry.kind_character."""
151
 
        return '/'
152
 
 
153
 
 
154
131
class GitInventoryDirectory(GitInventoryEntry):
155
132
 
156
133
    _git_class = Tree
178
155
        for mode, name, hexsha in self.object.entries():
179
156
            basename = name.decode("utf-8")
180
157
            child_path = osutils.pathjoin(self.path, basename)
181
 
            executable = mode_is_executable(mode)
182
 
            kind_class = {'directory': GitInventoryDirectory,
183
 
                          'file': GitInventoryFile,
184
 
                          'symlink': GitInventoryLink,
185
 
                          'tree-reference': GitInventoryTreeReference}[mode_kind(mode)]
 
158
            entry_kind = (mode & 0700000) / 0100000
 
159
            fs_mode = mode & 0777
 
160
            executable = bool(fs_mode & 0111)
 
161
            if entry_kind == 0:
 
162
                kind_class = GitInventoryDirectory
 
163
            elif entry_kind == 1:
 
164
                file_kind = (mode & 070000) / 010000
 
165
                if file_kind == 0:
 
166
                    kind_class = GitInventoryFile
 
167
                elif file_kind == 2:
 
168
                    kind_class = GitInventoryLink
 
169
                else:
 
170
                    raise AssertionError(
 
171
                        "Unknown file kind, perms=%o." % (mode,))
 
172
            else:
 
173
                raise AssertionError(
 
174
                    "Unknown blob kind, perms=%r." % (mode,))
186
175
            self._children[basename] = kind_class(self._inventory, self.file_id, hexsha, child_path, basename, executable)
187
176
 
188
177
    def copy(self):
203
192
        self.root = GitInventoryDirectory(self, None, tree_id, u"", u"", False)
204
193
 
205
194
    def _get_ie(self, path):
206
 
        if path == "":
207
 
            return self.root
208
195
        parts = path.split("/")
209
196
        ie = self.root
210
197
        for name in parts:
252
239
class GitIndexInventory(inventory.Inventory):
253
240
    """Inventory that retrieves its contents from an index file."""
254
241
 
255
 
    def __init__(self, basis_inventory, mapping, index, store):
 
242
    def __init__(self, basis_inventory, mapping, index):
256
243
        super(GitIndexInventory, self).__init__(revision_id=None, root_id=basis_inventory.root.file_id)
257
244
        self.basis_inv = basis_inventory
258
245
        self.mapping = mapping
265
252
                        i, len(self.index))
266
253
                assert isinstance(path, str)
267
254
                assert isinstance(value, tuple) and len(value) == 10
268
 
                (ctime, mtime, dev, ino, mode, uid, gid, size, sha, flags) = value
 
255
                (ctime, mtime, ino, dev, mode, uid, gid, size, sha, flags) = value
269
256
                try:
270
257
                    old_ie = self.basis_inv._get_ie(path)
271
258
                except KeyError:
274
261
                    file_id = self.mapping.generate_file_id(path)
275
262
                else:
276
263
                    file_id = old_ie.file_id
277
 
                kind = mode_kind(mode)
 
264
                if stat.S_ISLNK(mode):
 
265
                    kind = 'symlink'
 
266
                else:
 
267
                    assert stat.S_ISREG(mode)
 
268
                    kind = 'file'
278
269
                if old_ie is not None and old_ie.hexsha == sha:
279
270
                    # Hasn't changed since basis inv
280
271
                    self.add_parents(path)
281
272
                    self.add(old_ie)
282
273
                else:
283
274
                    ie = self.add_path(path, kind, file_id, self.add_parents(path))
284
 
                    data = store[sha].data
285
 
                    if kind == "symlink":
286
 
                        ie.symlink_target = data
287
 
                    else:
288
 
                        ie.text_sha1 = osutils.sha_string(data)
289
 
                        ie.text_size = len(data)
290
275
                    ie.revision = None
291
276
        finally:
292
277
            pb.finished()