I8: the take-in fed by the forge bridge's messages goes with B1's forgemsg: the FORGE consumer and its handlers, the group end, the pending state with its keys, claims, dry take-in and hand tools (indexer_pending, indexer_take_in_pending, indexer_drop_pending, indexer_take_in_merge, kept again for the held take-in in I5), the catch-up by comparison (kickBehind, TakeInBehind, sayUntaken, takeInHeads, kickCatchUp, CatchUp, merge-untaken), the source numbering in memory (nextSource), the source verb's follow and Src stamping on a source answer, the bridge's merged message call, the pull request candidates written from pull and open messages, the checker's previews and verdict hearing. A repository's trees at a commit are the internal whole (wholeAt), which ApplyMessage takes in; the dry indexer stays for a run on request's candidate. The manifest drops the consumes of forge.**, the checker's verdict and version-delivered, the reads of the checker's previews and the invokes of open-pulls, bridge_merged_message and mesh-delivery.source. RoomAgain says room when a take-in is held on a full store (heldFull, I5 holds it). H-A-82: the fill of delivered versions into the edges goes: HearVersionDelivered, the delivered.<module> key, the first fill's kinds 2, 4 and 6 from the placement and the stream running, and outdated's kinds 2, 4 and 6; their entries read not yet delivered. The tests of the removed paths go (index_test's candidate groups, source_test, branch_take_in_test, previews_test, candidate_manifests_test, the FORGE handle tests); the versions tests now hold kinds 2, 4 and 6 as declarations. The integration tests still drive FORGE and are rewritten in I10. Builds: design 47 H §743, §744, §764 (the indexer); H-A-48, H-A-82 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
132 lines
4.4 KiB
Go
132 lines
4.4 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
|
|
}
|
|
|
|
// srcOf is the source revision that names this merge commit as the repository's head, or 0 when the latest source seen
|
|
// names another head or none has been seen.
|
|
func (ix *Indexer) srcOf(repository, merge string) uint64 {
|
|
ix.mu.Lock()
|
|
defer ix.mu.Unlock()
|
|
if ix.source.rev != 0 && merge != "" && ix.source.heads[repository] == merge {
|
|
return ix.source.rev
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// sourceHeads is the head the latest source seen names for each repository (a copy), nil while none has been seen.
|
|
func (ix *Indexer) sourceHeads() map[string]string {
|
|
ix.mu.Lock()
|
|
defer ix.mu.Unlock()
|
|
return maps.Clone(ix.source.heads)
|
|
}
|
|
|
|
// 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 ix.ReadFile(ctx, repository, head, p)
|
|
}
|
|
first, err := 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 = 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)
|
|
}
|