271
275
if not "version" in self.db:
272
276
self.db["version"] = str(TDB_MAP_VERSION)
274
assert int(self.db["version"]) == TDB_MAP_VERSION
278
if int(self.db["version"]) != TDB_MAP_VERSION:
279
trace.warning("SHA Map is incompatible (%s -> %d), rebuilding database.",
280
self.db["version"], TDB_MAP_VERSION)
282
self.db["version"] = str(TDB_MAP_VERSION)
277
285
def from_repository(cls, repository):
285
293
return cls(os.path.join(config_dir(), "remote-git.tdb"))
287
295
def lookup_commit(self, revid):
288
return self.db["commit %s" % revid].split(" ")[0]
296
return sha_to_hex(self.db["commit\0" + revid][:20])
290
298
def commit(self):
293
301
def add_entry(self, sha, type, type_data):
294
302
"""Add a new entry to the database.
296
self.db["git %s" % sha] = "%s %s %s" % (type, type_data[0], type_data[1])
304
self.db["git\0" + hex_to_sha(sha)] = "\0".join((type, type_data[0], type_data[1]))
297
305
if type == "commit":
298
self.db["commit %s" % type_data[0]] = "%s %s" % (sha, type_data[1])
306
self.db["commit\0" + type_data[0]] = "\0".join((hex_to_sha(sha), type_data[1]))
300
self.db["%s %s %s" % (type, type_data[0], type_data[1])] = sha
308
self.db["\0".join((type, type_data[0], type_data[1]))] = hex_to_sha(sha)
302
310
def lookup_tree(self, fileid, revid):
303
return self.db["tree %s %s" % (fileid, revid)]
311
return sha_to_hex(self.db["\0".join(("tree", fileid, revid))])
305
313
def lookup_blob(self, fileid, revid):
306
return self.db["blob %s %s" % (fileid, revid)]
314
return sha_to_hex(self.db["\0".join(("blob", fileid, revid))])
308
316
def lookup_git_sha(self, sha):
309
317
"""Lookup a Git sha in the database.
312
320
:return: (type, type_data) with type_data:
313
321
revision: revid, tree sha
315
data = self.db["git %s" % sha].split(" ")
323
data = self.db["git\0" + hex_to_sha(sha)].split("\0")
316
324
return (data[0], (data[1], data[2]))
318
326
def revids(self):
319
327
"""List the revision ids known."""
320
328
for key in self.db.iterkeys():
321
if key.startswith("commit "):
322
yield key.split(" ")[1]
329
if key.startswith("commit\0"):
325
333
"""List the SHA1s."""
326
334
for key in self.db.iterkeys():
327
if key.startswith("git "):
328
yield key.split(" ")[1]
335
if key.startswith("git\0"):
336
yield sha_to_hex(key[4:])