/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

ImplementĀ GitDir.destroy_workingtree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
 
57
57
def get_remote_cache_transport():
58
 
    """Retrieve the transport to use when accessing (unwritable) remote 
59
 
    repositories.
60
 
    """
61
58
    return get_transport(get_cache_dir())
62
59
 
63
60
 
101
98
        """Lookup a Git sha in the database.
102
99
        :param sha: Git object sha
103
100
        :return: (type, type_data) with type_data:
104
 
            commit: revid, tree_sha, verifiers
105
 
            blob: fileid, revid
106
 
            tree: fileid, revid
 
101
            revision: revid, tree sha
107
102
        """
108
103
        raise NotImplementedError(self.lookup_git_sha)
109
104
 
222
217
    """Base class for objects that can update a bzr-git cache."""
223
218
 
224
219
    def add_object(self, obj, ie, path):
225
 
        """Add an object.
226
 
 
227
 
        :param obj: Object type ("commit", "blob" or "tree")
228
 
        :param ie: Inventory entry (for blob/tree) or testament_sha in case
229
 
            of commit
230
 
        :param path: Path of the object (optional)
231
 
        """
232
220
        raise NotImplementedError(self.add_object)
233
221
 
234
222
    def finish(self):
266
254
    def add_object(self, obj, ie, path):
267
255
        if obj.type_name == "commit":
268
256
            self._commit = obj
269
 
            assert type(ie) is dict
270
 
            type_data = (self.revid, self._commit.tree, ie)
 
257
            assert ie is None
 
258
            type_data = (self.revid, self._commit.tree)
271
259
            self.cache.idmap._by_revid[self.revid] = obj.id
272
260
        elif obj.type_name in ("blob", "tree"):
273
261
            if ie is not None:
276
264
                else:
277
265
                    revision = self.revid
278
266
                type_data = (ie.file_id, revision)
279
 
                self.cache.idmap._by_fileid.setdefault(type_data[1], {})[type_data[0]] = obj.id
 
267
                self.cache.idmap._by_fileid.setdefault(type_data[1], {})[type_data[0]] =\
 
268
                    obj.id
280
269
        else:
281
270
            raise AssertionError
282
271
        self.cache.idmap._by_sha[obj.id] = (obj.type_name, type_data)
329
318
    def add_object(self, obj, ie, path):
330
319
        if obj.type_name == "commit":
331
320
            self._commit = obj
332
 
            self._testament3_sha1 = ie["testament3-sha1"]
333
 
            assert type(ie) is dict
 
321
            assert ie is None
334
322
        elif obj.type_name == "tree":
335
323
            if ie is not None:
336
324
                self._trees.append((obj.id, ie.file_id, self.revid))
350
338
            "replace into blobs (sha1, fileid, revid) values (?, ?, ?)",
351
339
            self._blobs)
352
340
        self.db.execute(
353
 
            "replace into commits (sha1, revid, tree_sha, testament3_sha1) values (?, ?, ?, ?)",
354
 
            (self._commit.id, self.revid, self._commit.tree, self._testament3_sha1))
 
341
            "replace into commits (sha1, revid, tree_sha) values (?, ?, ?)",
 
342
            (self._commit.id, self.revid, self._commit.tree))
355
343
        return self._commit
356
344
 
357
345
 
406
394
        create unique index if not exists trees_sha1 on trees(sha1);
407
395
        create unique index if not exists trees_fileid_revid on trees(fileid, revid);
408
396
""")
409
 
        try:
410
 
            self.db.executescript(
411
 
                "ALTER TABLE commits ADD testament3_sha1 TEXT;")
412
 
        except sqlite3.OperationalError:
413
 
            pass # Column already exists.
414
397
 
415
398
    def __repr__(self):
416
399
        return "%s(%r)" % (self.__class__.__name__, self.path)
417
 
 
 
400
    
418
401
    def lookup_commit(self, revid):
419
402
        cursor = self.db.execute("select sha1 from commits where revid = ?", 
420
403
            (revid,))
443
426
 
444
427
        :param sha: Git object sha
445
428
        :return: (type, type_data) with type_data:
446
 
            commit: revid, tree sha, verifiers
447
 
            tree: fileid, revid
448
 
            blob: fileid, revid
 
429
            revision: revid, tree sha
449
430
        """
450
 
        row = self.db.execute("select revid, tree_sha, testament3_sha1 from commits where sha1 = ?", (sha,)).fetchone()
 
431
        row = self.db.execute("select revid, tree_sha from commits where sha1 = ?", (sha,)).fetchone()
451
432
        if row is not None:
452
 
            return ("commit", (row[0], row[1], {"testament3-sha1": row[2]}))
 
433
            return ("commit", row)
453
434
        row = self.db.execute("select fileid, revid from blobs where sha1 = ?", (sha,)).fetchone()
454
435
        if row is not None:
455
436
            return ("blob", row)
484
465
        sha = obj.sha().digest()
485
466
        if obj.type_name == "commit":
486
467
            self.db["commit\0" + self.revid] = "\0".join((sha, obj.tree))
487
 
            assert type(ie) is dict, "was %r" % ie
488
 
            type_data = (self.revid, obj.tree, ie["testament3-sha1"])
 
468
            type_data = (self.revid, obj.tree)
489
469
            self._commit = obj
 
470
            assert ie is None
490
471
        elif obj.type_name == "blob":
491
472
            if ie is None:
492
473
                return
580
561
 
581
562
    def lookup_blob_id(self, fileid, revision):
582
563
        return sha_to_hex(self.db["\0".join(("blob", fileid, revision))])
583
 
 
 
564
                
584
565
    def lookup_git_sha(self, sha):
585
566
        """Lookup a Git sha in the database.
586
567
 
587
568
        :param sha: Git object sha
588
569
        :return: (type, type_data) with type_data:
589
 
            commit: revid, tree sha
590
 
            blob: fileid, revid
591
 
            tree: fileid, revid
 
570
            revision: revid, tree sha
592
571
        """
593
572
        if len(sha) == 40:
594
573
            sha = hex_to_sha(sha)
595
574
        data = self.db["git\0" + sha].split("\0")
596
 
        if data[0] == "commit":
597
 
            if len(data) == 3:
598
 
                return (data[0], (data[1], data[2], {}))
599
 
            else:
600
 
                return (data[0], (data[1], data[2], {"testament3-sha1": data[3]}))
601
 
        else:
602
 
            return (data[0], tuple(data[1:]))
 
575
        return (data[0], (data[1], data[2]))
603
576
 
604
577
    def missing_revisions(self, revids):
605
578
        ret = set()
667
640
    def add_object(self, obj, ie, path):
668
641
        if obj.type_name == "commit":
669
642
            self._commit = obj
670
 
            assert type(ie) is dict
 
643
            assert ie is None
671
644
            self.cache.idmap._add_git_sha(obj.id, "commit",
672
 
                (self.revid, obj.tree, ie))
 
645
                (self.revid, obj.tree))
673
646
            self.cache.idmap._add_node(("commit", self.revid, "X"),
674
647
                " ".join((obj.id, obj.tree)))
675
648
            self._cache_objs.add((obj, path))
835
808
    def _add_git_sha(self, hexsha, type, type_data):
836
809
        if hexsha is not None:
837
810
            self._name.update(hexsha)
838
 
            if type == "commit":
839
 
                td = (type_data[0], type_data[1], type_data[2]["testament3-sha1"])
840
 
            else:
841
 
                td = type_data
842
 
            self._add_node(("git", hexsha, "X"), " ".join((type,) + td))
 
811
            self._add_node(("git", hexsha, "X"),
 
812
                " ".join((type, type_data[0], type_data[1])))
843
813
        else:
844
814
            # This object is not represented in Git - perhaps an empty
845
815
            # directory?
851
821
    def lookup_git_sha(self, sha):
852
822
        if len(sha) == 20:
853
823
            sha = sha_to_hex(sha)
854
 
        data = self._get_entry(("git", sha, "X")).split(" ", 3)
855
 
        if data[0] == "commit":
856
 
            return ("commit", (data[1], data[2], {"testament3-sha1": data[3]}))
857
 
        else:
858
 
            return (data[0], tuple(data[1:]))
 
824
        data = self._get_entry(("git", sha, "X")).split(" ", 2)
 
825
        return (data[0], (data[1], data[2]))
859
826
 
860
827
    def revids(self):
861
828
        """List the revision ids known."""