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
126 lines
5.0 KiB
Go
126 lines
5.0 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"maps"
|
|
"slices"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
|
|
)
|
|
|
|
// heldByAnotherTrunk reads, for a module the trunk of repository no longer holds, whether the trunk of another repository
|
|
// holds it at the head the latest source names: the module directories there are asked of the forge (Trunk) and the manifest of
|
|
// each directory named like the module is read (Read). It answers the merge to hand the module over with, or none: a forge
|
|
// that cannot say leaves the module to be dropped as it was, said (issue 1367).
|
|
func (ix *Indexer) heldByAnotherTrunk(ctx context.Context, module, repository string) (whole, bool) {
|
|
if ix.Trunk == nil || ix.Read == nil {
|
|
return whole{}, false
|
|
}
|
|
ix.mu.Lock()
|
|
heads := maps.Clone(ix.source.heads)
|
|
ix.mu.Unlock()
|
|
for _, other := range slices.Sorted(maps.Keys(heads)) {
|
|
head := heads[other]
|
|
if head == "" || trunk.SameRepository(other, repository) {
|
|
continue
|
|
}
|
|
dirs, err := ix.Trunk(ctx, other, head)
|
|
if err != nil {
|
|
ix.logf("%s at %s: the modules of the trunk cannot be read, so %s is not looked for there: %v", other, head, module, err)
|
|
continue
|
|
}
|
|
for _, d := range dirs {
|
|
dir := strings.Trim(d, "/")
|
|
if nameOfDirectory(dir) != module {
|
|
continue
|
|
}
|
|
read, err := ix.Read(ctx, other, head, dir)
|
|
if err != nil {
|
|
ix.logf("%s at %s: %q cannot be read, so %s is not handed over from it: %v", other, head, dir, module, err)
|
|
continue
|
|
}
|
|
raw := read.Manifests[dir]
|
|
if read.Trees[dir] == "" || manifestModule(raw) != module {
|
|
continue
|
|
}
|
|
f := whole{Repository: other, Merge: head, Root: read.Root,
|
|
Trees: map[string]string{dir: read.Trees[dir]}, Manifests: map[string]string{dir: raw}}
|
|
if l := read.Locks[dir]; len(l) > 0 {
|
|
f.Locks = map[string]map[string]string{dir: l}
|
|
}
|
|
if p := read.Packages[dir]; len(p) > 0 {
|
|
f.Packages = map[string][]string{dir: p}
|
|
}
|
|
ix.logf("%s at %s: the trunk holds the module %s at %q, so it is handed over from there and not deleted (issue 1367)", other, head, module, dir)
|
|
return f, true
|
|
}
|
|
}
|
|
return whole{}, false
|
|
}
|
|
|
|
// nameOfDirectory is the last element of a module directory.
|
|
func nameOfDirectory(dir string) string { return dir[strings.LastIndex(dir, "/")+1:] }
|
|
|
|
// A module moves between repositories by the merges of the delivery group that moves it (novox/hq ADR 0420 clause 7, ADR
|
|
// 0501 clause 3; issue 1126: route-proxy leaves the controller's repository, which is archived). The merge of the
|
|
// repository it moves to names it while the indexer holds it of another: that merge leaves it, says so, and waits here.
|
|
// The merge of the repository that held it, whose trunk no longer holds it, then hands it over: the module is written from
|
|
// the waiting merge, in place, so its key never goes missing between the two (dropRemoved). Merged the other way round,
|
|
// the first merge deletes the key and the second writes it as a new module. Nothing else moves a module: a merge of a
|
|
// repository naming a module whose holding trunk still holds it changes nothing.
|
|
//
|
|
// The wait is the indexer's memory of a merge it heard, not state of its own: an indexer started between the two merges
|
|
// has forgotten it, and the module is deleted by the second; the next merge of the repository it moved to writes it.
|
|
|
|
// waitToMove keeps, by modules key, the part of a merged message naming one module directory the indexer holds of another
|
|
// repository. A later merge of the same repository replaces it.
|
|
func (ix *Indexer) waitToMove(key string, f whole, dir string) {
|
|
one := whole{Repository: f.Repository, Branch: f.Branch, Merge: f.Merge, Head: f.Head, Root: f.Root,
|
|
Trees: map[string]string{dir: f.Trees[dir]}, Manifests: map[string]string{dir: f.Manifests[dir]}}
|
|
if l := f.Locks[dir]; len(l) > 0 {
|
|
one.Locks = map[string]map[string]string{dir: l}
|
|
}
|
|
if p := f.Paths[dir]; len(p) > 0 {
|
|
one.Paths = map[string]map[string]string{dir: p}
|
|
}
|
|
if p := f.Packages[dir]; len(p) > 0 {
|
|
one.Packages = map[string][]string{dir: p}
|
|
}
|
|
ix.mu.Lock()
|
|
defer ix.mu.Unlock()
|
|
if ix.moving == nil {
|
|
ix.moving = map[string]whole{}
|
|
}
|
|
ix.moving[key] = one
|
|
}
|
|
|
|
// movingTo says a merge of another repository than from waits to take the module at key.
|
|
func (ix *Indexer) movingTo(key, from string) bool {
|
|
ix.mu.Lock()
|
|
defer ix.mu.Unlock()
|
|
f, ok := ix.moving[key]
|
|
return ok && !trunk.SameRepository(f.Repository, from)
|
|
}
|
|
|
|
// handOver writes the module at key from the merge waiting to take it, and forgets the wait.
|
|
func (ix *Indexer) handOver(ctx context.Context, key string) error {
|
|
ix.mu.Lock()
|
|
f, ok := ix.moving[key]
|
|
delete(ix.moving, key)
|
|
ix.mu.Unlock()
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return ix.handOverFrom(ctx, key, f)
|
|
}
|
|
|
|
// handOverFrom writes the module at key from the merge f, which names it, in place.
|
|
func (ix *Indexer) handOverFrom(ctx context.Context, key string, f whole) error {
|
|
if _, err := ix.applyMoving(ctx, f, false, map[string]bool{key: true}); err != nil {
|
|
return fmt.Errorf("modules.%s, moving to %s: %w", key, f.Repository, err)
|
|
}
|
|
return nil
|
|
}
|