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
|
W bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// layers returns pathnames collected from A deduplicated by checksum.
|
// PromoteLayers returns artifacts with identical-by-content layers promoted to
|
||||||
func (p *ExecPath) layers(f *FContext) []*check.Absolute {
|
// the highest priority instance, as if mounted via [ExecPath].
|
||||||
msg := f.GetMessage()
|
func PromoteLayers(
|
||||||
|
artifacts []Artifact,
|
||||||
layers := make([]*check.Absolute, 0, len(p.A))
|
getArtifact func(Artifact) (*check.Absolute, unique.Handle[Checksum]),
|
||||||
checksums := make(map[unique.Handle[Checksum]]struct{}, len(p.A))
|
report func(i int, d Artifact),
|
||||||
for i := range p.A {
|
) []*check.Absolute {
|
||||||
d := p.A[len(p.A)-1-i]
|
layers := make([]*check.Absolute, 0, len(artifacts))
|
||||||
pathname, checksum := f.GetArtifact(d)
|
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 _, ok := checksums[checksum]; ok {
|
||||||
if msg.IsVerbose() {
|
report(len(artifacts)-1-i, d)
|
||||||
msg.Verbosef(
|
|
||||||
"promoted layer %d as %s",
|
|
||||||
len(p.A)-1-i, reportName(d, f.cache.Ident(d)),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
checksums[checksum] = struct{}{}
|
checksums[checksum] = struct{}{}
|
||||||
@@ -64,6 +62,19 @@ func (p *ExecPath) layers(f *FContext) []*check.Absolute {
|
|||||||
return layers
|
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].
|
// Path returns a populated [ExecPath].
|
||||||
func Path(pathname *check.Absolute, writable bool, a ...Artifact) ExecPath {
|
func Path(pathname *check.Absolute, writable bool, a ...Artifact) ExecPath {
|
||||||
return ExecPath{pathname, a, writable}
|
return ExecPath{pathname, a, writable}
|
||||||
|
|||||||
Reference in New Issue
Block a user