Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/movers.go
T
jschoubben 8f24d9804b I12: a take-in names no version for a package one of its movers publishes, in an import-form importer's entry
At the take-in the version a mover's pipeline will publish is not released, so
the import-form importer's entry names its package with no version and its
build waits for that pipeline's publish (design 47 H2 H-A-532 DMC-1, H-A-547
Q5); a version-line entry keeps its pins, which its fingerprint takes.

Builds: design 47 H2 H-A-521, H-A-532 (DMC-1), H-A-547 (Q5)
2026-11-23 12:05:53 +01:00

104 lines
4.0 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 as H2 H-A-520 amends it): 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); every module, in any repository,
// whose import set is reported (its entry's import form, H-A-536, H-A-538) and whose fingerprint differs from its entry
// in before, since its fingerprint moves only with a package it imports (H-A-520, ADR 0593 §3); and every module with no
// reported import set that requires a package one of the fingerprint's movers publishes, by its packages (the fallback
// that exists, H-A-528). A module whose reported set holds no changed package is no mover. 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 == "" {
continue
}
fp, held := was[name]
_, reported := importSetOf(e)
if !inMoved(e.Repository) && !(reported && held) || held && 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 _, reported := importSetOf(e); movers[name] || e.Fp == "" || reported {
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
}
// unpinnedByMovers are the entries of a take-in with no version named, in an importer's packages, for a package a mover of
// the same take-in publishes (design 47 H2 H-A-532 DMC-1, H-A-547 Q5): the version that pipeline publishes is not released
// at the take-in, so the importer's build waits for that package's publish and is made against it (H-A-165, H-A-521). Only
// an entry on the import form is touched (its import set reported, H-A-538): a version-line entry's fingerprint takes its
// pins (H-A-167, H-A-530), so it keeps them. A mover's own packages are left as they are. The entries are written anew where
// one changes; the others are the same values.
func unpinnedByMovers(entries map[string]meshcatalog.CatalogEntry, movers []meshcatalog.TakeInEntry) map[string]meshcatalog.CatalogEntry {
published := map[string]string{} // package name to the mover that publishes it
for _, m := range movers {
for _, a := range entries[m.Module].Artifacts {
if a.Package != nil && a.Package.Name != "" {
published[a.Package.Name] = m.Module
}
}
}
if len(published) == 0 {
return entries
}
out := make(map[string]meshcatalog.CatalogEntry, len(entries))
for name, e := range entries {
out[name] = e
if _, reported := importSetOf(e); !reported {
continue
}
var pkgs map[string]string
for p, v := range e.Packages {
if by, ok := published[p]; ok && by != name && v != "" {
if pkgs == nil {
pkgs = maps.Clone(e.Packages)
}
pkgs[p] = ""
}
}
if pkgs != nil {
e.Packages = pkgs
out[name] = e
}
}
return out
}