forked from adamm/git-importer
Switch to walker for tree print
This commit is contained in:
parent
6f83425538
commit
822329279d
@ -130,6 +130,7 @@ def main():
|
||||
|
||||
if args.db:
|
||||
importer.import_into_db()
|
||||
importer.export_as_git()
|
||||
return
|
||||
importer.import_all_revisions(args.gc)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user