/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

Abstract out kind mapping a bit, initial work on support tree-references.

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,
25
26
    Blob,
26
27
    Tree,
27
28
    )
35
36
    urlutils,
36
37
    )
37
38
 
 
39
from bzrlib.plugins.git.mapping import (
 
40
    mode_kind,
 
41
    mode_is_executable,
 
42
    )
 
43
 
38
44
 
39
45
class GitInventoryEntry(inventory.InventoryEntry):
40
46
 
128
134
        return other
129
135
 
130
136
 
 
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
 
131
154
class GitInventoryDirectory(GitInventoryEntry):
132
155
 
133
156
    _git_class = Tree
155
178
        for mode, name, hexsha in self.object.entries():
156
179
            basename = name.decode("utf-8")
157
180
            child_path = osutils.pathjoin(self.path, basename)
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,))
 
181
            executable = mode_is_executable(mode)
 
182
            kind_class = {'directory': GitInventoryDirectory,
 
183
                          'file': GitInventoryFile,
 
184
                          'symlink': GitInventoryLink,
 
185
                          'tree-reference': GitInventoryTreeReference}[mode_kind(mode)]
175
186
            self._children[basename] = kind_class(self._inventory, self.file_id, hexsha, child_path, basename, executable)
176
187
 
177
188
    def copy(self):
265
276
                    file_id = old_ie.file_id
266
277
                if stat.S_ISLNK(mode):
267
278
                    kind = 'symlink'
 
279
                elif S_ISGITLINK(mode):
 
280
                    kind = 'tree-reference'
268
281
                else:
269
282
                    assert stat.S_ISREG(mode)
270
283
                    kind = 'file'