/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

Use BZR_PLUGINS_AT.

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(path.encode('utf-8'))
 
53
        self.file_id = self._inventory.fileid_map.lookup_file_id(
 
54
            path.encode('utf-8'))
54
55
 
55
56
    @property
56
57
    def object(self):
75
76
 
76
77
    @property
77
78
    def text_sha1(self):
78
 
        return osutils.sha_string(self.object.data)
 
79
        return osutils.sha_strings(self.object.chunked)
79
80
 
80
81
    @property
81
82
    def text_size(self):
126
127
 
127
128
    def copy(self):
128
129
        other = inventory.InventoryLink(self.file_id, self.name, self.parent_id)
 
130
        other.executable = self.executable
129
131
        other.symlink_target = self.symlink_target
130
132
        other.revision = self.revision
131
133
        return other
177
179
        for mode, name, hexsha in self.object.entries():
178
180
            basename = name.decode("utf-8")
179
181
            child_path = osutils.pathjoin(self.path, basename)
 
182
            if self._inventory.mapping.is_control_file(child_path):
 
183
                continue
180
184
            executable = mode_is_executable(mode)
181
185
            kind_class = {'directory': GitInventoryDirectory,
182
186
                          'file': GitInventoryFile,
183
187
                          'symlink': GitInventoryLink,
184
188
                          'tree-reference': GitInventoryTreeReference}[mode_kind(mode)]
185
 
            self._children[basename] = kind_class(self._inventory, self.file_id, hexsha, child_path, basename, executable)
 
189
            self._children[basename] = kind_class(self._inventory,
 
190
                self.file_id, hexsha, child_path, basename, executable)
186
191
 
187
192
    def copy(self):
188
193
        other = inventory.InventoryDirectory(self.file_id, self.name,
195
200
 
196
201
class GitInventory(inventory.Inventory):
197
202
 
198
 
    def __init__(self, tree_id, mapping, store, revision_id):
 
203
    def __init__(self, tree_id, mapping, fileid_map, store, revision_id):
199
204
        super(GitInventory, self).__init__(revision_id=revision_id)
200
205
        self.store = store
 
206
        self.fileid_map = fileid_map
201
207
        self.mapping = mapping
202
208
        self.root = GitInventoryDirectory(self, None, tree_id, u"", u"", False)
203
209
 
225
231
            return False
226
232
 
227
233
    def id2path(self, file_id):
228
 
        path = self.mapping.parse_file_id(file_id)
 
234
        path = self.fileid_map.lookup_path(file_id)
229
235
        try:
230
236
            ie = self._get_ie(path)
231
237
            assert ie.path == path
241
247
    def __getitem__(self, file_id):
242
248
        if file_id == inventory.ROOT_ID:
243
249
            return self.root
244
 
        path = self.mapping.parse_file_id(file_id)
 
250
        path = self.fileid_map.lookup_path(file_id)
245
251
        try:
246
252
            return self._get_ie(path)
247
253
        except KeyError:
251
257
class GitIndexInventory(inventory.Inventory):
252
258
    """Inventory that retrieves its contents from an index file."""
253
259
 
254
 
    def __init__(self, basis_inventory, mapping, index, store):
 
260
    def __init__(self, basis_inventory, fileid_map, index, store):
255
261
        super(GitIndexInventory, self).__init__(revision_id=None, root_id=basis_inventory.root.file_id)
256
262
        self.basis_inv = basis_inventory
257
 
        self.mapping = mapping
 
263
        self.fileid_map = fileid_map
258
264
        self.index = index
259
265
        self._contents_read = False
 
266
        self.store = store
260
267
        self.root = self.add_path("", 'directory',
261
 
            self.mapping.generate_file_id(""), None)
 
268
            self.fileid_map.lookup_file_id(""), None)
262
269
 
263
270
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
264
271
        self._read_contents()
265
 
        return super(GitIndexInventory, self).iter_entries_by_dir(specific_file_ids=specific_file_ids, yield_parents=yield_parents)
 
272
        return super(GitIndexInventory, self).iter_entries_by_dir(
 
273
            specific_file_ids=specific_file_ids, yield_parents=yield_parents)
266
274
 
267
275
    def has_id(self, file_id):
 
276
        if type(file_id) != str:
 
277
            raise AssertionError
268
278
        try:
269
279
            self.id2path(file_id)
270
280
            return True
278
288
        return super(GitIndexInventory, self).has_filename(path)
279
289
 
280
290
    def id2path(self, file_id):
281
 
        path = self.mapping.parse_file_id(file_id)
 
291
        if type(file_id) != str:
 
292
            raise AssertionError
 
293
        path = self.fileid_map.lookup_path(file_id)
282
294
        if path in self.index:
283
295
            return path
284
296
        self._read_contents()
286
298
 
287
299
    def path2id(self, path):
288
300
        if path in self.index:
289
 
            return self.mapping.generate_file_id(path)
 
301
            return self.fileid_map.lookup_file_id(path)
290
302
        self._read_contents()
291
303
        return super(GitIndexInventory, self).path2id(path)
292
304
 
311
323
                except KeyError:
312
324
                    old_ie = None
313
325
                if old_ie is None:
314
 
                    file_id = self.mapping.generate_file_id(path)
 
326
                    file_id = self.fileid_map.lookup_file_id(path)
315
327
                else:
316
328
                    file_id = old_ie.file_id
 
329
                if type(file_id) != str:
 
330
                    raise AssertionError
317
331
                kind = mode_kind(mode)
318
332
                if old_ie is not None and old_ie.hexsha == sha:
319
333
                    # Hasn't changed since basis inv
322
336
                else:
323
337
                    ie = self.add_path(path, kind, file_id,
324
338
                        self.add_parents(path))
325
 
                    data = store[sha].data
 
339
                    data = self.store[sha].data
326
340
                    if kind == "symlink":
327
341
                        ie.symlink_target = data
328
342
                    else:
341
355
            else:
342
356
                parent_fid = self.add_parents(dirname)
343
357
            ie = self.add_path(dirname, 'directory',
344
 
                    self.mapping.generate_file_id(dirname), parent_fid)
 
358
                    self.fileid_map.lookup_file_id(dirname), parent_fid)
345
359
            if ie.file_id in self.basis_inv:
346
360
                ie.revision = self.basis_inv[ie.file_id].revision
347
361
            file_id = ie.file_id
 
362
        if type(file_id) != str:
 
363
            raise AssertionError
348
364
        return file_id
349
365