/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

Fix support for older versions of Dulwich.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Git inventory."""
19
19
 
20
20
 
21
 
import stat
22
 
 
23
 
 
24
21
from dulwich.objects import (
25
 
    S_ISGITLINK,
26
22
    Blob,
27
23
    Tree,
28
24
    )
33
29
    inventory,
34
30
    osutils,
35
31
    ui,
36
 
    urlutils,
37
32
    )
38
33
 
39
34
from bzrlib.plugins.git.mapping import (
140
135
 
141
136
    def __init__(self, inv, parent_id, hexsha, path, basename, executable):
142
137
        super(GitInventoryTreeReference, self).__init__(inv, parent_id, hexsha, path, basename, executable)
 
138
        self.hexsha = hexsha
 
139
        self.reference_revision = inv.mapping.revision_id_foreign_to_bzr(hexsha)
143
140
        self.text_sha1 = None
144
141
        self.text_size = None
145
142
        self.symlink_target = None
257
254
        self.basis_inv = basis_inventory
258
255
        self.mapping = mapping
259
256
        self.index = index
260
 
 
 
257
        self._contents_read = False
 
258
        self.root = self.add_path("", 'directory', 
 
259
            self.mapping.generate_file_id(""), None)
 
260
 
 
261
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
 
262
        self._read_contents()
 
263
        return super(GitIndexInventory, self).iter_entries_by_dir(specific_file_ids=specific_file_ids, yield_parents=yield_parents)
 
264
 
 
265
    def has_id(self, file_id):
 
266
        try:
 
267
            self.id2path(file_id)
 
268
            return True
 
269
        except errors.NoSuchId:
 
270
            return False
 
271
 
 
272
    def has_filename(self, path):
 
273
        if path in self.index:
 
274
            return True
 
275
        self._read_contents()
 
276
        return super(GitIndexInventory, self).has_filename(path)
 
277
 
 
278
    def id2path(self, file_id):
 
279
        path = self.mapping.parse_file_id(file_id)
 
280
        if path in self.index:
 
281
            return path
 
282
        self._read_contents()
 
283
        return super(GitIndexInventory, self).id2path(file_id)
 
284
 
 
285
    def path2id(self, path):
 
286
        if path in self.index:
 
287
            return self.mapping.generate_file_id(path)
 
288
        self._read_contents()
 
289
        return super(GitIndexInventory, self).path2id(path)
 
290
 
 
291
    def __getitem__(self, file_id):
 
292
        self._read_contents()
 
293
        return super(GitIndexInventory, self).__getitem__(file_id)
 
294
 
 
295
    def _read_contents(self):
 
296
        if self._contents_read:
 
297
            return
 
298
        self._contents_read = True
261
299
        pb = ui.ui_factory.nested_progress_bar()
262
300
        try:
263
301
            for i, (path, value) in enumerate(self.index.iteritems()):
293
331
 
294
332
    def add_parents(self, path):
295
333
        dirname, _ = osutils.split(path)
296
 
        file_id = self.path2id(dirname)
 
334
        file_id = super(GitIndexInventory, self).path2id(dirname)
297
335
        if file_id is None:
298
336
            if dirname == "":
299
337
                parent_fid = None