internal/pkg: export layer promotion
All checks were successful
Test / Create distribution (push) Successful in 1m0s
Test / Sandbox (push) Successful in 2m48s
Test / Hakurei (push) Successful in 3m45s
Test / ShareFS (push) Successful in 4m2s
Test / Hpkg (push) Successful in 4m29s
Test / Sandbox (race detector) (push) Successful in 5m2s
Test / Hakurei (race detector) (push) Successful in 5m58s
Test / Flake checks (push) Successful in 1m58s
All checks were successful
Test / Create distribution (push) Successful in 1m0s
Test / Sandbox (push) Successful in 2m48s
Test / Hakurei (push) Successful in 3m45s
Test / ShareFS (push) Successful in 4m2s
Test / Hpkg (push) Successful in 4m29s
Test / Sandbox (race detector) (push) Successful in 5m2s
Test / Hakurei (race detector) (push) Successful in 5m58s
Test / Flake checks (push) Successful in 1m58s
This is a useful helper for external tooling. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -39,22 +39,20 @@ type ExecPath struct {
|
||||
W bool
|
||||
}
|
||||
|
||||
// layers returns pathnames collected from A deduplicated by checksum.
|
||||
func (p *ExecPath) layers(f *FContext) []*check.Absolute {
|
||||
msg := f.GetMessage()
|
||||
|
||||
layers := make([]*check.Absolute, 0, len(p.A))
|
||||
checksums := make(map[unique.Handle[Checksum]]struct{}, len(p.A))
|
||||
for i := range p.A {
|
||||
d := p.A[len(p.A)-1-i]
|
||||
pathname, checksum := f.GetArtifact(d)
|
||||
// PromoteLayers returns artifacts with identical-by-content layers promoted to
|
||||
// the highest priority instance, as if mounted via [ExecPath].
|
||||
func PromoteLayers(
|
||||
artifacts []Artifact,
|
||||
getArtifact func(Artifact) (*check.Absolute, unique.Handle[Checksum]),
|
||||
report func(i int, d Artifact),
|
||||
) []*check.Absolute {
|
||||
layers := make([]*check.Absolute, 0, len(artifacts))
|
||||
checksums := make(map[unique.Handle[Checksum]]struct{}, len(artifacts))
|
||||
for i := range artifacts {
|
||||
d := artifacts[len(artifacts)-1-i]
|
||||
pathname, checksum := getArtifact(d)
|
||||
if _, ok := checksums[checksum]; ok {
|
||||
if msg.IsVerbose() {
|
||||
msg.Verbosef(
|
||||
"promoted layer %d as %s",
|
||||
len(p.A)-1-i, reportName(d, f.cache.Ident(d)),
|
||||
)
|
||||
}
|
||||
report(len(artifacts)-1-i, d)
|
||||
continue
|
||||
}
|
||||
checksums[checksum] = struct{}{}
|
||||
@@ -64,6 +62,19 @@ func (p *ExecPath) layers(f *FContext) []*check.Absolute {
|
||||
return layers
|
||||
}
|
||||
|
||||
// layers returns pathnames collected from A deduplicated via [PromoteLayers].
|
||||
func (p *ExecPath) layers(f *FContext) []*check.Absolute {
|
||||
msg := f.GetMessage()
|
||||
return PromoteLayers(p.A, f.GetArtifact, func(i int, d Artifact) {
|
||||
if msg.IsVerbose() {
|
||||
msg.Verbosef(
|
||||
"promoted layer %d as %s",
|
||||
i, reportName(d, f.cache.Ident(d)),
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Path returns a populated [ExecPath].
|
||||
func Path(pathname *check.Absolute, writable bool, a ...Artifact) ExecPath {
|
||||
return ExecPath{pathname, a, writable}
|
||||
|
||||
Reference in New Issue
Block a user