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

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-07-02 01:50:36 UTC
  • mfrom: (6973.13.15 python3-l)
  • Revision ID: breezy.the.bot@gmail.com-20180702015036-p7h30yemu44e4p01
Fix more tests on Python3.

Merged from https://code.launchpad.net/~jelmer/brz/python3-l/+merge/348782

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    index as _mod_index,
41
41
    versionedfile,
42
42
    )
 
43
from ...sixish import (
 
44
    viewitems,
 
45
    viewkeys,
 
46
    viewvalues,
 
47
    )
43
48
from ...transport import (
44
49
    get_transport,
45
50
    )
290
295
        if isinstance(obj, tuple):
291
296
            (type_name, hexsha) = obj
292
297
        else:
293
 
            type_name = obj.type_name
 
298
            type_name = obj.type_name.decode('ascii')
294
299
            hexsha = obj.id
295
300
        if type_name == "commit":
296
301
            self._commit = obj
326
331
        return self._by_fileid[revision][fileid]
327
332
 
328
333
    def lookup_git_sha(self, sha):
329
 
        for entry in self._by_sha[sha].itervalues():
 
334
        for entry in viewvalues(self._by_sha[sha]):
330
335
            yield entry
331
336
 
332
337
    def lookup_tree_id(self, fileid, revision):
336
341
        return self._by_revid[revid]
337
342
 
338
343
    def revids(self):
339
 
        for key, entries in self._by_sha.iteritems():
 
344
        for key, entries in viewitems(self._by_sha):
340
345
            for (type, type_data) in entries.values():
341
346
                if type == "commit":
342
347
                    yield type_data[0]
343
348
 
344
349
    def sha1s(self):
345
 
        return self._by_sha.iterkeys()
 
350
        return viewkeys(self._by_sha)
346
351
 
347
352
 
348
353
class SqliteCacheUpdater(CacheUpdater):
359
364
        if isinstance(obj, tuple):
360
365
            (type_name, hexsha) = obj
361
366
        else:
362
 
            type_name = obj.type_name
 
367
            type_name = obj.type_name.decode('ascii')
363
368
            hexsha = obj.id
364
369
        if type_name == "commit":
365
370
            self._commit = obj
649
654
            raise KeyError("No cache entry for %r" % revid)
650
655
 
651
656
    def lookup_blob_id(self, fileid, revision):
652
 
        return sha_to_hex(self.db[b"\0".join(("blob", fileid, revision))])
 
657
        return sha_to_hex(self.db[b"\0".join((b"blob", fileid, revision))])
653
658
 
654
659
    def lookup_git_sha(self, sha):
655
660
        """Lookup a Git sha in the database.
685
690
 
686
691
    def revids(self):
687
692
        """List the revision ids known."""
688
 
        for key in self.db.iterkeys():
 
693
        for key in self.db.keys():
689
694
            if key.startswith(b"commit\0"):
690
695
                yield key[7:]
691
696
 
692
697
    def sha1s(self):
693
698
        """List the SHA1s."""
694
 
        for key in self.db.iterkeys():
 
699
        for key in self.db.keys():
695
700
            if key.startswith(b"git\0"):
696
701
                yield sha_to_hex(key[4:])
697
702
 
727
732
        if isinstance(obj, tuple):
728
733
            (type_name, hexsha) = obj
729
734
        else:
730
 
            type_name = obj.type_name
 
735
            type_name = obj.type_name.decode('ascii')
731
736
            hexsha = obj.id
732
737
        if type_name == "commit":
733
738
            self._commit = obj
734
739
            if type(bzr_key_data) is not dict:
735
740
                raise TypeError(bzr_key_data)
736
 
            self.cache.idmap._add_git_sha(hexsha, "commit",
 
741
            self.cache.idmap._add_git_sha(hexsha, b"commit",
737
742
                (self.revid, obj.tree, bzr_key_data))
738
 
            self.cache.idmap._add_node(("commit", self.revid, "X"),
739
 
                " ".join((hexsha, obj.tree)))
 
743
            self.cache.idmap._add_node((b"commit", self.revid, b"X"),
 
744
                b" ".join((hexsha, obj.tree)))
740
745
        elif type_name == "blob":
741
 
            self.cache.idmap._add_git_sha(hexsha, "blob", bzr_key_data)
742
 
            self.cache.idmap._add_node(("blob", bzr_key_data[0],
 
746
            self.cache.idmap._add_git_sha(hexsha, b"blob", bzr_key_data)
 
747
            self.cache.idmap._add_node((b"blob", bzr_key_data[0],
743
748
                bzr_key_data[1]), hexsha)
744
749
        elif type_name == "tree":
745
 
            self.cache.idmap._add_git_sha(hexsha, "tree", bzr_key_data)
 
750
            self.cache.idmap._add_git_sha(hexsha, b"tree", bzr_key_data)
746
751
        else:
747
752
            raise AssertionError
748
753
 
890
895
                yield (entry[1], entry[2])
891
896
 
892
897
    def lookup_commit(self, revid):
893
 
        return self._get_entry(("commit", revid, "X"))[:40]
 
898
        return self._get_entry((b"commit", revid, b"X"))[:40]
894
899
 
895
900
    def _add_git_sha(self, hexsha, type, type_data):
896
901
        if hexsha is not None:
897
902
            self._name.update(hexsha)
898
 
            if type == "commit":
 
903
            if type == b"commit":
899
904
                td = (type_data[0], type_data[1])
900
905
                try:
901
906
                    td += (type_data[2]["testament3-sha1"],)
903
908
                    pass
904
909
            else:
905
910
                td = type_data
906
 
            self._add_node(("git", hexsha, "X"), " ".join((type,) + td))
 
911
            self._add_node((b"git", hexsha, b"X"), b" ".join((type,) + td))
907
912
        else:
908
913
            # This object is not represented in Git - perhaps an empty
909
914
            # directory?
910
 
            self._name.update(type + " ".join(type_data))
 
915
            self._name.update(type + b" ".join(type_data))
911
916
 
912
917
    def lookup_blob_id(self, fileid, revision):
913
 
        return self._get_entry(("blob", fileid, revision))
 
918
        return self._get_entry((b"blob", fileid, revision))
914
919
 
915
920
    def lookup_git_sha(self, sha):
916
921
        if len(sha) == 20:
917
922
            sha = sha_to_hex(sha)
918
 
        value = self._get_entry(("git", sha, "X"))
919
 
        data = value.split(" ", 3)
920
 
        if data[0] == "commit":
 
923
        value = self._get_entry((b"git", sha, b"X"))
 
924
        data = value.split(b" ", 3)
 
925
        if data[0] == b"commit":
921
926
            try:
922
927
                if data[3]:
923
928
                    verifiers = {"testament3-sha1": data[3]}
927
932
                verifiers = {}
928
933
            yield ("commit", (data[1], data[2], verifiers))
929
934
        else:
930
 
            yield (data[0], tuple(data[1:]))
 
935
            yield (data[0].decode('ascii'), tuple(data[1:]))
931
936
 
932
937
    def revids(self):
933
938
        """List the revision ids known."""
934
 
        for key, value in self._iter_entries_prefix(("commit", None, None)):
 
939
        for key, value in self._iter_entries_prefix((b"commit", None, None)):
935
940
            yield key[1]
936
941
 
937
942
    def missing_revisions(self, revids):
938
943
        """Return set of all the revisions that are not present."""
939
944
        missing_revids = set(revids)
940
945
        for _, key, value in self._index.iter_entries((
941
 
            ("commit", revid, "X") for revid in revids)):
 
946
            (b"commit", revid, b"X") for revid in revids)):
942
947
            missing_revids.remove(key[1])
943
948
        return missing_revids
944
949
 
945
950
    def sha1s(self):
946
951
        """List the SHA1s."""
947
 
        for key, value in self._iter_entries_prefix(("git", None, None)):
 
952
        for key, value in self._iter_entries_prefix((b"git", None, None)):
948
953
            yield key[1]
949
954
 
950
955