INNER CODE UNIT · Python
match_renames
lissy93/portainer-templates · lib/changelog.py:73
def match_renames(old, new, added, removed):
"""Renames, matched on title then body and dropped from `added` and `removed`.
A pair only counts when exactly one candidate matches, so splits stay honest."""
renamed = []
for key in (by_name, by_body):
candidates = {}
for title in added:
candidates.setdefault(key(new[title]), []).append(title)
for title in list(removed):
identity = key(old[title])
if len(candidates.get(identity, [])) == 1:
new_title = candidates.pop(identity)[0]
renamed.append({'from': title, 'to': new_title})
added.remove(new_title)
removed.remove(title)
return sorted(renamed, key=lambda pair: pair['from'])
def diff(old, new):