Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/movers.go
T
jschoubben d00ee48363 I2a: the movers of a take-in are the moved fingerprints and their importers
A take-in's movers are the modules registered for a repository the source revision moved
whose fingerprint differs from their entry in the branch's newest catalog revision, and
every module, in any repository, importing a package one of them publishes. A module of
another repository is no mover by its fingerprint alone; one with no build is none.

Builds: design 47 H §743 (movers); A-476a

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 04:56:27 +01:00

58 lines
1.9 KiB
Go

package index
import (
"maps"
"slices"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
)
// moversOf are the movers of one take-in (design 47 H §743, A-476a): of the modules registered for a repository the source
// revision moved (moved, by the entry's repository), those whose fingerprint differs from their entry in before, the branch's
// newest catalog revision (one it does not hold included); and every module, in any repository, that imports a package one of
// them publishes. A module with no fingerprint (no build) is no mover. One {module, commit, fingerprint, repository} per mover,
// by module name.
func moversOf(before []meshcatalog.CatalogEntry, after map[string]meshcatalog.CatalogEntry, moved []string) []meshcatalog.TakeInEntry {
was := make(map[string]string, len(before))
for _, e := range before {
was[e.Module] = e.Fp
}
inMoved := func(repository string) bool {
return slices.ContainsFunc(moved, func(r string) bool { return trunk.SameRepository(r, repository) })
}
movers := map[string]bool{}
published := map[string]bool{} // the packages the fingerprint's movers publish, by name
for name, e := range after {
if e.Fp == "" || !inMoved(e.Repository) {
continue
}
if fp, ok := was[name]; ok && fp == e.Fp {
continue
}
movers[name] = true
for _, a := range e.Artifacts {
if a.Package != nil && a.Package.Name != "" {
published[a.Package.Name] = true
}
}
}
for name, e := range after {
if movers[name] || e.Fp == "" {
continue
}
for p := range e.Packages {
if published[p] {
movers[name] = true
break
}
}
}
out := make([]meshcatalog.TakeInEntry, 0, len(movers))
for _, name := range slices.Sorted(maps.Keys(movers)) {
e := after[name]
out = append(out, meshcatalog.TakeInEntry{Module: name, Commit: e.Commit, Fingerprint: e.Fp, Repository: e.Repository})
}
return out
}