49
51
def __init__(self, transport):
50
52
self.transport = transport
53
self.db = sqlite3.connect(
54
os.path.join(self.transport.local_abspath("."), "git.db"))
55
self.db.executescript("""
56
create table if not exists commits(sha1 text, revid text, tree_sha text);
57
create index if not exists commit_sha1 on commits(sha1);
58
create table if not exists blobs(sha1 text, fileid text, revid text);
59
create index if not exists blobs_sha1 on blobs(sha1);
60
create table if not exists trees(sha1 text, fileid text, revid text);
61
create index if not exists trees_sha1 on trees(sha1);
52
64
def add_entry(self, sha, type, type_data):
53
65
"""Add a new entry to the database.
55
raise NotImplementedError(self.add_entry)
68
self.db.execute("replace into commits (sha1, revid, tree_sha) values (?, ?, ?)", (sha, type_data[0], type_data[1]))
70
self.db.execute("replace into blobs (sha1, fileid, revid) values (?, ?, ?)", (sha, type_data[0], type_data[1]))
72
self.db.execute("replace into trees (sha1, fileid, revid) values (?, ?, ?)", (sha, type_data[0], type_data[1]))
74
raise AssertionError("Unknown type %s" % type)
57
76
def lookup_git_sha(self, sha):
58
77
"""Lookup a Git sha in the database.
61
80
:return: (type, type_data) with type_data:
62
81
revision: revid, tree sha
64
raise NotImplementedError(self.lookup_git_sha)
83
row = self.db.execute("select revid, tree_sha from commits where sha1 = ?", (sha,)).fetchone()
85
return ("commit", row)
86
row = self.db.execute("select fileid, revid from blobs where sha1 = ?", (sha,)).fetchone()
89
row = self.db.execute("select fileid, revid from trees where sha1 = ?", (sha,)).fetchone()
95
for row in self.db.execute("select revid from commits").fetchall():