From 578fb2a30a2f6368bc4716d9ee8e488460f46aa1 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Tue, 1 Nov 2022 13:09:27 +0100 Subject: [PATCH] Change tree pruning algorithm The first merge we see in Factory determines if we keep the devel commits in the factory chain or cut that branch. --- lib/importer.py | 2 +- lib/tree_builder.py | 34 +++++++++++++++-------- tests/fixtures/clapper-expected-tree.yaml | 5 ++++ tests/fixtures/llvm13-expected-tree.yaml | 2 ++ tests/fixtures/zsh-expected-tree.yaml | 2 ++ tests/tree_test.py | 1 + 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/lib/importer.py b/lib/importer.py index 85f90e7..df0efd0 100644 --- a/lib/importer.py +++ b/lib/importer.py @@ -1,4 +1,3 @@ -import functools import logging import os import xml.etree.ElementTree as ET @@ -15,6 +14,7 @@ from lib.proxy_sha256 import ProxySHA256, md5, sha256 from lib.tree_builder import AbstractWalker, TreeBuilder, TreeNode from lib.user import User + class Importer: def __init__(self, projects, package, repodir): # The idea is to create each commit in order, and draw the diff --git a/lib/tree_builder.py b/lib/tree_builder.py index f719dc7..f5b10f1 100644 --- a/lib/tree_builder.py +++ b/lib/tree_builder.py @@ -13,9 +13,12 @@ class AbstractWalker: class PrintWalker(AbstractWalker): def call(self, node, is_source): if is_source: - print(" ", node.revision, node.revision.files_hash) + print(" ", node.revision.short_string(), node.revision.files_hash) else: - print(node.revision, node.revision.files_hash) + merge_str = "" + if node.merged: + merge_str = f"merged:{node.merged.revision.short_string()}" + print(node.revision.short_string(), node.revision.files_hash, merge_str) class TreeNode: @@ -160,28 +163,37 @@ class TreeBuilder: def prune_loose_end(self, factory_node): """Look for source revisions that end in a new root and prune them""" + merge_before_last = None last_merge = None while factory_node: if factory_node.merged: source_node = factory_node.merged - ended_without_merge = False while source_node: source_node = source_node.parent if source_node and source_node.merged_into: - ended_without_merge = True break - if not ended_without_merge: - factory_node.merged = None - if last_merge: - last_merge.parent = None - else: - last_merge = factory_node.merged + merge_before_last = last_merge + last_merge = factory_node factory_node = factory_node.parent + # we need to find the last merged_into that didn't end nowhere + # and cut the rope there + node = merge_before_last.merged + last_node = None + while node: + node = node.parent + if node and node.merged_into: + break + last_node = node + last_node.parent = None + + if not last_merge.parent: + last_merge.parent = last_merge.merged + last_merge.merged.merged_into = None + last_merge.merged = None 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) - self.prune_loose_end(factory_revisions) return factory_revisions diff --git a/tests/fixtures/clapper-expected-tree.yaml b/tests/fixtures/clapper-expected-tree.yaml index 261c3f6..532366d 100644 --- a/tests/fixtures/clapper-expected-tree.yaml +++ b/tests/fixtures/clapper-expected-tree.yaml @@ -4,4 +4,9 @@ - commit: openSUSE:Factory/clapper/2.0 merged: - multimedia:apps/clapper/7.0 + - multimedia:apps/clapper/6.0 + - multimedia:apps/clapper/5.0 - commit: openSUSE:Factory/clapper/1.0 +- commit: multimedia:apps/clapper/3.0 +- commit: multimedia:apps/clapper/2.0 +- commit: multimedia:apps/clapper/1.0 diff --git a/tests/fixtures/llvm13-expected-tree.yaml b/tests/fixtures/llvm13-expected-tree.yaml index a18d982..69145cf 100644 --- a/tests/fixtures/llvm13-expected-tree.yaml +++ b/tests/fixtures/llvm13-expected-tree.yaml @@ -44,4 +44,6 @@ - commit: openSUSE:Factory/llvm13/2.0 merged: - devel:tools:compiler/llvm13/4.0 + - devel:tools:compiler/llvm13/3.0 - commit: openSUSE:Factory/llvm13/1.0 +- commit: devel:tools:compiler/llvm13/1.0 diff --git a/tests/fixtures/zsh-expected-tree.yaml b/tests/fixtures/zsh-expected-tree.yaml index 8357463..efe5ced 100644 --- a/tests/fixtures/zsh-expected-tree.yaml +++ b/tests/fixtures/zsh-expected-tree.yaml @@ -286,6 +286,8 @@ - commit: openSUSE:Factory/zsh/13.0 merged: - shells/zsh/34.0 + - shells/zsh/33.0 + - shells/zsh/32.0 - commit: openSUSE:Factory/zsh/12.0 - commit: openSUSE:Factory/zsh/11.0 - commit: openSUSE:Factory/zsh/10.0 diff --git a/tests/tree_test.py b/tests/tree_test.py index bd89471..6c4da5f 100644 --- a/tests/tree_test.py +++ b/tests/tree_test.py @@ -42,5 +42,6 @@ class TestTreeMethods(unittest.TestCase): def test_llvm13_tree(self): self.verify_package("llvm13") + if __name__ == "__main__": unittest.main()