forked from importers/git-importer
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.
This commit is contained in:
parent
9aaba03bcc
commit
578fb2a30a
@ -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
|
||||
|
@ -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
|
||||
|
5
tests/fixtures/clapper-expected-tree.yaml
vendored
5
tests/fixtures/clapper-expected-tree.yaml
vendored
@ -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
|
||||
|
2
tests/fixtures/llvm13-expected-tree.yaml
vendored
2
tests/fixtures/llvm13-expected-tree.yaml
vendored
@ -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
|
||||
|
2
tests/fixtures/zsh-expected-tree.yaml
vendored
2
tests/fixtures/zsh-expected-tree.yaml
vendored
@ -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
|
||||
|
@ -42,5 +42,6 @@ class TestTreeMethods(unittest.TestCase):
|
||||
def test_llvm13_tree(self):
|
||||
self.verify_package("llvm13")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user