/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

mark remote git directories as not supporting working trees.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
        """Lookup a Git sha in the database.
102
102
        :param sha: Git object sha
103
103
        :return: (type, type_data) with type_data:
104
 
            commit: revid, tree_sha, verifiers
105
 
            blob: fileid, revid
106
 
            tree: fileid, revid
 
104
            revision: revid, tree sha
107
105
        """
108
106
        raise NotImplementedError(self.lookup_git_sha)
109
107
 
222
220
    """Base class for objects that can update a bzr-git cache."""
223
221
 
224
222
    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
223
        raise NotImplementedError(self.add_object)
233
224
 
234
225
    def finish(self):
266
257
    def add_object(self, obj, ie, path):
267
258
        if obj.type_name == "commit":
268
259
            self._commit = obj
269
 
            assert type(ie) is dict
270
 
            type_data = (self.revid, self._commit.tree, ie)
 
260
            assert ie is None
 
261
            type_data = (self.revid, self._commit.tree)
271
262
            self.cache.idmap._by_revid[self.revid] = obj.id
272
263
        elif obj.type_name in ("blob", "tree"):
273
264
            if ie is not None:
276
267
                else:
277
268
                    revision = self.revid
278
269
                type_data = (ie.file_id, revision)
279
 
                self.cache.idmap._by_fileid.setdefault(type_data[1], {})[type_data[0]] = obj.id
 
270
                self.cache.idmap._by_fileid.setdefault(type_data[1], {})[type_data[0]] =\
 
271
                    obj.id
280
272
        else:
281
273
            raise AssertionError
282
274
        self.cache.idmap._by_sha[obj.id] = (obj.type_name, type_data)
329
321
    def add_object(self, obj, ie, path):
330
322
        if obj.type_name == "commit":
331
323
            self._commit = obj
332
 
            self._testament3_sha1 = ie["testament3-sha1"]
333
 
            assert type(ie) is dict
 
324
            assert ie is None
334
325
        elif obj.type_name == "tree":
335
326
            if ie is not None:
336
327
                self._trees.append((obj.id, ie.file_id, self.revid))
350
341
            "replace into blobs (sha1, fileid, revid) values (?, ?, ?)",
351
342
            self._blobs)
352
343
        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))
 
344
            "replace into commits (sha1, revid, tree_sha) values (?, ?, ?)",
 
345
            (self._commit.id, self.revid, self._commit.tree))
355
346
        return self._commit
356
347
 
357
348
 
406
397
        create unique index if not exists trees_sha1 on trees(sha1);
407
398
        create unique index if not exists trees_fileid_revid on trees(fileid, revid);
408
399
""")
409
 
        try:
410
 
            self.db.executescript(
411
 
                "ALTER TABLE commits ADD testament3_sha1 TEXT;")
412
 
        except sqlite3.OperationalError:
413
 
            pass # Column already exists.
414
400
 
415
401
    def __repr__(self):
416
402
        return "%s(%r)" % (self.__class__.__name__, self.path)
417
 
 
 
403
    
418
404
    def lookup_commit(self, revid):
419
405
        cursor = self.db.execute("select sha1 from commits where revid = ?", 
420
406
            (revid,))
443
429
 
444
430
        :param sha: Git object sha
445
431
        :return: (type, type_data) with type_data:
446
 
            commit: revid, tree sha, verifiers
447
 
            tree: fileid, revid
448
 
            blob: fileid, revid
 
432
            revision: revid, tree sha
449
433
        """
450
 
        row = self.db.execute("select revid, tree_sha, testament3_sha1 from commits where sha1 = ?", (sha,)).fetchone()
 
434
        row = self.db.execute("select revid, tree_sha from commits where sha1 = ?", (sha,)).fetchone()
451
435
        if row is not None:
452
 
            return ("commit", (row[0], row[1], {"testament3-sha1": row[2]}))
 
436
            return ("commit", row)
453
437
        row = self.db.execute("select fileid, revid from blobs where sha1 = ?", (sha,)).fetchone()
454
438
        if row is not None:
455
439
            return ("blob", row)
484
468
        sha = obj.sha().digest()
485
469
        if obj.type_name == "commit":
486
470
            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"])
 
471
            type_data = (self.revid, obj.tree)
489
472
            self._commit = obj
 
473
            assert ie is None
490
474
        elif obj.type_name == "blob":
491
475
            if ie is None:
492
476
                return
580
564
 
581
565
    def lookup_blob_id(self, fileid, revision):
582
566
        return sha_to_hex(self.db["\0".join(("blob", fileid, revision))])
583
 
 
 
567
                
584
568
    def lookup_git_sha(self, sha):
585
569
        """Lookup a Git sha in the database.
586
570
 
587
571
        :param sha: Git object sha
588
572
        :return: (type, type_data) with type_data:
589
 
            commit: revid, tree sha
590
 
            blob: fileid, revid
591
 
            tree: fileid, revid
 
573
            revision: revid, tree sha
592
574
        """
593
575
        if len(sha) == 40:
594
576
            sha = hex_to_sha(sha)
595
577
        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:]))
 
578
        return (data[0], (data[1], data[2]))
603
579
 
604
580
    def missing_revisions(self, revids):
605
581
        ret = set()
667
643
    def add_object(self, obj, ie, path):
668
644
        if obj.type_name == "commit":
669
645
            self._commit = obj
670
 
            assert type(ie) is dict
 
646
            assert ie is None
671
647
            self.cache.idmap._add_git_sha(obj.id, "commit",
672
 
                (self.revid, obj.tree, ie))
 
648
                (self.revid, obj.tree))
673
649
            self.cache.idmap._add_node(("commit", self.revid, "X"),
674
650
                " ".join((obj.id, obj.tree)))
675
651
            self._cache_objs.add((obj, path))
835
811
    def _add_git_sha(self, hexsha, type, type_data):
836
812
        if hexsha is not None:
837
813
            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))
 
814
            self._add_node(("git", hexsha, "X"),
 
815
                " ".join((type, type_data[0], type_data[1])))
843
816
        else:
844
817
            # This object is not represented in Git - perhaps an empty
845
818
            # directory?
851
824
    def lookup_git_sha(self, sha):
852
825
        if len(sha) == 20:
853
826
            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:]))
 
827
        data = self._get_entry(("git", sha, "X")).split(" ", 2)
 
828
        return (data[0], (data[1], data[2]))
859
829
 
860
830
    def revids(self):
861
831
        """List the revision ids known."""