Calculate the linked revision

This commit is contained in:
Stephan Kulow 2022-10-18 15:40:11 +02:00
parent fb130bbf6f
commit d747a3a761
2 changed files with 44 additions and 2 deletions

View File

@ -13,12 +13,17 @@ class DBRevision:
self.requestid,
) = row
def __str__(self):
return f"Rev {self.project}/{self.rev} Md5 {self.unexpanded_srcmd5} {self.commit_time} {self.userid} {self.requestid}"
def __repr__(self):
return f"[{self.__str__()}]"
def links_to(self, db, project, package):
db.cursor().execute(
"INSERT INTO links (revision_id, project, package) VALUES (%s,%s,%s)",
(self.dbid, project, package),
)
print("links_to", project, package)
@classmethod
def import_obs_rev(cls, db, revision):
@ -63,3 +68,36 @@ class DBRevision:
if max:
return DBRevision.fetch_revision(db, project, package, int(max))
return None
@classmethod
def all_revisions(cls, db, project, package):
cur = db.cursor()
cur.execute(
"SELECT * FROM revisions where project=%s and package=%s",
(project, package),
)
ret = []
for row in cur.fetchall():
ret.append(DBRevision(row))
cur.close()
return ret
def linked_rev(self, db):
cur = db.cursor()
cur.execute(
"SELECT project,package FROM links where revision_id=%s", (self.dbid,)
)
row = cur.fetchone()
if not row:
cur.close()
return None
project, package = row
cur.execute(
"SELECT * FROM revisions where project=%s and package=%s and commit_time <= %s ORDER BY commit_time DESC LIMIT 1",
(project, package, self.commit_time),
)
revisions = [DBRevision(row) for row in cur.fetchall()]
cur.close()
if revisions:
return revisions[0]
return None

View File

@ -133,7 +133,7 @@ class Importer:
if not latest or rev.rev > latest.rev:
dbrev = DBRevision.import_obs_rev(db, rev)
root = rev.read_link()
if root:
if root is not None:
tprj = root.get("project") or project
tpkg = root.get("package") or package
dbrev.links_to(db, tprj, tpkg)
@ -152,6 +152,10 @@ class Importer:
for row in cur.fetchall():
(lproject, lpackage) = row
self.update_db_package(db, lproject, lpackage)
for rev in DBRevision.all_revisions(db, project, self.package):
print(rev, rev.linked_rev(db))
cur.close()
def import_all_revisions(self, gc):