241
241
for table in ("blobs", "commits", "trees"):
242
242
for row in self.db.execute("select sha1 from %s" % table).fetchall():
243
243
yield row[0].encode("utf-8")
246
class TdbGitShaMap(GitShaMap):
247
"""SHA Map that uses a TDB database.
251
commit/sha1 -> revid tree-id
252
tree/sha1 -> revid file-id
253
blob/sha1 -> revid file-id
256
def __init__(self, path=None):
262
if not mapdbs().has_key(path):
263
mapdbs()[path] = tdb.open(path, 0, tdb.DEFAULT,
264
os.O_RDWR|os.O_CREAT)
265
self.db = mapdbs()[path]
268
def from_repository(cls, repository):
269
return cls(os.path.join(repository._transport.local_abspath("."), "git.tdb"))
271
def _parent_lookup(self, revid):
272
row = self.db.execute("select sha1 from commits where revid = ?", (revid,)).fetchone()
274
return row[0].encode("utf-8")
280
def add_entry(self, sha, type, type_data):
281
"""Add a new entry to the database.
283
self.db["%s/%s" % (type, sha)] = "%s %s" % type_data
285
def lookup_tree(self, fileid, revid):
286
row = self.db.execute("select sha1 from trees where fileid = ? and revid = ?", (fileid,revid)).fetchone()
288
raise KeyError((fileid, revid))
289
return row[0].encode("utf-8")
291
def lookup_blob(self, fileid, revid):
292
row = self.db.execute("select sha1 from blobs where fileid = ? and revid = ?", (fileid, revid)).fetchone()
294
raise KeyError((fileid, revid))
295
return row[0].encode("utf-8")
297
def lookup_git_sha(self, sha):
298
"""Lookup a Git sha in the database.
300
:param sha: Git object sha
301
:return: (type, type_data) with type_data:
302
revision: revid, tree sha
304
for type in ("commit", "blob", "tree"):
306
return (type, tuple(self.db["%s/%s" % (type, sha)].split(" ")))
312
"""List the revision ids known."""
313
for key in self.db.iterkeys():
314
if key.startswith("commit/"):
315
yield self.db[key].split(" ")[0]
318
"""List the SHA1s."""
319
for key in self.db.iterkeys():
320
if (key.startswith("tree/") or key.startswith("blob/") or
321
key.startswith("commit/")):
322
yield key.split("/")[1]