/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

Cope with imports.

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 (
72
67
    _git_class = Blob
73
68
 
74
69
    def __init__(self, inv, parent_id, hexsha, path, basename, executable):
75
 
        super(GitInventoryFile, self).__init__(inv, parent_id, hexsha, path, basename, executable)
 
70
        super(GitInventoryFile, self).__init__(inv, parent_id, hexsha, path,
 
71
            basename, executable)
76
72
        self.kind = 'file'
77
73
        self.text_id = None
78
74
        self.symlink_target = None
100
96
        return ''
101
97
 
102
98
    def copy(self):
103
 
        other = inventory.InventoryFile(self.file_id, self.name, self.parent_id)
 
99
        other = inventory.InventoryFile(self.file_id, self.name,
 
100
            self.parent_id)
104
101
        other.executable = self.executable
105
102
        other.text_id = self.text_id
106
103
        other.text_sha1 = self.text_sha1
129
126
 
130
127
    def copy(self):
131
128
        other = inventory.InventoryLink(self.file_id, self.name, self.parent_id)
 
129
        other.executable = self.executable
132
130
        other.symlink_target = self.symlink_target
133
131
        other.revision = self.revision
134
132
        return other
140
138
 
141
139
    def __init__(self, inv, parent_id, hexsha, path, basename, executable):
142
140
        super(GitInventoryTreeReference, self).__init__(inv, parent_id, hexsha, path, basename, executable)
 
141
        self.hexsha = hexsha
 
142
        self.reference_revision = inv.mapping.revision_id_foreign_to_bzr(hexsha)
143
143
        self.text_sha1 = None
144
144
        self.text_size = None
145
145
        self.symlink_target = None
186
186
            self._children[basename] = kind_class(self._inventory, self.file_id, hexsha, child_path, basename, executable)
187
187
 
188
188
    def copy(self):
189
 
        other = inventory.InventoryDirectory(self.file_id, self.name, 
 
189
        other = inventory.InventoryDirectory(self.file_id, self.name,
190
190
                                             self.parent_id)
191
191
        other.revision = self.revision
192
192
        # note that children are *not* copied; they're pulled across when
208
208
        parts = path.split("/")
209
209
        ie = self.root
210
210
        for name in parts:
211
 
            ie = ie.children[name] 
 
211
            ie = ie.children[name]
212
212
        return ie
213
213
 
214
214
    def has_filename(self, path):
257
257
        self.basis_inv = basis_inventory
258
258
        self.mapping = mapping
259
259
        self.index = index
260
 
 
 
260
        self._contents_read = False
 
261
        self.root = self.add_path("", 'directory',
 
262
            self.mapping.generate_file_id(""), None)
 
263
 
 
264
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
 
265
        self._read_contents()
 
266
        return super(GitIndexInventory, self).iter_entries_by_dir(specific_file_ids=specific_file_ids, yield_parents=yield_parents)
 
267
 
 
268
    def has_id(self, file_id):
 
269
        try:
 
270
            self.id2path(file_id)
 
271
            return True
 
272
        except errors.NoSuchId:
 
273
            return False
 
274
 
 
275
    def has_filename(self, path):
 
276
        if path in self.index:
 
277
            return True
 
278
        self._read_contents()
 
279
        return super(GitIndexInventory, self).has_filename(path)
 
280
 
 
281
    def id2path(self, file_id):
 
282
        path = self.mapping.parse_file_id(file_id)
 
283
        if path in self.index:
 
284
            return path
 
285
        self._read_contents()
 
286
        return super(GitIndexInventory, self).id2path(file_id)
 
287
 
 
288
    def path2id(self, path):
 
289
        if path in self.index:
 
290
            return self.mapping.generate_file_id(path)
 
291
        self._read_contents()
 
292
        return super(GitIndexInventory, self).path2id(path)
 
293
 
 
294
    def __getitem__(self, file_id):
 
295
        self._read_contents()
 
296
        return super(GitIndexInventory, self).__getitem__(file_id)
 
297
 
 
298
    def _read_contents(self):
 
299
        if self._contents_read:
 
300
            return
 
301
        self._contents_read = True
261
302
        pb = ui.ui_factory.nested_progress_bar()
262
303
        try:
263
304
            for i, (path, value) in enumerate(self.index.iteritems()):
264
 
                pb.update("creating working inventory from index", 
 
305
                pb.update("creating working inventory from index",
265
306
                        i, len(self.index))
266
307
                assert isinstance(path, str)
267
308
                assert isinstance(value, tuple) and len(value) == 10
280
321
                    self.add_parents(path)
281
322
                    self.add(old_ie)
282
323
                else:
283
 
                    ie = self.add_path(path, kind, file_id, self.add_parents(path))
 
324
                    ie = self.add_path(path, kind, file_id,
 
325
                        self.add_parents(path))
284
326
                    data = store[sha].data
285
327
                    if kind == "symlink":
286
328
                        ie.symlink_target = data
293
335
 
294
336
    def add_parents(self, path):
295
337
        dirname, _ = osutils.split(path)
296
 
        file_id = self.path2id(dirname)
 
338
        file_id = super(GitIndexInventory, self).path2id(dirname)
297
339
        if file_id is None:
298
340
            if dirname == "":
299
341
                parent_fid = None
300
342
            else:
301
343
                parent_fid = self.add_parents(dirname)
302
 
            ie = self.add_path(dirname, 'directory', 
 
344
            ie = self.add_path(dirname, 'directory',
303
345
                    self.mapping.generate_file_id(dirname), parent_fid)
304
346
            if ie.file_id in self.basis_inv:
305
347
                ie.revision = self.basis_inv[ie.file_id].revision