290
295
if isinstance(obj, tuple):
291
296
(type_name, hexsha) = obj
293
type_name = obj.type_name
298
type_name = obj.type_name.decode('ascii')
295
300
if type_name == "commit":
296
301
self._commit = obj
326
331
return self._by_fileid[revision][fileid]
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]):
332
337
def lookup_tree_id(self, fileid, revision):
336
341
return self._by_revid[revid]
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]
345
return self._by_sha.iterkeys()
350
return viewkeys(self._by_sha)
348
353
class SqliteCacheUpdater(CacheUpdater):
359
364
if isinstance(obj, tuple):
360
365
(type_name, hexsha) = obj
362
type_name = obj.type_name
367
type_name = obj.type_name.decode('ascii')
364
369
if type_name == "commit":
365
370
self._commit = obj
649
654
raise KeyError("No cache entry for %r" % revid)
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))])
654
659
def lookup_git_sha(self, sha):
655
660
"""Lookup a Git sha in the database.
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"):
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:])
727
732
if isinstance(obj, tuple):
728
733
(type_name, hexsha) = obj
730
type_name = obj.type_name
735
type_name = obj.type_name.decode('ascii')
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)
747
752
raise AssertionError
890
895
yield (entry[1], entry[2])
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]
895
900
def _add_git_sha(self, hexsha, type, type_data):
896
901
if hexsha is not None:
897
902
self._name.update(hexsha)
903
if type == b"commit":
899
904
td = (type_data[0], type_data[1])
901
906
td += (type_data[2]["testament3-sha1"],)
906
self._add_node(("git", hexsha, "X"), " ".join((type,) + td))
911
self._add_node((b"git", hexsha, b"X"), b" ".join((type,) + td))
908
913
# This object is not represented in Git - perhaps an empty
910
self._name.update(type + " ".join(type_data))
915
self._name.update(type + b" ".join(type_data))
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))
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":
923
928
verifiers = {"testament3-sha1": data[3]}
928
933
yield ("commit", (data[1], data[2], verifiers))
930
yield (data[0], tuple(data[1:]))
935
yield (data[0].decode('ascii'), tuple(data[1:]))
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)):
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
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)):