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

Write git pack files rather than loose objects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
class ContentCache(object):
144
144
    """Object that can cache Git objects."""
145
145
 
 
146
    def add(self, object):
 
147
        """Add an object."""
 
148
        raise NotImplementedError(self.add)
 
149
 
 
150
    def add_multi(self, objects):
 
151
        """Add multiple objects."""
 
152
        for obj in objects:
 
153
            self.add(obj)
 
154
 
146
155
    def __getitem__(self, sha):
147
156
        """Retrieve an item, by SHA."""
148
157
        raise NotImplementedError(self.__getitem__)
207
216
class CacheUpdater(object):
208
217
    """Base class for objects that can update a bzr-git cache."""
209
218
 
210
 
    def add_object(self, obj, ie):
 
219
    def add_object(self, obj, ie, path):
211
220
        raise NotImplementedError(self.add_object)
212
221
 
213
222
    def finish(self):
242
251
        self._commit = None
243
252
        self._entries = []
244
253
 
245
 
    def add_object(self, obj, ie):
 
254
    def add_object(self, obj, ie, path):
246
255
        if obj.type_name == "commit":
247
256
            self._commit = obj
248
257
            assert ie is None
306
315
        self._trees = []
307
316
        self._blobs = []
308
317
 
309
 
    def add_object(self, obj, ie):
 
318
    def add_object(self, obj, ie, path):
310
319
        if obj.type_name == "commit":
311
320
            self._commit = obj
312
321
            assert ie is None
452
461
        self._commit = None
453
462
        self._entries = []
454
463
 
455
 
    def add_object(self, obj, ie):
 
464
    def add_object(self, obj, ie, path):
456
465
        sha = obj.sha().digest()
457
466
        if obj.type_name == "commit":
458
467
            self.db["commit\0" + self.revid] = "\0".join((sha, obj.tree))
608
617
    def __init__(self, store):
609
618
        self.store = store
610
619
 
611
 
    def add(self, obj):
 
620
    def add_multi(self, objs):
 
621
        self.store.add_objects(objs)
 
622
 
 
623
    def add(self, obj, path):
612
624
        self.store.add_object(obj)
613
625
 
614
626
    def __getitem__(self, sha):
623
635
        self.parent_revids = rev.parent_ids
624
636
        self._commit = None
625
637
        self._entries = []
 
638
        self._cache_objs = set()
626
639
 
627
 
    def add_object(self, obj, ie):
 
640
    def add_object(self, obj, ie, path):
628
641
        if obj.type_name == "commit":
629
642
            self._commit = obj
630
643
            assert ie is None
632
645
                (self.revid, obj.tree))
633
646
            self.cache.idmap._add_node(("commit", self.revid, "X"),
634
647
                " ".join((obj.id, obj.tree)))
635
 
            self.cache.content_cache.add(obj)
 
648
            self._cache_objs.add((obj, path))
636
649
        elif obj.type_name == "blob":
637
650
            self.cache.idmap._add_git_sha(obj.id, "blob",
638
651
                (ie.file_id, ie.revision))
639
652
            self.cache.idmap._add_node(("blob", ie.file_id, ie.revision), obj.id)
640
653
            if ie.kind == "symlink":
641
 
                self.cache.content_cache.add(obj)
 
654
                self._cache_objs.add((obj, path))
642
655
        elif obj.type_name == "tree":
643
656
            self.cache.idmap._add_git_sha(obj.id, "tree",
644
657
                (ie.file_id, self.revid))
645
 
            self.cache.content_cache.add(obj)
 
658
            self._cache_objs.add((obj, path))
646
659
        else:
647
660
            raise AssertionError
648
661
 
649
662
    def finish(self):
 
663
        self.cache.content_cache.add_multi(self._cache_objs)
650
664
        return self._commit
651
665
 
652
666