forked from importers/git-importer
Create fake revisions for every commit in the base of a linked package
This is a rather complex operation, but whenever a package changes in Factory, the inherited package gets a shadow revision consisting of the 3-way merge. If this happens due to a request being accepted, this is actually in most cases also commited by 'buildservice-autocommit', so we're making sure this is always happening (and are actually duplicating revisions in cases that we filter out later as empty commits). To differenciate the fake revisions from the real revisions, I add a fraction part
This commit is contained in:
@@ -19,10 +19,10 @@ class DBRevision:
|
||||
self.expanded_srcmd5,
|
||||
self.request_number,
|
||||
self.request_id,
|
||||
self.files_hash,
|
||||
) = row
|
||||
self.rev = int(self.rev)
|
||||
self.rev = float(self.rev)
|
||||
self._files = None
|
||||
self._hash = None
|
||||
|
||||
def __str__(self):
|
||||
return f"Rev {self.project}/{self.package}/{self.rev} Md5 {self.unexpanded_srcmd5} {self.commit_time} {self.userid} {self.request_number}"
|
||||
@@ -52,6 +52,7 @@ class DBRevision:
|
||||
"comment": self.comment,
|
||||
"broken": self.broken,
|
||||
"expanded_srcmd5": self.expanded_srcmd5,
|
||||
"files_hash": self.files_hash,
|
||||
"files": self.files_list(db),
|
||||
}
|
||||
if self.request_id:
|
||||
@@ -92,7 +93,8 @@ class DBRevision:
|
||||
(project, package, str(rev)),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
return DBRevision(row)
|
||||
if row:
|
||||
return DBRevision(row)
|
||||
|
||||
@staticmethod
|
||||
def latest_revision(db, project, package):
|
||||
@@ -103,7 +105,7 @@ class DBRevision:
|
||||
)
|
||||
max = cur.fetchone()[0]
|
||||
if max:
|
||||
return DBRevision.fetch_revision(db, project, package, int(max))
|
||||
return DBRevision.fetch_revision(db, project, package, max)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
@@ -144,7 +146,6 @@ class DBRevision:
|
||||
with db.cursor() as cur:
|
||||
cur.execute("UPDATE revisions SET broken=TRUE where id=%s", (self.dbid,))
|
||||
|
||||
|
||||
def import_dir_list(self, db, xml):
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
@@ -164,9 +165,13 @@ class DBRevision:
|
||||
),
|
||||
)
|
||||
|
||||
def files_hash(self, db):
|
||||
if self._hash:
|
||||
return self._hash
|
||||
def previous_commit(self, db):
|
||||
return self.fetch_revision(db, self.project, self.package, int(self.rev) - 1)
|
||||
|
||||
def next_commit(self, db):
|
||||
return self.fetch_revision(db, self.project, self.package, int(self.rev) + 1)
|
||||
|
||||
def calculate_files_hash(self, db):
|
||||
m = md5()
|
||||
for file_dict in self.files_list(db):
|
||||
m.update(
|
||||
@@ -178,8 +183,7 @@ class DBRevision:
|
||||
+ str(file_dict["size"])
|
||||
).encode("utf-8")
|
||||
)
|
||||
self._hash = m.hexdigest()
|
||||
return self._hash
|
||||
return m.hexdigest()
|
||||
|
||||
def files_list(self, db):
|
||||
if self._files:
|
||||
@@ -194,7 +198,7 @@ class DBRevision:
|
||||
return self._files
|
||||
|
||||
@staticmethod
|
||||
def requests_to_fetch(self, db, project, package):
|
||||
def requests_to_fetch(db, project, package):
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"""SELECT request_number FROM revisions revs LEFT JOIN requests
|
||||
@@ -209,8 +213,9 @@ class DBRevision:
|
||||
"""Used in test cases to read a revision from fixtures into the test database"""
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"""INSERT INTO revisions (project, package, rev, unexpanded_srcmd5, expanded_srcmd5, commit_time, userid, comment, broken)
|
||||
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id""",
|
||||
"""INSERT INTO revisions (project, package, rev, unexpanded_srcmd5, expanded_srcmd5,
|
||||
commit_time, userid, comment, broken, files_hash)
|
||||
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id""",
|
||||
(
|
||||
rev_dict["project"],
|
||||
rev_dict["package"],
|
||||
@@ -221,6 +226,7 @@ class DBRevision:
|
||||
rev_dict["userid"],
|
||||
rev_dict["comment"],
|
||||
rev_dict["broken"],
|
||||
rev_dict["files_hash"],
|
||||
),
|
||||
)
|
||||
rev_id = cur.fetchone()[0]
|
||||
|
Reference in New Issue
Block a user