Skip to content

Commit

Permalink
s/SetupKey/SliceKey/g
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Jan 27, 2025
1 parent 5abdffa commit b9ebd1d
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 90 deletions.
4 changes: 2 additions & 2 deletions cmd/chisel/cmd_cut.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func (cmd *cmdCut) Execute(args []string) error {
return ErrExtraArgs
}

sliceKeys := make([]setup.SetupKey, len(cmd.Positional.SliceRefs))
sliceKeys := make([]setup.SliceKey, len(cmd.Positional.SliceRefs))
for i, sliceRef := range cmd.Positional.SliceRefs {
sliceKey, err := setup.ParseSetupKey(sliceRef)
sliceKey, err := setup.ParseSliceKey(sliceRef)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/chisel/cmd_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func selectPackageSlices(release *setup.Release, queries []string) (packages []*
pkgSlices := make(map[string][]string)
allPkgSlices := make(map[string]bool)

sliceExists := func(key setup.SetupKey) bool {
sliceExists := func(key setup.SliceKey) bool {
pkg, ok := release.Packages[key.Package]
if !ok {
return false
Expand All @@ -93,7 +93,7 @@ func selectPackageSlices(release *setup.Release, queries []string) (packages []*
for _, query := range queries {
var pkg, slice string
if strings.Contains(query, "_") {
key, err := setup.ParseSetupKey(query)
key, err := setup.ParseSliceKey(query)
if err != nil || !sliceExists(key) {
notFound = append(notFound, query)
continue
Expand Down
24 changes: 12 additions & 12 deletions internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Package struct {
type Slice struct {
Package string
Name string
Essential []SetupKey
Essential []SliceKey
Contents map[string]PathInfo
Scripts SliceScripts
}
Expand Down Expand Up @@ -103,10 +103,10 @@ func (pi *PathInfo) SameContent(other *PathInfo) bool {
pi.Generate == other.Generate)
}

type SetupKey = apacheutil.SliceKey
type SliceKey = apacheutil.SliceKey

func ParseSetupKey(setupKey string) (SetupKey, error) {
return apacheutil.ParseSliceKey(setupKey)
func ParseSliceKey(sliceKey string) (SliceKey, error) {
return apacheutil.ParseSliceKey(sliceKey)
}

func (s *Slice) String() string { return s.Package + "_" + s.Name }
Expand Down Expand Up @@ -145,7 +145,7 @@ func ReadRelease(dir string) (*Release, error) {
}

func (r *Release) validate() error {
keys := []SetupKey(nil)
keys := []SliceKey(nil)

// Check for info conflicts and prepare for following checks. A conflict
// means that two slices attempt to extract different files or directories
Expand All @@ -162,7 +162,7 @@ func (r *Release) validate() error {
globs := make(map[string]*Slice)
for _, pkg := range r.Packages {
for _, new := range pkg.Slices {
keys = append(keys, SetupKey{pkg.Name, new.Name})
keys = append(keys, SliceKey{pkg.Name, new.Name})
for newPath, newInfo := range new.Contents {
if old, ok := paths[newPath]; ok {
oldInfo := old.Contents[newPath]
Expand Down Expand Up @@ -243,7 +243,7 @@ func (r *Release) validate() error {
return nil
}

func order(pkgs map[string]*Package, keys []SetupKey) ([]SetupKey, error) {
func order(pkgs map[string]*Package, keys []SliceKey) ([]SliceKey, error) {

// Preprocess the list to improve error messages.
for _, key := range keys {
Expand All @@ -256,9 +256,9 @@ func order(pkgs map[string]*Package, keys []SetupKey) ([]SetupKey, error) {

// Collect all relevant package slices.
successors := map[string][]string{}
pending := append([]SetupKey(nil), keys...)
pending := append([]SliceKey(nil), keys...)

seen := make(map[SetupKey]bool)
seen := make(map[SliceKey]bool)
for i := 0; i < len(pending); i++ {
key := pending[i]
if seen[key] {
Expand All @@ -281,14 +281,14 @@ func order(pkgs map[string]*Package, keys []SetupKey) ([]SetupKey, error) {
}

// Sort them up.
var order []SetupKey
var order []SliceKey
for _, names := range tarjanSort(successors) {
if len(names) > 1 {
return nil, fmt.Errorf("essential loop detected: %s", strings.Join(names, ", "))
}
name := names[0]
dot := strings.IndexByte(name, '_')
order = append(order, SetupKey{name[:dot], name[dot+1:]})
order = append(order, SliceKey{name[:dot], name[dot+1:]})
}

return order, nil
Expand Down Expand Up @@ -360,7 +360,7 @@ func stripBase(baseDir, path string) string {
return strings.TrimPrefix(path, baseDir+string(filepath.Separator))
}

func Select(release *Release, slices []SetupKey) (*Selection, error) {
func Select(release *Release, slices []SliceKey) (*Selection, error) {
logf("Selecting slices...")

selection := &Selection{
Expand Down
26 changes: 13 additions & 13 deletions internal/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type setupTest struct {
input map[string]string
release *setup.Release
relerror string
selslices []setup.SetupKey
selslices []setup.SliceKey
selection *setup.Selection
selerror string
}
Expand Down Expand Up @@ -143,7 +143,7 @@ var setupTests = []setupTest{{
"myslice2": {
Package: "mypkg",
Name: "myslice2",
Essential: []setup.SetupKey{
Essential: []setup.SliceKey{
{"mypkg", "myslice1"},
},
Contents: map[string]setup.PathInfo{
Expand Down Expand Up @@ -283,7 +283,7 @@ var setupTests = []setupTest{{
myslice2: {essential: [mypkg1_myslice1]}
`,
},
selslices: []setup.SetupKey{{"mypkg1", "myslice1"}},
selslices: []setup.SliceKey{{"mypkg1", "myslice1"}},
selection: &setup.Selection{
Slices: []*setup.Slice{{
Package: "mypkg1",
Expand All @@ -306,15 +306,15 @@ var setupTests = []setupTest{{
myslice2: {essential: [mypkg1_myslice1]}
`,
},
selslices: []setup.SetupKey{{"mypkg2", "myslice2"}},
selslices: []setup.SliceKey{{"mypkg2", "myslice2"}},
selection: &setup.Selection{
Slices: []*setup.Slice{{
Package: "mypkg1",
Name: "myslice1",
}, {
Package: "mypkg2",
Name: "myslice2",
Essential: []setup.SetupKey{
Essential: []setup.SliceKey{
{"mypkg1", "myslice1"},
},
}},
Expand Down Expand Up @@ -345,7 +345,7 @@ var setupTests = []setupTest{{
/path3: {symlink: /link}
`,
},
selslices: []setup.SetupKey{{"mypkg1", "myslice1"}, {"mypkg1", "myslice2"}, {"mypkg2", "myslice1"}},
selslices: []setup.SliceKey{{"mypkg1", "myslice1"}, {"mypkg1", "myslice2"}, {"mypkg2", "myslice1"}},
}, {
summary: "Conflicting paths across slices",
input: map[string]string{
Expand Down Expand Up @@ -1199,7 +1199,7 @@ var setupTests = []setupTest{{
"slice1": {
Package: "mypkg",
Name: "slice1",
Essential: []setup.SetupKey{
Essential: []setup.SliceKey{
{"mypkg", "slice2"},
},
},
Expand All @@ -1210,7 +1210,7 @@ var setupTests = []setupTest{{
"slice3": {
Package: "mypkg",
Name: "slice3",
Essential: []setup.SetupKey{
Essential: []setup.SliceKey{
{"mypkg", "slice2"},
{"mypkg", "slice1"},
{"mypkg", "slice4"},
Expand All @@ -1219,7 +1219,7 @@ var setupTests = []setupTest{{
"slice4": {
Package: "mypkg",
Name: "slice4",
Essential: []setup.SetupKey{
Essential: []setup.SliceKey{
{"mypkg", "slice2"},
},
},
Expand Down Expand Up @@ -1266,7 +1266,7 @@ var setupTests = []setupTest{{
"slice1": {
Package: "mypkg",
Name: "slice1",
Essential: []setup.SetupKey{
Essential: []setup.SliceKey{
{"myotherpkg", "slice2"},
{"mypkg", "slice2"},
{"myotherpkg", "slice1"},
Expand All @@ -1275,7 +1275,7 @@ var setupTests = []setupTest{{
"slice2": {
Package: "mypkg",
Name: "slice2",
Essential: []setup.SetupKey{
Essential: []setup.SliceKey{
{"myotherpkg", "slice2"},
},
},
Expand Down Expand Up @@ -1451,7 +1451,7 @@ var setupTests = []setupTest{{
},
},
},
selslices: []setup.SetupKey{{"mypkg", "myslice"}},
selslices: []setup.SliceKey{{"mypkg", "myslice"}},
selection: &setup.Selection{
Slices: []*setup.Slice{{
Package: "mypkg",
Expand Down Expand Up @@ -1498,7 +1498,7 @@ var setupTests = []setupTest{{
},
},
},
selslices: []setup.SetupKey{{"mypkg", "myslice"}},
selslices: []setup.SliceKey{{"mypkg", "myslice"}},
selerror: `slice mypkg_myslice has invalid 'generate' for path /dir/\*\*: "foo"`,
}, {
summary: "Paths with generate: manifest must have trailing /**",
Expand Down
4 changes: 2 additions & 2 deletions internal/setup/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func parsePackage(baseDir, pkgName, pkgPath string, data []byte) (*Package, erro
},
}
for _, refName := range yamlPkg.Essential {
sliceKey, err := ParseSetupKey(refName)
sliceKey, err := ParseSliceKey(refName)
if err != nil {
return nil, fmt.Errorf("package %q has invalid essential slice reference: %q", pkgName, refName)
}
Expand All @@ -331,7 +331,7 @@ func parsePackage(baseDir, pkgName, pkgPath string, data []byte) (*Package, erro
slice.Essential = append(slice.Essential, sliceKey)
}
for _, refName := range yamlSlice.Essential {
sliceKey, err := ParseSetupKey(refName)
sliceKey, err := ParseSliceKey(refName)
if err != nil {
return nil, fmt.Errorf("package %q has invalid essential slice reference: %q", pkgName, refName)
}
Expand Down
Loading

0 comments on commit b9ebd1d

Please sign in to comment.