Identify the protected alias affected by a proposed edit

This commit is contained in:
2026-11-11 12:34:20 +00:00
parent 73ef2c6083
commit 891c204e8f
3 changed files with 49 additions and 6 deletions

View File

@@ -99,8 +99,23 @@ func validateIdentityPreservation(beforeByID, afterByID map[glossary.Identity][]
var selected string
found := false
for identity, beforeItems := range beforeByID {
if len(afterByID[identity]) < len(beforeItems) && len(beforeItems) > 0 {
if spelling := beforeItems[0].canonical; !found || spelling < selected {
afterItems := afterByID[identity]
if len(afterItems) >= len(beforeItems) {
continue
}
// Protect identity counts. Within an identity that lost a mention,
// use spelling counts to identify which alias was affected.
remaining := make(map[string]int)
for _, item := range afterItems {
remaining[item.canonical]++
}
for _, item := range beforeItems {
spelling := item.canonical
if remaining[spelling] > 0 {
remaining[spelling]--
continue
}
if !found || spelling < selected {
selected, found = spelling, true
}
}