diff --git a/git-importer.py b/git-importer.py index cf45294..549d3e2 100755 --- a/git-importer.py +++ b/git-importer.py @@ -130,6 +130,7 @@ def main(): if args.db: importer.import_into_db() + importer.export_as_git() return importer.import_all_revisions(args.gc) diff --git a/lib/importer.py b/lib/importer.py index 82e21ac..3dc6da2 100644 --- a/lib/importer.py +++ b/lib/importer.py @@ -259,6 +259,10 @@ class Importer: ) return [DBRevision(row) for row in cur.fetchall()] + def export_as_git(self): + db = DB() + TreeBuilder(db).build(self.package).print() + def import_into_db(self): db = DB() for project, _, api_url in self.projects: @@ -303,7 +307,6 @@ class Importer: self.obs.request(number).import_into_db(db) db.conn.commit() - TreeBuilder(db).build(self.package).print() def import_all_revisions(self, gc): # Fetch all the requests and sort them. Ideally we should diff --git a/lib/tree_builder.py b/lib/tree_builder.py index 4cb6439..41baa32 100644 --- a/lib/tree_builder.py +++ b/lib/tree_builder.py @@ -2,6 +2,19 @@ from lib.db_revision import DBRevision from lib.request import Request +class AbstractWalker: + def call(self, node, is_source): + pass + + +class PrintWalker(AbstractWalker): + def call(self, node, is_source): + if is_source: + print(" ", node.revision, node.revision.files_hash) + else: + print(node.revision, node.revision.files_hash) + + class TreeNode: """ Nodes in this "tree" have either no parent (root), one parent (in a chain) @@ -13,20 +26,24 @@ class TreeNode: self.merged = None self.revision = rev self.merged_into = None + self.git_commit = None - def print(self): + def walk(self, walker: AbstractWalker): node = self while node: - print(node.revision, node.revision.files_hash) + walker.call(node, False) if node.merged: source_node = node.merged while source_node: - print(" ", source_node.revision, source_node.revision.files_hash) + walker.call(node, True) source_node = source_node.parent if source_node and source_node.merged_into: break node = node.parent + def print(self): + self.walk(PrintWalker()) + def as_list(self): """Return a list for test cases""" node = self @@ -51,6 +68,8 @@ class TreeBuilder: self.db = db def revisions_chain(self, project, package): + """Build a tree without branches (chain) from a project's + history ignoring empty and broken revisions""" revisions = DBRevision.all_revisions(self.db, project, package) revisions.sort() prev = None @@ -69,6 +88,8 @@ class TreeBuilder: return tree def find_merge(self, revision, source_chain): + """For a given revision in the target, find the node in the source chain + that matches the files""" node = source_chain while node: # exclude reverts happening after the merge @@ -80,6 +101,8 @@ class TreeBuilder: node = node.parent def add_merge_points(self, factory_revisions): + """For all target revisions that accepted a request, look up the merge + points in the source chains (ignoring the actual revision submitted for now)""" source_revisions = dict() factory_node = factory_revisions while factory_node: @@ -120,6 +143,7 @@ class TreeBuilder: factory_node = factory_node.parent def build(self, package): + """Create a Factory tree (returning the top)""" factory_revisions = self.revisions_chain("openSUSE:Factory", package) self.add_merge_points(factory_revisions)