forked from importers/git-importer
Calculate the linked revision
This commit is contained in:
parent
fb130bbf6f
commit
d747a3a761
@ -13,12 +13,17 @@ class DBRevision:
|
|||||||
self.requestid,
|
self.requestid,
|
||||||
) = row
|
) = 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):
|
def links_to(self, db, project, package):
|
||||||
db.cursor().execute(
|
db.cursor().execute(
|
||||||
"INSERT INTO links (revision_id, project, package) VALUES (%s,%s,%s)",
|
"INSERT INTO links (revision_id, project, package) VALUES (%s,%s,%s)",
|
||||||
(self.dbid, project, package),
|
(self.dbid, project, package),
|
||||||
)
|
)
|
||||||
print("links_to", project, package)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def import_obs_rev(cls, db, revision):
|
def import_obs_rev(cls, db, revision):
|
||||||
@ -63,3 +68,36 @@ class DBRevision:
|
|||||||
if max:
|
if max:
|
||||||
return DBRevision.fetch_revision(db, project, package, int(max))
|
return DBRevision.fetch_revision(db, project, package, int(max))
|
||||||
return None
|
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
|
||||||
|
@ -133,7 +133,7 @@ class Importer:
|
|||||||
if not latest or rev.rev > latest.rev:
|
if not latest or rev.rev > latest.rev:
|
||||||
dbrev = DBRevision.import_obs_rev(db, rev)
|
dbrev = DBRevision.import_obs_rev(db, rev)
|
||||||
root = rev.read_link()
|
root = rev.read_link()
|
||||||
if root:
|
if root is not None:
|
||||||
tprj = root.get("project") or project
|
tprj = root.get("project") or project
|
||||||
tpkg = root.get("package") or package
|
tpkg = root.get("package") or package
|
||||||
dbrev.links_to(db, tprj, tpkg)
|
dbrev.links_to(db, tprj, tpkg)
|
||||||
@ -152,6 +152,10 @@ class Importer:
|
|||||||
for row in cur.fetchall():
|
for row in cur.fetchall():
|
||||||
(lproject, lpackage) = row
|
(lproject, lpackage) = row
|
||||||
self.update_db_package(db, lproject, lpackage)
|
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()
|
cur.close()
|
||||||
|
|
||||||
def import_all_revisions(self, gc):
|
def import_all_revisions(self, gc):
|
||||||
|
Loading…
Reference in New Issue
Block a user