Merge pull request #390 from Morganamilo/stringslicemap

Refactor complex map types into their own type
This commit is contained in:
Anna 2018-05-07 23:44:05 +01:00 committed by GitHub
commit 4eca2be3c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 34 deletions

View File

@ -11,7 +11,7 @@ import (
// Checks a single conflict against every other to be installed package's
// name and its provides.
func checkInnerConflict(name string, conflict string, conflicts map[string]stringSet, dc *depCatagories) {
func checkInnerConflict(name string, conflict string, conflicts mapStringSet, dc *depCatagories) {
deps, err := gopkg.ParseDeps([]string{conflict})
if err != nil {
return
@ -28,7 +28,7 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
return
}
if dep.Name == pkg.Name && version.Satisfies(dep) {
addMapStringSet(conflicts, name, pkg.Name)
conflicts.Add(name, pkg.Name)
continue
}
@ -57,7 +57,7 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
}
if version != nil && version.Satisfies(dep) {
addMapStringSet(conflicts, name, pkg.Name)
conflicts.Add(name, pkg.Name)
break
}
@ -75,7 +75,7 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
}
if dep.Name == pkg.Name() && version.Satisfies(dep) {
addMapStringSet(conflicts, name, pkg.Name())
conflicts.Add(name, pkg.Name())
continue
}
@ -92,7 +92,7 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
}
if provide.Mod == alpm.DepModAny {
addMapStringSet(conflicts, name, pkg.Name())
conflicts.Add(name, pkg.Name())
return fmt.Errorf("")
}
@ -102,7 +102,7 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
}
if version.Satisfies(dep) {
addMapStringSet(conflicts, name, pkg.Name())
conflicts.Add(name, pkg.Name())
return fmt.Errorf("")
}
@ -113,8 +113,8 @@ func checkInnerConflict(name string, conflict string, conflicts map[string]strin
// Checks every to be installed package's conflicts against every other to be
// installed package and its provides.
func checkForInnerConflicts(dc *depCatagories) map[string]stringSet {
conflicts := make(map[string]stringSet)
func checkForInnerConflicts(dc *depCatagories) mapStringSet {
conflicts := make(mapStringSet)
for _, pkg := range dc.Aur {
for _, cpkg := range pkg.Conflicts {
@ -134,7 +134,7 @@ func checkForInnerConflicts(dc *depCatagories) map[string]stringSet {
// Checks a provide or packagename from a to be installed package
// against every already installed package's conflicts
func checkReverseConflict(name string, provide string, conflicts map[string]stringSet) error {
func checkReverseConflict(name string, provide string, conflicts mapStringSet) error {
var version *gopkg.CompleteVersion
var err error
@ -176,7 +176,7 @@ func checkReverseConflict(name string, provide string, conflicts map[string]stri
if version == nil || version.Satisfies(dep) {
// Todo
addMapStringSet(conflicts, name, pkg.Name()+" ("+provide+")")
conflicts.Add(name, pkg.Name()+" ("+provide+")")
return fmt.Errorf("")
}
@ -191,7 +191,7 @@ func checkReverseConflict(name string, provide string, conflicts map[string]stri
// Checks the conflict of a to be installed package against the package name and
// provides of every installed package.
func checkConflict(name string, conflict string, conflicts map[string]stringSet) error {
func checkConflict(name string, conflict string, conflicts mapStringSet) error {
localDb, err := alpmHandle.LocalDb()
if err != nil {
return err
@ -215,7 +215,7 @@ func checkConflict(name string, conflict string, conflicts map[string]stringSet)
}
if dep.Name == pkg.Name() && version.Satisfies(dep) {
addMapStringSet(conflicts, name, pkg.Name())
conflicts.Add(name, pkg.Name())
return nil
}
@ -232,7 +232,7 @@ func checkConflict(name string, conflict string, conflicts map[string]stringSet)
}
if provide.Mod == alpm.DepModAny {
addMapStringSet(conflicts, name, pkg.Name()+" ("+provide.Name+")")
conflicts.Add(name, pkg.Name()+" ("+provide.Name+")")
return fmt.Errorf("")
}
@ -242,7 +242,7 @@ func checkConflict(name string, conflict string, conflicts map[string]stringSet)
}
if version.Satisfies(dep) {
addMapStringSet(conflicts, name, pkg.Name()+" ("+provide.Name+")")
conflicts.Add(name, pkg.Name()+" ("+provide.Name+")")
return fmt.Errorf("")
}
@ -258,8 +258,8 @@ func checkConflict(name string, conflict string, conflicts map[string]stringSet)
// Checks every to be installed package's conflicts against the names and
// provides of every already installed package and checks every to be installed
// package's name and provides against every already installed package.
func checkForConflicts(dc *depCatagories) (map[string]stringSet, error) {
conflicts := make(map[string]stringSet)
func checkForConflicts(dc *depCatagories) (mapStringSet, error) {
conflicts := make(mapStringSet)
for _, pkg := range dc.Aur {
for _, cpkg := range pkg.Conflicts {
@ -296,8 +296,8 @@ func checkForConflicts(dc *depCatagories) (map[string]stringSet, error) {
// does some printing.
func checkForAllConflicts(dc *depCatagories) error {
var err error
var conflicts map[string]stringSet
var innerConflicts map[string]stringSet
var conflicts mapStringSet
var innerConflicts mapStringSet
var wg sync.WaitGroup
wg.Add(2)

View File

@ -548,7 +548,7 @@ func depTreeRecursive(dt *depTree, localDb *alpm.Db, syncDb alpm.DbList, isMake
}
func checkVersions(dt *depTree) error {
has := make(map[string][]string)
has := make(mapStringSlice)
allDeps := make([]*gopkg.Dependency, 0)
localDb, err := alpmHandle.LocalDb()
@ -569,13 +569,13 @@ func checkVersions(dt *depTree) error {
}
}
addMapStringSlice(has, pkg.Name, pkg.Version)
has.Add(pkg.Name, pkg.Version)
if !isDevelName(pkg.Name) {
for _, name := range pkg.Provides {
_name, _ver := splitNameFromDep(name)
if _ver != "" {
addMapStringSlice(has, _name, _ver)
has.Add(_name, _ver)
} else {
delete(has, _name)
}
@ -594,11 +594,11 @@ func checkVersions(dt *depTree) error {
return nil
})
addMapStringSlice(has, pkg.Name(), pkg.Version())
has.Add(pkg.Name(), pkg.Version())
pkg.Provides().ForEach(func(dep alpm.Depend) error {
if dep.Mod != alpm.DepModAny {
addMapStringSlice(has, dep.Name, dep.Version)
has.Add(dep.Name, dep.Version)
} else {
delete(has, dep.Name)
}
@ -611,7 +611,7 @@ func checkVersions(dt *depTree) error {
localDb.PkgCache().ForEach(func(pkg alpm.Package) error {
pkg.Provides().ForEach(func(dep alpm.Depend) error {
if dep.Mod != alpm.DepModAny {
addMapStringSlice(has, dep.Name, dep.Version)
has.Add(dep.Name, dep.Version)
} else {
delete(has, dep.Name)
}

View File

@ -332,7 +332,7 @@ func hangingPackages(removeOptional bool) (hanging []string, err error) {
// State = 2 - Keep package and have iterated over dependencies
safePackages := make(map[string]uint8)
// provides stores a mapping from the provides name back to the original package name
provides := make(map[string]stringSet)
provides := make(mapStringSet)
packages := localDb.PkgCache()
// Mark explicit dependencies and enumerate the provides list
@ -344,7 +344,7 @@ func hangingPackages(removeOptional bool) (hanging []string, err error) {
}
pkg.Provides().ForEach(func(dep alpm.Depend) error {
addMapStringSet(provides, dep.Name, pkg.Name())
provides.Add(dep.Name, pkg.Name())
return nil
})
return nil

View File

@ -7,6 +7,9 @@ import (
"unicode"
)
type mapStringSlice map[string][]string
type mapStringSet map[string]stringSet
type intRange struct {
min int
max int
@ -49,20 +52,20 @@ func max(a, b int) int {
return a
}
func addMapStringSet(h map[string]stringSet, n string, v string) {
_, ok := h[n]
func (mss mapStringSet) Add(n string, v string) {
_, ok := mss[n]
if !ok {
h[n] = make(stringSet)
mss[n] = make(stringSet)
}
h[n].set(v)
mss[n].set(v)
}
func addMapStringSlice(h map[string][]string, n string, v string) {
_, ok := h[n]
func (mss mapStringSlice) Add(n string, v string) {
_, ok := mss[n]
if !ok {
h[n] = make([]string, 0, 1)
mss[n] = make([]string, 0, 1)
}
h[n] = append(h[n], v)
mss[n] = append(mss[n], v)
}
func completeFileName(dir, name string) (string, error) {