Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/source.go
T
jschoubben 8bd66112f0 I2: a take-in says what it waits on
A source-moved take-in waiting over a minute on the seat git writes one
journal line and its waiting-on (part, verb, since) in the state takeins
under running.<source revision>, removed at the take-in's end; past five
minutes it raises take-in-waiting (scope merge), cleared when the wait
ends. indexer_pending answers the running take-ins beside the held ones.
The wait is measured by a context's bound, no timer (ADR 0437 §8).

Builds: design 47 H2 §803, H-A-409
2026-11-22 01:02:11 +01:00

114 lines
3.9 KiB
Go

package index
import (
"context"
"encoding/json"
"errors"
"fmt"
"maps"
"path"
"slices"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
)
// The gate's source revision of a watched branch (design 47 H §737, §743), heard on its event source-moved: it names the heads
// of the repositories it moved, and its number is the mesh's source revision of that branch. The indexer keeps the latest it
// took in.
// sourceNow is the latest source revision seen.
type sourceNow struct {
rev uint64
heads map[string]string
}
// wholeAt reads repository's trees at the commit head through the seat git (design 47 H §743): every module directory's manifest,
// templates' needs, lock files and packages, and the catalogue's predefined list where the repository is the catalogue's (§769).
func (ix *Indexer) wholeAt(ctx context.Context, repository, head string) (whole, error) {
f := whole{Repository: repository, Merge: head, Head: head}
file := func(p string) ([]byte, error) {
if ix.ReadFile == nil {
return nil, errors.New("the indexer reads no file of the forge")
}
return waited(ctx, "git", "file", func() ([]byte, error) { return ix.ReadFile(ctx, repository, head, p) })
}
first, err := waited(ctx, "git", "trees", func() (RepoRead, error) { return ix.Read(ctx, repository, head, "") })
if err != nil {
return f, fmt.Errorf("the seat git could not read %s at %.12s: %w", repository, head, err)
}
f.Root, f.Trees = first.Root, maps.Clone(first.Trees)
for _, dir := range slices.Sorted(maps.Keys(first.Trees)) {
read := first
if dir != "" {
if read, err = waited(ctx, "git", "trees", func() (RepoRead, error) { return ix.Read(ctx, repository, head, dir) }); err != nil {
return f, fmt.Errorf("the seat git could not read %q of %s at %.12s: %w", dir, repository, head, err)
}
}
if f.Manifests == nil {
f.Manifests = map[string]string{}
}
f.Manifests[dir] = read.Manifests[dir]
// The reader capabilities of a manifest that names templates, its templates' text too, as the forge bridge reads them
// (ADR 0632 §2): a template the forge does not have is no need, any other failure to read one is the head's.
if paths := manifestTemplatePaths(read.Manifests[dir]); len(paths) > 0 {
texts := map[string]string{}
for _, t := range paths {
content, err := file(path.Join(dir, t))
if err != nil {
return f, fmt.Errorf("the seat git could not read the template %q of %q of %s at %.12s: %w", t, dir, repository, head, err)
}
if content != nil {
texts[t] = string(content)
}
}
if f.Needs == nil {
f.Needs = map[string][]string{}
}
f.Needs[dir], _ = catalogue.ModuleNeeds([]byte(read.Manifests[dir]), texts)
}
if l := read.Locks[dir]; len(l) > 0 {
if f.Locks == nil {
f.Locks = map[string]map[string]string{}
}
f.Locks[dir] = l
}
if p := read.Packages[dir]; len(p) > 0 {
if f.Packages == nil {
f.Packages = map[string][]string{}
}
f.Packages[dir] = p
}
}
// The catalogue's predefined list at the commit, as the forge bridge carries it (ADR 0565 §2).
if trunk.SameRepository(repository, catalogueRepository) {
raw, err := file(predefinedFile)
if err != nil {
return f, fmt.Errorf("the seat git could not read %s of %s at %.12s: %w", predefinedFile, repository, head, err)
}
if raw == nil {
f.PredefinedRead = true
} else {
f.Predefined = json.RawMessage(raw)
}
}
return f, nil
}
// The catalogue repository and its predefined list's file, whose merged message carries the list (the forge bridge's
// CatalogRepository and PredefinedFile).
const (
catalogueRepository = "novox/mesh-catalog"
predefinedFile = "predefined.json"
)
// manifestTemplatePaths is the template paths a manifest names, none for one that cannot be read.
func manifestTemplatePaths(raw string) []string {
m, err := catalogue.Decode([]byte(raw))
if err != nil {
return nil
}
return catalogue.TemplatePaths(m)
}