git-importer/lib/tree_builder.py

42 lines
1.5 KiB
Python
Raw Normal View History

2022-10-22 12:03:21 +02:00
from lib.db_revision import DBRevision
from lib.request import Request
class TreeBuilder:
def __init__(self, db):
self.db = db
def filtered_revisions(self, project, package):
revisions = DBRevision.all_revisions(self.db, project, package)
revisions.sort()
ret = []
prev = None
for rev in revisions:
if rev.broken:
continue
if prev and prev.files_hash == rev.files_hash:
2022-10-22 12:03:21 +02:00
continue
ret.append(rev)
prev = rev
return ret
def build(self, package):
factory_revisions = self.filtered_revisions("openSUSE:Factory", package)
source_revisions = dict()
for rev in factory_revisions:
print(rev, rev.files_hash)
2022-10-22 12:03:21 +02:00
if rev.request_id:
req = Request.find(self.db, rev.request_id)
print(" ", req)
key = f"{req.source_project}/{req.source_package}"
if key not in source_revisions:
source_revisions[key] = self.filtered_revisions(
req.source_project, req.source_package
)
for rev2 in source_revisions.get(key):
2022-10-25 13:24:08 +02:00
# this happened after the fact - possibly a revert
if rev2.commit_time > rev.commit_time:
continue
if rev2.files_hash == rev.files_hash:
2022-10-22 12:03:21 +02:00
print(" ", rev2)