Moved StringSet definition to types package

This commit is contained in:
Jguer 2019-10-05 18:39:31 +01:00
parent 3d31b52799
commit b01790f752
No known key found for this signature in database
GPG key ID: 6D6CC9BEA8556B35
13 changed files with 263 additions and 240 deletions

View file

@ -5,6 +5,8 @@ import (
"io/ioutil"
"os"
"path/filepath"
"github.com/Jguer/yay/v9/pkg/types"
)
// GetPkgbuild gets the pkgbuild of the package 'pkg' trying the ABS first and then the AUR trying the ABS first and then the AUR.
@ -104,8 +106,8 @@ func syncClean(parser *arguments) error {
func cleanAUR(keepInstalled, keepCurrent, removeAll bool) error {
fmt.Println("removing AUR packages from cache...")
installedBases := make(stringSet)
inAURBases := make(stringSet)
installedBases := make(types.StringSet)
inAURBases := make(types.StringSet)
_, remotePackages, _, _, err := filterPackages()
if err != nil {
@ -137,15 +139,15 @@ func cleanAUR(keepInstalled, keepCurrent, removeAll bool) error {
}
for _, pkg := range info {
inAURBases.set(pkg.PackageBase)
inAURBases.Set(pkg.PackageBase)
}
}
for _, pkg := range remotePackages {
if pkg.Base() != "" {
installedBases.set(pkg.Base())
installedBases.Set(pkg.Base())
} else {
installedBases.set(pkg.Name())
installedBases.Set(pkg.Name())
}
}
@ -155,11 +157,11 @@ func cleanAUR(keepInstalled, keepCurrent, removeAll bool) error {
}
if !removeAll {
if keepInstalled && installedBases.get(file.Name()) {
if keepInstalled && installedBases.Get(file.Name()) {
continue
}
if keepCurrent && inAURBases.get(file.Name()) {
if keepCurrent && inAURBases.Get(file.Name()) {
continue
}
}

View file

@ -7,9 +7,10 @@ import (
"sync"
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
)
func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts mapStringSet) {
func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts types.MapStringSet) {
for _, pkg := range dp.Aur {
if pkg.Name == name {
continue
@ -31,7 +32,7 @@ func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts ma
}
}
func (dp *depPool) checkForwardConflict(name string, conflict string, conflicts mapStringSet) {
func (dp *depPool) checkForwardConflict(name string, conflict string, conflicts types.MapStringSet) {
dp.LocalDB.PkgCache().ForEach(func(pkg alpm.Package) error {
if pkg.Name() == name || dp.hasPackage(pkg.Name()) {
return nil
@ -49,7 +50,7 @@ func (dp *depPool) checkForwardConflict(name string, conflict string, conflicts
})
}
func (dp *depPool) checkReverseConflict(name string, conflict string, conflicts mapStringSet) {
func (dp *depPool) checkReverseConflict(name string, conflict string, conflicts types.MapStringSet) {
for _, pkg := range dp.Aur {
if pkg.Name == name {
continue
@ -79,7 +80,7 @@ func (dp *depPool) checkReverseConflict(name string, conflict string, conflicts
}
}
func (dp *depPool) checkInnerConflicts(conflicts mapStringSet) {
func (dp *depPool) checkInnerConflicts(conflicts types.MapStringSet) {
for _, pkg := range dp.Aur {
for _, conflict := range pkg.Conflicts {
dp.checkInnerConflict(pkg.Name, conflict, conflicts)
@ -94,7 +95,7 @@ func (dp *depPool) checkInnerConflicts(conflicts mapStringSet) {
}
}
func (dp *depPool) checkForwardConflicts(conflicts mapStringSet) {
func (dp *depPool) checkForwardConflicts(conflicts types.MapStringSet) {
for _, pkg := range dp.Aur {
for _, conflict := range pkg.Conflicts {
dp.checkForwardConflict(pkg.Name, conflict, conflicts)
@ -109,7 +110,7 @@ func (dp *depPool) checkForwardConflicts(conflicts mapStringSet) {
}
}
func (dp *depPool) checkReverseConflicts(conflicts mapStringSet) {
func (dp *depPool) checkReverseConflicts(conflicts types.MapStringSet) {
dp.LocalDB.PkgCache().ForEach(func(pkg alpm.Package) error {
if dp.hasPackage(pkg.Name()) {
return nil
@ -124,10 +125,10 @@ func (dp *depPool) checkReverseConflicts(conflicts mapStringSet) {
})
}
func (dp *depPool) CheckConflicts() (mapStringSet, error) {
func (dp *depPool) CheckConflicts() (types.MapStringSet, error) {
var wg sync.WaitGroup
innerConflicts := make(mapStringSet)
conflicts := make(mapStringSet)
innerConflicts := make(types.MapStringSet)
conflicts := make(types.MapStringSet)
wg.Add(2)
fmt.Println(bold(cyan("::") + bold(" Checking for conflicts...")))
@ -181,9 +182,9 @@ func (dp *depPool) CheckConflicts() (mapStringSet, error) {
// These are used to decide what to pass --ask to (if set) or don't pass --noconfirm to
// As we have no idea what the order is yet we add every inner conflict to the slice
for name, pkgs := range innerConflicts {
conflicts[name] = make(stringSet)
conflicts[name] = make(types.StringSet)
for pkg := range pkgs {
conflicts[pkg] = make(stringSet)
conflicts[pkg] = make(types.StringSet)
}
}
@ -203,12 +204,12 @@ func (dp *depPool) CheckConflicts() (mapStringSet, error) {
}
type missing struct {
Good stringSet
Good types.StringSet
Missing map[string][][]string
}
func (dp *depPool) _checkMissing(dep string, stack []string, missing *missing) {
if missing.Good.get(dep) {
if missing.Good.Get(dep) {
return
}
@ -224,11 +225,11 @@ func (dp *depPool) _checkMissing(dep string, stack []string, missing *missing) {
aurPkg := dp.findSatisfierAur(dep)
if aurPkg != nil {
missing.Good.set(dep)
missing.Good.Set(dep)
for _, deps := range [3][]string{aurPkg.Depends, aurPkg.MakeDepends, aurPkg.CheckDepends} {
for _, aurDep := range deps {
if _, err := dp.LocalDB.PkgCache().FindSatisfier(aurDep); err == nil {
missing.Good.set(aurDep)
missing.Good.Set(aurDep)
continue
}
@ -241,10 +242,10 @@ func (dp *depPool) _checkMissing(dep string, stack []string, missing *missing) {
repoPkg := dp.findSatisfierRepo(dep)
if repoPkg != nil {
missing.Good.set(dep)
missing.Good.Set(dep)
repoPkg.Depends().ForEach(func(repoDep alpm.Depend) error {
if _, err := dp.LocalDB.PkgCache().FindSatisfier(repoDep.String()); err == nil {
missing.Good.set(repoDep.String())
missing.Good.Set(repoDep.String())
return nil
}
@ -260,7 +261,7 @@ func (dp *depPool) _checkMissing(dep string, stack []string, missing *missing) {
func (dp *depPool) CheckMissing() error {
missing := &missing{
make(stringSet),
make(types.StringSet),
make(map[string][][]string),
}

View file

@ -2,6 +2,7 @@ package main
import (
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
rpc "github.com/mikkeloscar/aur"
)
@ -22,14 +23,14 @@ func (b Base) URLPath() string {
type depOrder struct {
Aur []Base
Repo []*alpm.Package
Runtime stringSet
Runtime types.StringSet
}
func makeDepOrder() *depOrder {
return &depOrder{
make([]Base, 0),
make([]*alpm.Package, 0),
make(stringSet),
make(types.StringSet),
}
}
@ -59,7 +60,7 @@ func getDepOrder(dp *depPool) *depOrder {
func (do *depOrder) orderPkgAur(pkg *rpc.Pkg, dp *depPool, runtime bool) {
if runtime {
do.Runtime.set(pkg.Name)
do.Runtime.Set(pkg.Name)
}
delete(dp.Aur, pkg.Name)
@ -89,7 +90,7 @@ func (do *depOrder) orderPkgAur(pkg *rpc.Pkg, dp *depPool, runtime bool) {
func (do *depOrder) orderPkgRepo(pkg *alpm.Package, dp *depPool, runtime bool) {
if runtime {
do.Runtime.set(pkg.Name())
do.Runtime.Set(pkg.Name())
}
delete(dp.Repo, pkg.Name())
@ -119,14 +120,14 @@ func (do *depOrder) getMake() []string {
for _, base := range do.Aur {
for _, pkg := range base {
if !do.Runtime.get(pkg.Name) {
if !do.Runtime.Get(pkg.Name) {
makeOnly = append(makeOnly, pkg.Name)
}
}
}
for _, pkg := range do.Repo {
if !do.Runtime.get(pkg.Name()) {
if !do.Runtime.Get(pkg.Name()) {
makeOnly = append(makeOnly, pkg.Name())
}
}

View file

@ -6,6 +6,7 @@ import (
"sync"
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
rpc "github.com/mikkeloscar/aur"
)
@ -42,7 +43,7 @@ func (t target) String() string {
type depPool struct {
Targets []target
Explicit stringSet
Explicit types.StringSet
Repo map[string]*alpm.Package
Aur map[string]*rpc.Pkg
AurCache map[string]*rpc.Pkg
@ -64,7 +65,7 @@ func makeDepPool() (*depPool, error) {
dp := &depPool{
make([]target, 0),
make(stringSet),
make(types.StringSet),
make(map[string]*alpm.Package),
make(map[string]*rpc.Pkg),
make(map[string]*rpc.Pkg),
@ -82,7 +83,7 @@ func (dp *depPool) ResolveTargets(pkgs []string) error {
// RPC requests are slow
// Combine as many AUR package requests as possible into a single RPC
// call
aurTargets := make(stringSet)
aurTargets := make(types.StringSet)
pkgs = removeInvalidTargets(pkgs)
@ -105,7 +106,7 @@ func (dp *depPool) ResolveTargets(pkgs []string) error {
// aur/ prefix means we only check the aur
if target.DB == "aur" || mode == modeAUR {
dp.Targets = append(dp.Targets, target)
aurTargets.set(target.DepString())
aurTargets.Set(target.DepString())
continue
}
@ -123,7 +124,7 @@ func (dp *depPool) ResolveTargets(pkgs []string) error {
if err == nil {
dp.Targets = append(dp.Targets, target)
dp.Explicit.set(foundPkg.Name())
dp.Explicit.Set(foundPkg.Name())
dp.ResolveRepoDependency(foundPkg)
continue
} else {
@ -138,7 +139,7 @@ func (dp *depPool) ResolveTargets(pkgs []string) error {
if !group.Empty() {
dp.Groups = append(dp.Groups, target.String())
group.ForEach(func(pkg alpm.Package) error {
dp.Explicit.set(pkg.Name())
dp.Explicit.Set(pkg.Name())
return nil
})
continue
@ -147,7 +148,7 @@ func (dp *depPool) ResolveTargets(pkgs []string) error {
//if there was no db prefix check the aur
if target.DB == "" {
aurTargets.set(target.DepString())
aurTargets.Set(target.DepString())
}
dp.Targets = append(dp.Targets, target)
@ -172,7 +173,7 @@ func (dp *depPool) ResolveTargets(pkgs []string) error {
// positives.
//
// This method increases dependency resolve time
func (dp *depPool) findProvides(pkgs stringSet) error {
func (dp *depPool) findProvides(pkgs types.StringSet) error {
var mux sync.Mutex
var wg sync.WaitGroup
@ -200,7 +201,7 @@ func (dp *depPool) findProvides(pkgs stringSet) error {
for _, result := range results {
mux.Lock()
if _, ok := dp.AurCache[result.Name]; !ok {
pkgs.set(result.Name)
pkgs.Set(result.Name)
}
mux.Unlock()
}
@ -219,13 +220,13 @@ func (dp *depPool) findProvides(pkgs stringSet) error {
return nil
}
func (dp *depPool) cacheAURPackages(_pkgs stringSet) error {
pkgs := _pkgs.copy()
func (dp *depPool) cacheAURPackages(_pkgs types.StringSet) error {
pkgs := _pkgs.Copy()
query := make([]string, 0)
for pkg := range pkgs {
if _, ok := dp.AurCache[pkg]; ok {
pkgs.remove(pkg)
pkgs.Remove(pkg)
}
}
@ -260,9 +261,9 @@ func (dp *depPool) cacheAURPackages(_pkgs stringSet) error {
return nil
}
func (dp *depPool) resolveAURPackages(pkgs stringSet, explicit bool) error {
newPackages := make(stringSet)
newAURPackages := make(stringSet)
func (dp *depPool) resolveAURPackages(pkgs types.StringSet, explicit bool) error {
newPackages := make(types.StringSet)
newAURPackages := make(types.StringSet)
err := dp.cacheAURPackages(pkgs)
if err != nil {
@ -285,13 +286,13 @@ func (dp *depPool) resolveAURPackages(pkgs stringSet, explicit bool) error {
}
if explicit {
dp.Explicit.set(pkg.Name)
dp.Explicit.Set(pkg.Name)
}
dp.Aur[pkg.Name] = pkg
for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
for _, dep := range deps {
newPackages.set(dep)
newPackages.Set(dep)
}
}
}
@ -317,7 +318,7 @@ func (dp *depPool) resolveAURPackages(pkgs stringSet, explicit bool) error {
//assume it's in the aur
//ditch the versioning because the RPC can't handle it
newAURPackages.set(dep)
newAURPackages.Set(dep)
}
@ -386,7 +387,7 @@ func (dp *depPool) findSatisfierAur(dep string) *rpc.Pkg {
// TODO: maybe intermix repo providers in the menu
func (dp *depPool) findSatisfierAurCache(dep string) *rpc.Pkg {
depName, _, _ := splitDep(dep)
seen := make(stringSet)
seen := make(types.StringSet)
providers := makeProviders(depName)
if dp.LocalDB.Pkg(depName) != nil {
@ -409,20 +410,20 @@ func (dp *depPool) findSatisfierAurCache(dep string) *rpc.Pkg {
}
for _, pkg := range dp.AurCache {
if seen.get(pkg.Name) {
if seen.Get(pkg.Name) {
continue
}
if pkgSatisfies(pkg.Name, pkg.Version, dep) {
providers.Pkgs = append(providers.Pkgs, pkg)
seen.set(pkg.Name)
seen.Set(pkg.Name)
continue
}
for _, provide := range pkg.Provides {
if provideSatisfies(provide, dep) {
providers.Pkgs = append(providers.Pkgs, pkg)
seen.set(pkg.Name)
seen.Set(pkg.Name)
continue
}
}

View file

@ -17,7 +17,7 @@ import (
// Install handles package installs
func install(parser *arguments) (err error) {
var incompatible stringSet
var incompatible types.StringSet
var do *depOrder
var aurUp upSlice
@ -55,8 +55,8 @@ func install(parser *arguments) (err error) {
return err
}
remoteNamesCache := sliceToStringSet(remoteNames)
localNamesCache := sliceToStringSet(localNames)
remoteNamesCache := types.SliceToStringSet(remoteNames)
localNamesCache := types.SliceToStringSet(localNames)
requestTargets := parser.copy().targets
@ -86,7 +86,7 @@ func install(parser *arguments) (err error) {
}
for _, up := range repoUp {
if !ignore.get(up.Name) {
if !ignore.Get(up.Name) {
requestTargets = append(requestTargets, up.Name)
parser.addTarget(up.Name)
}
@ -100,7 +100,7 @@ func install(parser *arguments) (err error) {
value, _, exists := cmdArgs.getArg("ignore")
if len(ignore) > 0 {
ignoreStr := strings.Join(ignore.toSlice(), ",")
ignoreStr := strings.Join(ignore.ToSlice(), ",")
if exists {
ignoreStr += "," + value
}
@ -108,7 +108,7 @@ func install(parser *arguments) (err error) {
}
}
targets := sliceToStringSet(parser.targets)
targets := types.SliceToStringSet(parser.targets)
dp, err := getDepPool(requestTargets, warnings)
if err != nil {
@ -290,14 +290,14 @@ func install(parser *arguments) (err error) {
expArguments.addArg("D", "asexplicit")
for _, pkg := range do.Repo {
if !dp.Explicit.get(pkg.Name()) && !localNamesCache.get(pkg.Name()) && !remoteNamesCache.get(pkg.Name()) {
if !dp.Explicit.Get(pkg.Name()) && !localNamesCache.Get(pkg.Name()) && !remoteNamesCache.Get(pkg.Name()) {
depArguments.addTarget(pkg.Name())
continue
}
if parser.existsArg("asdeps", "asdep") && dp.Explicit.get(pkg.Name()) {
if parser.existsArg("asdeps", "asdep") && dp.Explicit.Get(pkg.Name()) {
depArguments.addTarget(pkg.Name())
} else if parser.existsArg("asexp", "asexplicit") && dp.Explicit.get(pkg.Name()) {
} else if parser.existsArg("asexp", "asexplicit") && dp.Explicit.Get(pkg.Name()) {
expArguments.addTarget(pkg.Name())
}
}
@ -412,8 +412,8 @@ func earlyRefresh(parser *arguments) error {
return show(passToPacman(arguments))
}
func getIncompatible(bases []Base, srcinfos map[string]*gosrc.Srcinfo) (stringSet, error) {
incompatible := make(stringSet)
func getIncompatible(bases []Base, srcinfos map[string]*gosrc.Srcinfo) (types.StringSet, error) {
incompatible := make(types.StringSet)
basesMap := make(map[string]Base)
alpmArch, err := alpmHandle.Arch()
if err != nil {
@ -428,7 +428,7 @@ nextpkg:
}
}
incompatible.set(base.Pkgbase())
incompatible.Set(base.Pkgbase())
basesMap[base.Pkgbase()] = base
}
@ -496,7 +496,7 @@ func anyExistInCache(bases []Base) bool {
return false
}
func pkgbuildNumberMenu(bases []Base, installed stringSet) bool {
func pkgbuildNumberMenu(bases []Base, installed types.StringSet) bool {
toPrint := ""
askClean := false
@ -509,7 +509,7 @@ func pkgbuildNumberMenu(bases []Base, installed stringSet) bool {
anyInstalled := false
for _, b := range base {
anyInstalled = anyInstalled || installed.get(b.Name)
anyInstalled = anyInstalled || installed.Get(b.Name)
}
if anyInstalled {
@ -529,7 +529,7 @@ func pkgbuildNumberMenu(bases []Base, installed stringSet) bool {
return askClean
}
func cleanNumberMenu(bases []Base, installed stringSet, hasClean bool) ([]Base, error) {
func cleanNumberMenu(bases []Base, installed types.StringSet, hasClean bool) ([]Base, error) {
toClean := make([]Base, 0)
if !hasClean {
@ -547,16 +547,16 @@ func cleanNumberMenu(bases []Base, installed stringSet, hasClean bool) ([]Base,
cInclude, cExclude, cOtherInclude, cOtherExclude := parseNumberMenu(cleanInput)
cIsInclude := len(cExclude) == 0 && len(cOtherExclude) == 0
if cOtherInclude.get("abort") || cOtherInclude.get("ab") {
if cOtherInclude.Get("abort") || cOtherInclude.Get("ab") {
return nil, fmt.Errorf("Aborting due to user")
}
if !cOtherInclude.get("n") && !cOtherInclude.get("none") {
if !cOtherInclude.Get("n") && !cOtherInclude.Get("none") {
for i, base := range bases {
pkg := base.Pkgbase()
anyInstalled := false
for _, b := range base {
anyInstalled = anyInstalled || installed.get(b.Name)
anyInstalled = anyInstalled || installed.Get(b.Name)
}
dir := filepath.Join(config.BuildDir, pkg)
@ -568,27 +568,27 @@ func cleanNumberMenu(bases []Base, installed stringSet, hasClean bool) ([]Base,
continue
}
if anyInstalled && (cOtherInclude.get("i") || cOtherInclude.get("installed")) {
if anyInstalled && (cOtherInclude.Get("i") || cOtherInclude.Get("installed")) {
toClean = append(toClean, base)
continue
}
if !anyInstalled && (cOtherInclude.get("no") || cOtherInclude.get("notinstalled")) {
if !anyInstalled && (cOtherInclude.Get("no") || cOtherInclude.Get("notinstalled")) {
toClean = append(toClean, base)
continue
}
if cOtherInclude.get("a") || cOtherInclude.get("all") {
if cOtherInclude.Get("a") || cOtherInclude.Get("all") {
toClean = append(toClean, base)
continue
}
if cIsInclude && (cInclude.get(len(bases)-i) || cOtherInclude.get(pkg)) {
if cIsInclude && (cInclude.get(len(bases)-i) || cOtherInclude.Get(pkg)) {
toClean = append(toClean, base)
continue
}
if !cIsInclude && (!cExclude.get(len(bases)-i) && !cOtherExclude.get(pkg)) {
if !cIsInclude && (!cExclude.get(len(bases)-i) && !cOtherExclude.Get(pkg)) {
toClean = append(toClean, base)
continue
}
@ -598,15 +598,15 @@ func cleanNumberMenu(bases []Base, installed stringSet, hasClean bool) ([]Base,
return toClean, nil
}
func editNumberMenu(bases []Base, installed stringSet) ([]Base, error) {
func editNumberMenu(bases []Base, installed types.StringSet) ([]Base, error) {
return editDiffNumberMenu(bases, installed, false)
}
func diffNumberMenu(bases []Base, installed stringSet) ([]Base, error) {
func diffNumberMenu(bases []Base, installed types.StringSet) ([]Base, error) {
return editDiffNumberMenu(bases, installed, true)
}
func editDiffNumberMenu(bases []Base, installed stringSet, diff bool) ([]Base, error) {
func editDiffNumberMenu(bases []Base, installed types.StringSet, diff bool) ([]Base, error) {
toEdit := make([]Base, 0)
var editInput string
var err error
@ -632,42 +632,42 @@ func editDiffNumberMenu(bases []Base, installed stringSet, diff bool) ([]Base, e
eInclude, eExclude, eOtherInclude, eOtherExclude := parseNumberMenu(editInput)
eIsInclude := len(eExclude) == 0 && len(eOtherExclude) == 0
if eOtherInclude.get("abort") || eOtherInclude.get("ab") {
if eOtherInclude.Get("abort") || eOtherInclude.Get("ab") {
return nil, fmt.Errorf("Aborting due to user")
}
if !eOtherInclude.get("n") && !eOtherInclude.get("none") {
if !eOtherInclude.Get("n") && !eOtherInclude.Get("none") {
for i, base := range bases {
pkg := base.Pkgbase()
anyInstalled := false
for _, b := range base {
anyInstalled = anyInstalled || installed.get(b.Name)
anyInstalled = anyInstalled || installed.Get(b.Name)
}
if !eIsInclude && eExclude.get(len(bases)-i) {
continue
}
if anyInstalled && (eOtherInclude.get("i") || eOtherInclude.get("installed")) {
if anyInstalled && (eOtherInclude.Get("i") || eOtherInclude.Get("installed")) {
toEdit = append(toEdit, base)
continue
}
if !anyInstalled && (eOtherInclude.get("no") || eOtherInclude.get("notinstalled")) {
if !anyInstalled && (eOtherInclude.Get("no") || eOtherInclude.Get("notinstalled")) {
toEdit = append(toEdit, base)
continue
}
if eOtherInclude.get("a") || eOtherInclude.get("all") {
if eOtherInclude.Get("a") || eOtherInclude.Get("all") {
toEdit = append(toEdit, base)
continue
}
if eIsInclude && (eInclude.get(len(bases)-i) || eOtherInclude.get(pkg)) {
if eIsInclude && (eInclude.get(len(bases)-i) || eOtherInclude.Get(pkg)) {
toEdit = append(toEdit, base)
}
if !eIsInclude && (!eExclude.get(len(bases)-i) && !eOtherExclude.get(pkg)) {
if !eIsInclude && (!eExclude.get(len(bases)-i) && !eOtherExclude.Get(pkg)) {
toEdit = append(toEdit, base)
}
}
@ -676,14 +676,14 @@ func editDiffNumberMenu(bases []Base, installed stringSet, diff bool) ([]Base, e
return toEdit, nil
}
func showPkgbuildDiffs(bases []Base, cloned stringSet) error {
func showPkgbuildDiffs(bases []Base, cloned types.StringSet) error {
for _, base := range bases {
pkg := base.Pkgbase()
dir := filepath.Join(config.BuildDir, pkg)
if shouldUseGit(dir) {
start := "HEAD"
if cloned.get(pkg) {
if cloned.Get(pkg) {
start = gitEmptyTree
} else {
hasDiff, err := gitHasDiff(config.BuildDir, pkg)
@ -775,13 +775,13 @@ func parseSrcinfoFiles(bases []Base, errIsFatal bool) (map[string]*gosrc.Srcinfo
return srcinfos, nil
}
func pkgbuildsToSkip(bases []Base, targets stringSet) stringSet {
toSkip := make(stringSet)
func pkgbuildsToSkip(bases []Base, targets types.StringSet) types.StringSet {
toSkip := make(types.StringSet)
for _, base := range bases {
isTarget := false
for _, pkg := range base {
isTarget = isTarget || targets.get(pkg.Name)
isTarget = isTarget || targets.Get(pkg.Name)
}
if (config.ReDownload == "yes" && isTarget) || config.ReDownload == "all" {
@ -793,7 +793,7 @@ func pkgbuildsToSkip(bases []Base, targets stringSet) stringSet {
if err == nil {
if alpm.VerCmp(pkgbuild.Version(), base.Version()) >= 0 {
toSkip.set(base.Pkgbase())
toSkip.Set(base.Pkgbase())
}
}
}
@ -814,8 +814,8 @@ func mergePkgbuilds(bases []Base) error {
return nil
}
func downloadPkgbuilds(bases []Base, toSkip stringSet, buildDir string) (stringSet, error) {
cloned := make(stringSet)
func downloadPkgbuilds(bases []Base, toSkip types.StringSet, buildDir string) (types.StringSet, error) {
cloned := make(types.StringSet)
downloaded := 0
var wg sync.WaitGroup
var mux sync.Mutex
@ -825,7 +825,7 @@ func downloadPkgbuilds(bases []Base, toSkip stringSet, buildDir string) (stringS
defer wg.Done()
pkg := base.Pkgbase()
if toSkip.get(pkg) {
if toSkip.Get(pkg) {
mux.Lock()
downloaded++
str := bold(cyan("::") + " PKGBUILD up to date, Skipping (%d/%d): %s\n")
@ -842,7 +842,7 @@ func downloadPkgbuilds(bases []Base, toSkip stringSet, buildDir string) (stringS
}
if clone {
mux.Lock()
cloned.set(pkg)
cloned.Set(pkg)
mux.Unlock()
}
} else {
@ -875,13 +875,13 @@ func downloadPkgbuilds(bases []Base, toSkip stringSet, buildDir string) (stringS
return cloned, errs.Return()
}
func downloadPkgbuildsSources(bases []Base, incompatible stringSet) (err error) {
func downloadPkgbuildsSources(bases []Base, incompatible types.StringSet) (err error) {
for _, base := range bases {
pkg := base.Pkgbase()
dir := filepath.Join(config.BuildDir, pkg)
args := []string{"--verifysource", "-Ccf"}
if incompatible.get(pkg) {
if incompatible.Get(pkg) {
args = append(args, "--ignorearch")
}
@ -894,7 +894,7 @@ func downloadPkgbuildsSources(bases []Base, incompatible stringSet) (err error)
return
}
func buildInstallPkgbuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc.Srcinfo, parser *arguments, incompatible stringSet, conflicts mapStringSet) error {
func buildInstallPkgbuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc.Srcinfo, parser *arguments, incompatible types.StringSet, conflicts types.MapStringSet) error {
for _, base := range do.Aur {
pkg := base.Pkgbase()
dir := filepath.Join(config.BuildDir, pkg)
@ -904,7 +904,7 @@ func buildInstallPkgbuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc
args := []string{"--nobuild", "-fC"}
if incompatible.get(pkg) {
if incompatible.Get(pkg) {
args = append(args, "--ignorearch")
}
@ -921,7 +921,7 @@ func buildInstallPkgbuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc
isExplicit := false
for _, b := range base {
isExplicit = isExplicit || dp.Explicit.get(b.Name)
isExplicit = isExplicit || dp.Explicit.Get(b.Name)
}
if config.ReBuild == "no" || (config.ReBuild == "yes" && !isExplicit) {
for _, split := range base {
@ -963,7 +963,7 @@ func buildInstallPkgbuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc
} else {
args := []string{"-cf", "--noconfirm", "--noextract", "--noprepare", "--holdver"}
if incompatible.get(pkg) {
if incompatible.Get(pkg) {
args = append(args, "--ignorearch")
}
@ -1018,8 +1018,8 @@ func buildInstallPkgbuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc
//cache as a stringset. maybe make it return a string set in the first
//place
remoteNamesCache := sliceToStringSet(remoteNames)
localNamesCache := sliceToStringSet(localNames)
remoteNamesCache := types.SliceToStringSet(remoteNames)
localNamesCache := types.SliceToStringSet(localNames)
for _, split := range base {
pkgdest, ok := pkgdests[split.Name]
@ -1028,11 +1028,11 @@ func buildInstallPkgbuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc
}
arguments.addTarget(pkgdest)
if !dp.Explicit.get(split.Name) && !localNamesCache.get(split.Name) && !remoteNamesCache.get(split.Name) {
if !dp.Explicit.Get(split.Name) && !localNamesCache.Get(split.Name) && !remoteNamesCache.Get(split.Name) {
depArguments.addTarget(split.Name)
}
if dp.Explicit.get(split.Name) {
if dp.Explicit.Get(split.Name) {
if parser.existsArg("asdeps", "asdep") {
depArguments.addTarget(split.Name)
} else if parser.existsArg("asexplicit", "asexp") {

View file

@ -10,71 +10,17 @@ import (
"strings"
"unicode"
"github.com/Jguer/yay/v9/pkg/types"
rpc "github.com/mikkeloscar/aur"
)
// A basic set implementation for strings.
// This is used a lot so it deserves its own type.
// Other types of sets are used throughout the code but do not have
// their own typedef.
// String sets and <type>sets should be used throughout the code when applicable,
// they are a lot more flexible than slices and provide easy lookup.
type stringSet map[string]struct{}
func (set stringSet) set(v string) {
set[v] = struct{}{}
}
func (set stringSet) get(v string) bool {
_, exists := set[v]
return exists
}
func (set stringSet) remove(v string) {
delete(set, v)
}
func (set stringSet) toSlice() []string {
slice := make([]string, 0, len(set))
for v := range set {
slice = append(slice, v)
}
return slice
}
func (set stringSet) copy() stringSet {
newSet := make(stringSet)
for str := range set {
newSet.set(str)
}
return newSet
}
func sliceToStringSet(in []string) stringSet {
set := make(stringSet)
for _, v := range in {
set.set(v)
}
return set
}
func makeStringSet(in ...string) stringSet {
return sliceToStringSet(in)
}
// Parses command line arguments in a way we can interact with programmatically but
// also in a way that can easily be passed to pacman later on.
type arguments struct {
op string
options map[string]string
globals map[string]string
doubles stringSet // Tracks args passed twice such as -yy and -dd
doubles types.StringSet // Tracks args passed twice such as -yy and -dd
targets []string
}
@ -83,7 +29,7 @@ func makeArguments() *arguments {
"",
make(map[string]string),
make(map[string]string),
make(stringSet),
make(types.StringSet),
make([]string, 0),
}
}
@ -896,11 +842,11 @@ func (parser *arguments) extractYayOptions() {
//intended to allow words inside of number menus. e.g. 'all' 'none' 'abort'
//of course the implementation is up to the caller, this function mearley parses
//the input and organizes it
func parseNumberMenu(input string) (intRanges, intRanges, stringSet, stringSet) {
func parseNumberMenu(input string) (intRanges, intRanges, types.StringSet, types.StringSet) {
include := make(intRanges, 0)
exclude := make(intRanges, 0)
otherInclude := make(stringSet)
otherExclude := make(stringSet)
otherInclude := make(types.StringSet)
otherExclude := make(types.StringSet)
words := strings.FieldsFunc(input, func(c rune) bool {
return unicode.IsSpace(c) || c == ','
@ -923,14 +869,14 @@ func parseNumberMenu(input string) (intRanges, intRanges, stringSet, stringSet)
num1, err = strconv.Atoi(ranges[0])
if err != nil {
other.set(strings.ToLower(word))
other.Set(strings.ToLower(word))
continue
}
if len(ranges) == 2 {
num2, err = strconv.Atoi(ranges[1])
if err != nil {
other.set(strings.ToLower(word))
other.Set(strings.ToLower(word))
continue
}
} else {

View file

@ -1,6 +1,10 @@
package main
import "testing"
import (
"testing"
"github.com/Jguer/yay/v9/pkg/types"
)
func intRangesEqual(a, b intRanges) bool {
if a == nil && b == nil {
@ -27,34 +31,12 @@ func intRangesEqual(a, b intRanges) bool {
return true
}
func stringSetEqual(a, b stringSet) bool {
if a == nil && b == nil {
return true
}
if a == nil || b == nil {
return false
}
if len(a) != len(b) {
return false
}
for n := range a {
if !b.get(n) {
return false
}
}
return true
}
func TestParseNumberMenu(t *testing.T) {
type result struct {
Include intRanges
Exclude intRanges
OtherInclude stringSet
OtherExclude stringSet
OtherInclude types.StringSet
OtherExclude types.StringSet
}
inputs := []string{
@ -72,17 +54,17 @@ func TestParseNumberMenu(t *testing.T) {
}
expected := []result{
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, intRanges{}, make(stringSet), make(stringSet)},
{intRanges{makeIntRange(1, 10), makeIntRange(5, 15)}, intRanges{}, make(stringSet), make(stringSet)},
{intRanges{makeIntRange(5, 10), makeIntRange(85, 90)}, intRanges{}, make(stringSet), make(stringSet)},
{intRanges{makeIntRange(1, 1), makeIntRange(99, 99), makeIntRange(60, 62)}, intRanges{makeIntRange(2, 2), makeIntRange(5, 10), makeIntRange(38, 40), makeIntRange(123, 123)}, make(stringSet), make(stringSet)},
{intRanges{}, intRanges{}, makeStringSet("abort", "all", "none"), make(stringSet)},
{intRanges{}, intRanges{}, makeStringSet("a-b"), makeStringSet("abort", "a-b")},
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, intRanges{}, make(stringSet), make(stringSet)},
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5), makeIntRange(6, 6), makeIntRange(7, 7), makeIntRange(8, 8)}, intRanges{}, make(stringSet), make(stringSet)},
{intRanges{}, intRanges{}, make(stringSet), make(stringSet)},
{intRanges{}, intRanges{}, make(stringSet), make(stringSet)},
{intRanges{}, intRanges{}, makeStringSet("a", "b", "c", "d", "e"), make(stringSet)},
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, intRanges{}, make(types.StringSet), make(types.StringSet)},
{intRanges{makeIntRange(1, 10), makeIntRange(5, 15)}, intRanges{}, make(types.StringSet), make(types.StringSet)},
{intRanges{makeIntRange(5, 10), makeIntRange(85, 90)}, intRanges{}, make(types.StringSet), make(types.StringSet)},
{intRanges{makeIntRange(1, 1), makeIntRange(99, 99), makeIntRange(60, 62)}, intRanges{makeIntRange(2, 2), makeIntRange(5, 10), makeIntRange(38, 40), makeIntRange(123, 123)}, make(types.StringSet), make(types.StringSet)},
{intRanges{}, intRanges{}, types.MakeStringSet("abort", "all", "none"), make(types.StringSet)},
{intRanges{}, intRanges{}, types.MakeStringSet("a-b"), types.MakeStringSet("abort", "a-b")},
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, intRanges{}, make(types.StringSet), make(types.StringSet)},
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5), makeIntRange(6, 6), makeIntRange(7, 7), makeIntRange(8, 8)}, intRanges{}, make(types.StringSet), make(types.StringSet)},
{intRanges{}, intRanges{}, make(types.StringSet), make(types.StringSet)},
{intRanges{}, intRanges{}, make(types.StringSet), make(types.StringSet)},
{intRanges{}, intRanges{}, types.MakeStringSet("a", "b", "c", "d", "e"), make(types.StringSet)},
}
for n, in := range inputs {
@ -91,8 +73,8 @@ func TestParseNumberMenu(t *testing.T) {
if !intRangesEqual(include, res.Include) ||
!intRangesEqual(exclude, res.Exclude) ||
!stringSetEqual(otherInclude, res.OtherInclude) ||
!stringSetEqual(otherExclude, res.OtherExclude) {
!types.StringSetEqual(otherInclude, res.OtherInclude) ||
!types.StringSetEqual(otherExclude, res.OtherExclude) {
t.Fatalf("Test %d Failed: Expected: include=%+v exclude=%+v otherInclude=%+v otherExclude=%+v got include=%+v excluive=%+v otherInclude=%+v otherExclude=%+v",
n+1, res.Include, res.Exclude, res.OtherInclude, res.OtherExclude, include, exclude, otherInclude, otherExclude)

98
pkg/types/stringset.go Normal file
View file

@ -0,0 +1,98 @@
package types
// StringSet is a basic set implementation for strings.
// This is used a lot so it deserves its own type.
// Other types of sets are used throughout the code but do not have
// their own typedef.
// String sets and <type>sets should be used throughout the code when applicable,
// they are a lot more flexible than slices and provide easy lookup.
type StringSet map[string]struct{}
// MapStringSet is a Map of StringSets.
type MapStringSet map[string]StringSet
// Add adds a new value to the Map.
func (mss MapStringSet) Add(n string, v string) {
_, ok := mss[n]
if !ok {
mss[n] = make(StringSet)
}
mss[n].Set(v)
}
// Set sets key in StringSet.
func (set StringSet) Set(v string) {
set[v] = struct{}{}
}
// Get returns true if the key exists in the set.
func (set StringSet) Get(v string) bool {
_, exists := set[v]
return exists
}
// Remove deletes a key from the set.
func (set StringSet) Remove(v string) {
delete(set, v)
}
// ToSlice turns all keys into a string slice.
func (set StringSet) ToSlice() []string {
slice := make([]string, 0, len(set))
for v := range set {
slice = append(slice, v)
}
return slice
}
// Copy copies a StringSet into a new structure of the same type.
func (set StringSet) Copy() StringSet {
newSet := make(StringSet)
for str := range set {
newSet.Set(str)
}
return newSet
}
// SliceToStringSet creates a new StringSet from an input slice
func SliceToStringSet(in []string) StringSet {
set := make(StringSet)
for _, v := range in {
set.Set(v)
}
return set
}
// MakeStringSet creates a new StringSet from a set of arguments
func MakeStringSet(in ...string) StringSet {
return SliceToStringSet(in)
}
// StringSetEqual compares if two StringSets have the same values
func StringSetEqual(a, b StringSet) bool {
if a == nil && b == nil {
return true
}
if a == nil || b == nil {
return false
}
if len(a) != len(b) {
return false
}
for n := range a {
if !b.Get(n) {
return false
}
}
return true
}

View file

@ -12,6 +12,7 @@ import (
"strings"
"time"
"github.com/Jguer/yay/v9/pkg/types"
rpc "github.com/mikkeloscar/aur"
)
@ -208,7 +209,7 @@ func (do *depOrder) Print() {
aurMakeLen := 0
for _, pkg := range do.Repo {
if do.Runtime.get(pkg.Name()) {
if do.Runtime.Get(pkg.Name()) {
repo += " " + pkg.Name() + "-" + pkg.Version()
repoLen++
} else {
@ -231,7 +232,7 @@ func (do *depOrder) Print() {
pkgStrMake += " ("
for _, split := range base {
if do.Runtime.get(split.Name) {
if do.Runtime.Get(split.Name) {
pkgStr += split.Name + " "
aurLen++
push = true
@ -244,7 +245,7 @@ func (do *depOrder) Print() {
pkgStr = pkgStr[:len(pkgStr)-1] + ")"
pkgStrMake = pkgStrMake[:len(pkgStrMake)-1] + ")"
case do.Runtime.get(base[0].Name):
case do.Runtime.Get(base[0].Name):
aurLen++
push = true
default:
@ -389,7 +390,7 @@ func printNumberOfUpdates() error {
//TODO: Make it less hacky
func printUpdateList(parser *arguments) error {
targets := sliceToStringSet(parser.targets)
targets := types.SliceToStringSet(parser.targets)
warnings := &aurWarnings{}
old := os.Stdout // keep backup of the real stdout
os.Stdout = nil
@ -408,7 +409,7 @@ func printUpdateList(parser *arguments) error {
if !parser.existsArg("m", "foreign") {
for _, pkg := range repoUp {
if noTargets || targets.get(pkg.Name) {
if noTargets || targets.Get(pkg.Name) {
if parser.existsArg("q", "quiet") {
fmt.Printf("%s\n", pkg.Name)
} else {
@ -421,7 +422,7 @@ func printUpdateList(parser *arguments) error {
if !parser.existsArg("n", "native") {
for _, pkg := range aurUp {
if noTargets || targets.get(pkg.Name) {
if noTargets || targets.Get(pkg.Name) {
if parser.existsArg("q", "quiet") {
fmt.Printf("%s\n", pkg.Name)
} else {

View file

@ -342,7 +342,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(mapStringSet)
provides := make(types.MapStringSet)
packages := localDB.PkgCache()
// Mark explicit dependencies and enumerate the provides list

View file

@ -169,12 +169,12 @@ func upList(warnings *aurWarnings) (upSlice, upSlice, error) {
printLocalNewerThanAUR(remote, aurdata)
if develUp != nil {
names := make(stringSet)
names := make(types.StringSet)
for _, up := range develUp {
names.set(up.Name)
names.Set(up.Name)
}
for _, up := range aurUp {
if !names.get(up.Name) {
if !names.Get(up.Name) {
develUp = append(develUp, up)
}
}
@ -325,9 +325,9 @@ func upRepo(local []alpm.Package) (upSlice, error) {
}
// upgradePkgs handles updating the cache and installing updates.
func upgradePkgs(aurUp, repoUp upSlice) (stringSet, stringSet, error) {
ignore := make(stringSet)
aurNames := make(stringSet)
func upgradePkgs(aurUp, repoUp upSlice) (types.StringSet, types.StringSet, error) {
ignore := make(types.StringSet)
aurNames := make(types.StringSet)
allUpLen := len(repoUp) + len(aurUp)
if allUpLen == 0 {
@ -336,7 +336,7 @@ func upgradePkgs(aurUp, repoUp upSlice) (stringSet, stringSet, error) {
if !config.UpgradeMenu {
for _, pkg := range aurUp {
aurNames.set(pkg.Name)
aurNames.Set(pkg.Name)
}
return ignore, aurNames, nil
@ -364,32 +364,32 @@ func upgradePkgs(aurUp, repoUp upSlice) (stringSet, stringSet, error) {
isInclude := len(exclude) == 0 && len(otherExclude) == 0
for i, pkg := range repoUp {
if isInclude && otherInclude.get(pkg.Repository) {
ignore.set(pkg.Name)
if isInclude && otherInclude.Get(pkg.Repository) {
ignore.Set(pkg.Name)
}
if isInclude && !include.get(len(repoUp)-i+len(aurUp)) {
continue
}
if !isInclude && (exclude.get(len(repoUp)-i+len(aurUp)) || otherExclude.get(pkg.Repository)) {
if !isInclude && (exclude.get(len(repoUp)-i+len(aurUp)) || otherExclude.Get(pkg.Repository)) {
continue
}
ignore.set(pkg.Name)
ignore.Set(pkg.Name)
}
for i, pkg := range aurUp {
if isInclude && otherInclude.get(pkg.Repository) {
if isInclude && otherInclude.Get(pkg.Repository) {
continue
}
if isInclude && !include.get(len(aurUp)-i) {
aurNames.set(pkg.Name)
aurNames.Set(pkg.Name)
}
if !isInclude && (exclude.get(len(aurUp)-i) || otherExclude.get(pkg.Repository)) {
aurNames.set(pkg.Name)
if !isInclude && (exclude.get(len(aurUp)-i) || otherExclude.Get(pkg.Repository)) {
aurNames.Set(pkg.Name)
}
}

View file

@ -6,8 +6,6 @@ import (
const gitEmptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
type mapStringSet map[string]stringSet
type intRange struct {
min int
max int
@ -50,14 +48,6 @@ func max(a, b int) int {
return a
}
func (mss mapStringSet) Add(n string, v string) {
_, ok := mss[n]
if !ok {
mss[n] = make(stringSet)
}
mss[n].set(v)
}
func stringSliceEqual(a, b []string) bool {
if a == nil && b == nil {
return true

3
vcs.go
View file

@ -9,6 +9,7 @@ import (
"sync"
"time"
"github.com/Jguer/yay/v9/pkg/types"
gosrc "github.com/Morganamilo/go-srcinfo"
)
@ -37,7 +38,7 @@ func createDevelDB() error {
}
bases := getBases(info)
toSkip := pkgbuildsToSkip(bases, sliceToStringSet(remoteNames))
toSkip := pkgbuildsToSkip(bases, types.SliceToStringSet(remoteNames))
downloadPkgbuilds(bases, toSkip, config.BuildDir)
srcinfos, _ := parseSrcinfoFiles(bases, false)