~sil2100/cupstream2distro/fix_commitlogs

« back to all changes in this revision

Viewing changes to cupstream2distro/tools.py

Rewrite reorder_branches_regarding_prereqs in a more readable way.

Approved by PS Jenkins bot, Barry Warsaw.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    """Return the packaging diff filename."""
50
50
    return os_path_join_safe(SILO_DIR(), 'packaging_changes_{}_{}.diff'.format(
51
51
        src_pkg, packaging_version))
52
 
 
53
 
 
54
 
def reorder_branches_regarding_prereqs(list_of_merges):
55
 
    """Return merges ordered by their prerequisites, if any."""
56
 
    prepare = list(list_of_merges)
57
 
    components = []
58
 
    index = 0
59
 
    mp = prepare.pop(0)
60
 
    next_mp = None
61
 
 
62
 
    # the ugly way of doing this
63
 
    while True:
64
 
        found = False
65
 
        next_mp = None
66
 
 
67
 
        # if there is a prereq branch, find it and put it before this one
68
 
        if mp.prerequisite_branch is not None:
69
 
            for i in prepare:
70
 
                if (mp.prerequisite_branch.bzr_identity ==
71
 
                        i.source_branch.bzr_identity):
72
 
                    next_mp = i
73
 
                    prepare.remove(i)
74
 
                    found = True
75
 
                    break
76
 
            if not found:
77
 
                # or look for the parent in the already prepared list
78
 
                for i in components:
79
 
                    if (mp.prerequisite_branch.bzr_identity ==
80
 
                            i.source_branch.bzr_identity):
81
 
                        index = components.index(i) + 1
82
 
                        found = True
83
 
 
84
 
        components.insert(index, mp)
85
 
 
86
 
        if next_mp:
87
 
            mp = next_mp
88
 
        else:
89
 
            if len(prepare) <= 0:
90
 
                break
91
 
 
92
 
            if not found:
93
 
                index = len(components)
94
 
 
95
 
            mp = prepare.pop(0)
96
 
 
97
 
    return components