/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 object_store.py

Add BzrGitCache object.

Show diffs side-by-side

added added

removed removed

Lines of Context:
221
221
            shamap[ie.file_id] = obj.id
222
222
 
223
223
 
224
 
class ObjectStoreUpdater(object):
225
 
 
226
 
    def __init__(self, store, rev):
227
 
        self.store = store
228
 
        self.revid = rev.revision_id
229
 
        self.parent_revids = rev.parent_ids
230
 
        self._commit = None
231
 
        self._entries = []
232
 
 
233
 
    def add_object(self, obj, ie):
234
 
        if obj.type_name == "commit":
235
 
            self._commit = obj
236
 
            assert ie is None
237
 
        elif obj.type_name in ("blob", "tree"):
238
 
            if obj.type_name == "blob":
239
 
                revision = ie.revision
240
 
            else:
241
 
                revision = self.revid
242
 
            self._entries.append((ie.file_id, obj.type_name, obj.id, revision))
243
 
        else:
244
 
            raise AssertionError
245
 
        if (self.store._content_cache and 
246
 
            obj.type_name in self.store._content_cache_types):
247
 
            self.store._content_cache.add(obj)
248
 
 
249
 
    def finish(self):
250
 
        if self._commit is None:
251
 
            raise AssertionError("No commit object added")
252
 
        self.store._idmap.add_entries(self.revid, self.parent_revids,
253
 
            self._commit.id, self._commit.tree, self._entries)
254
 
        return self._commit
255
 
 
256
 
 
257
224
class BazaarObjectStore(BaseObjectStore):
258
225
    """A Git-style object store backed onto a Bazaar repository."""
259
226
 
263
230
            self.mapping = default_mapping
264
231
        else:
265
232
            self.mapping = mapping
266
 
        (self._idmap, self._content_cache) = cache_from_repository(repository)
 
233
        self._cache = cache_from_repository(repository)
267
234
        self._content_cache_types = ("tree")
268
 
        self.start_write_group = self._idmap.start_write_group
269
 
        self.abort_write_group = self._idmap.abort_write_group
270
 
        self.commit_write_group = self._idmap.commit_write_group
 
235
        self.start_write_group = self._cache.idmap.start_write_group
 
236
        self.abort_write_group = self._cache.idmap.abort_write_group
 
237
        self.commit_write_group = self._cache.idmap.commit_write_group
271
238
        self.parent_invs_cache = LRUInventoryCache(self.repository)
272
239
 
273
240
    def _update_sha_map(self, stop_revision=None):
276
243
            heads = graph.heads(self.repository.all_revision_ids())
277
244
        else:
278
245
            heads = set([stop_revision])
279
 
        missing_revids = self._idmap.missing_revisions(heads)
 
246
        missing_revids = self._cache.idmap.missing_revisions(heads)
280
247
        while heads:
281
248
            parents = graph.get_parent_map(heads)
282
249
            todo = set()
283
250
            for p in parents.values():
284
251
                todo.update([x for x in p if x not in missing_revids])
285
 
            heads = self._idmap.missing_revisions(todo)
 
252
            heads = self._cache.idmap.missing_revisions(todo)
286
253
            missing_revids.update(heads)
287
254
        if NULL_REVISION in missing_revids:
288
255
            missing_revids.remove(NULL_REVISION)
307
274
 
308
275
    def __iter__(self):
309
276
        self._update_sha_map()
310
 
        return iter(self._idmap.sha1s())
 
277
        return iter(self._cache.idmap.sha1s())
311
278
 
312
279
    def _revision_to_commit(self, rev, tree_sha):
313
280
        def parent_lookup(revid):
326
293
            [p for p in rev.parent_ids if p in present_parents])
327
294
        tree_sha = None
328
295
        for path, obj, ie in _inventory_to_objects(inv, parent_invs,
329
 
                self._idmap, unusual_modes,
 
296
                self._cache.idmap, unusual_modes,
330
297
                self.repository.iter_files_bytes, has_ghost_parents):
331
298
            yield path, obj, ie
332
299
            if path == "":
347
314
        yield None, commit_obj, None
348
315
 
349
316
    def _get_updater(self, rev):
350
 
        return ObjectStoreUpdater(self, rev)
 
317
        return self._cache.get_updater(rev, self._content_cache_types)
351
318
 
352
319
    def _update_sha_map_revision(self, revid):
353
320
        rev = self.repository.get_revision(revid)
385
352
        def get_ie_sha1(entry):
386
353
            if entry.kind == "directory":
387
354
                try:
388
 
                    return self._idmap.lookup_tree_id(entry.file_id)
 
355
                    return self._cache.idmap.lookup_tree_id(entry.file_id)
389
356
                except (NotImplementedError, KeyError):
390
357
                    obj = self._get_tree(entry.file_id, revid, inv,
391
358
                        unusual_modes)
394
361
                    else:
395
362
                        return obj.id
396
363
            elif entry.kind in ("file", "symlink"):
397
 
                return self._idmap.lookup_blob_id(entry.file_id, entry.revision)
 
364
                return self._cache.idmap.lookup_blob_id(entry.file_id, entry.revision)
398
365
            else:
399
366
                raise AssertionError("unknown entry kind '%s'" % entry.kind)
400
367
        tree = directory_to_tree(inv[fileid], get_ie_sha1, unusual_modes)
414
381
        if revid == NULL_REVISION:
415
382
            return "0" * 40
416
383
        try:
417
 
            return self._idmap.lookup_commit(revid)
 
384
            return self._cache.idmap.lookup_commit(revid)
418
385
        except KeyError:
419
386
            try:
420
387
                return mapping_registry.parse_revision_id(revid)[0]
421
388
            except errors.InvalidRevisionId:
422
389
                self._update_sha_map(revid)
423
 
                return self._idmap.lookup_commit(revid)
 
390
                return self._cache.idmap.lookup_commit(revid)
424
391
 
425
392
    def get_raw(self, sha):
426
393
        """Get the raw representation of a Git object by SHA1.
448
415
    def _lookup_git_sha(self, sha):
449
416
        # See if sha is in map
450
417
        try:
451
 
            return self._idmap.lookup_git_sha(sha)
 
418
            return self._cache.idmap.lookup_git_sha(sha)
452
419
        except KeyError:
453
420
            # if not, see if there are any unconverted revisions and add them
454
421
            # to the map, search for sha in map again
455
422
            self._update_sha_map()
456
 
            return self._idmap.lookup_git_sha(sha)
 
423
            return self._cache.idmap.lookup_git_sha(sha)
457
424
 
458
425
    def __getitem__(self, sha):
459
426
        (type, type_data) = self._lookup_git_sha(sha)
460
 
        if (self._content_cache is not None and 
 
427
        if (self._cache.content_cache is not None and 
461
428
            type in self._content_cache_types):
462
429
            try:
463
 
                return self._content_cache[sha]
 
430
                return self._cache.content_cache[sha]
464
431
            except KeyError:
465
432
                pass
466
433
        # convert object to git object