/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

Special-case NULL_REVISION when looking for Git shas.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
        self.path = path
51
51
        self.revision = self._inventory.revision_id
52
52
        self.executable = executable
53
 
        self.file_id = self._inventory.mapping.generate_file_id(
 
53
        self.file_id = self._inventory.fileid_map.lookup_file_id(
54
54
            path.encode('utf-8'))
55
55
 
56
56
    @property
179
179
        for mode, name, hexsha in self.object.entries():
180
180
            basename = name.decode("utf-8")
181
181
            child_path = osutils.pathjoin(self.path, basename)
 
182
            if self._inventory.mapping.is_control_file(child_path):
 
183
                continue
182
184
            executable = mode_is_executable(mode)
183
185
            kind_class = {'directory': GitInventoryDirectory,
184
186
                          'file': GitInventoryFile,
198
200
 
199
201
class GitInventory(inventory.Inventory):
200
202
 
201
 
    def __init__(self, tree_id, mapping, store, revision_id):
 
203
    def __init__(self, tree_id, mapping, fileid_map, store, revision_id):
202
204
        super(GitInventory, self).__init__(revision_id=revision_id)
203
205
        self.store = store
 
206
        self.fileid_map = fileid_map
204
207
        self.mapping = mapping
205
208
        self.root = GitInventoryDirectory(self, None, tree_id, u"", u"", False)
206
209
 
228
231
            return False
229
232
 
230
233
    def id2path(self, file_id):
231
 
        path = self.mapping.parse_file_id(file_id)
 
234
        path = self.fileid_map.lookup_path(file_id)
232
235
        try:
233
236
            ie = self._get_ie(path)
234
237
            assert ie.path == path
244
247
    def __getitem__(self, file_id):
245
248
        if file_id == inventory.ROOT_ID:
246
249
            return self.root
247
 
        path = self.mapping.parse_file_id(file_id)
 
250
        path = self.fileid_map.lookup_path(file_id)
248
251
        try:
249
252
            return self._get_ie(path)
250
253
        except KeyError:
254
257
class GitIndexInventory(inventory.Inventory):
255
258
    """Inventory that retrieves its contents from an index file."""
256
259
 
257
 
    def __init__(self, basis_inventory, mapping, index, store):
 
260
    def __init__(self, basis_inventory, fileid_map, index, store):
258
261
        super(GitIndexInventory, self).__init__(revision_id=None, root_id=basis_inventory.root.file_id)
259
262
        self.basis_inv = basis_inventory
260
 
        self.mapping = mapping
 
263
        self.fileid_map = fileid_map
261
264
        self.index = index
262
265
        self._contents_read = False
263
266
        self.store = store
264
267
        self.root = self.add_path("", 'directory',
265
 
            self.mapping.generate_file_id(""), None)
 
268
            self.fileid_map.lookup_file_id(""), None)
266
269
 
267
270
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
268
271
        self._read_contents()
287
290
    def id2path(self, file_id):
288
291
        if type(file_id) != str:
289
292
            raise AssertionError
290
 
        path = self.mapping.parse_file_id(file_id)
 
293
        path = self.fileid_map.lookup_path(file_id)
291
294
        if path in self.index:
292
295
            return path
293
296
        self._read_contents()
295
298
 
296
299
    def path2id(self, path):
297
300
        if path in self.index:
298
 
            return self.mapping.generate_file_id(path)
299
 
        self._read_contents()
300
 
        return super(GitIndexInventory, self).path2id(path)
 
301
            file_id = self.fileid_map.lookup_file_id(path)
 
302
        else:
 
303
            self._read_contents()
 
304
            file_id = super(GitIndexInventory, self).path2id(path)
 
305
        if type(file_id) is not str:
 
306
            raise AssertionError
 
307
        return file_id
301
308
 
302
309
    def __getitem__(self, file_id):
303
310
        self._read_contents()
320
327
                except KeyError:
321
328
                    old_ie = None
322
329
                if old_ie is None:
323
 
                    file_id = self.mapping.generate_file_id(path)
 
330
                    file_id = self.fileid_map.lookup_file_id(path)
324
331
                else:
325
332
                    file_id = old_ie.file_id
326
333
                if type(file_id) != str:
352
359
            else:
353
360
                parent_fid = self.add_parents(dirname)
354
361
            ie = self.add_path(dirname, 'directory',
355
 
                    self.mapping.generate_file_id(dirname), parent_fid)
 
362
                    self.fileid_map.lookup_file_id(dirname), parent_fid)
356
363
            if ie.file_id in self.basis_inv:
357
364
                ie.revision = self.basis_inv[ie.file_id].revision
358
365
            file_id = ie.file_id