Merge pull request #1064 from Morganamilo/refactor-files

Refactor files
This commit is contained in:
J Guerreiro 2019-10-17 00:27:44 +01:00 committed by GitHub
commit 9e773149e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 163 additions and 150 deletions

1
.gitignore vendored
View File

@ -24,3 +24,4 @@ yay
yay_*/
*.tar.gz
qemu-*
.go

View File

@ -6,7 +6,7 @@ import (
"os"
"path/filepath"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/stringset"
)
// GetPkgbuild gets the pkgbuild of the package 'pkg' trying the ABS first and then the AUR trying the ABS first and then the AUR.
@ -109,8 +109,8 @@ func syncClean(parser *arguments) error {
func cleanAUR(keepInstalled, keepCurrent, removeAll bool) error {
fmt.Println("removing AUR packages from cache...")
installedBases := make(types.StringSet)
inAURBases := make(types.StringSet)
installedBases := make(stringset.StringSet)
inAURBases := make(stringset.StringSet)
_, remotePackages, _, _, err := filterPackages()
if err != nil {

4
cmd.go
View File

@ -8,7 +8,7 @@ import (
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/completion"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/intrange"
)
var cmdArgs = makeArguments()
@ -355,7 +355,7 @@ func displayNumberMenu(pkgS []string) (err error) {
return fmt.Errorf("Input too long")
}
include, exclude, _, otherExclude := types.ParseNumberMenu(string(numberBuf))
include, exclude, _, otherExclude := intrange.ParseNumberMenu(string(numberBuf))
arguments := cmdArgs.copyGlobal()
isInclude := len(exclude) == 0 && len(otherExclude) == 0

3
dep.go
View File

@ -5,7 +5,6 @@ import (
"strings"
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
rpc "github.com/mikkeloscar/aur"
)
@ -34,7 +33,7 @@ func (q providers) Less(i, j int) bool {
return false
}
return types.LessRunes([]rune(q.Pkgs[i].Name), []rune(q.Pkgs[j].Name))
return LessRunes([]rune(q.Pkgs[i].Name), []rune(q.Pkgs[j].Name))
}
func (q providers) Swap(i, j int) {

View File

@ -7,10 +7,10 @@ import (
"sync"
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/stringset"
)
func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts types.MapStringSet) {
func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts stringset.MapStringSet) {
for _, pkg := range dp.Aur {
if pkg.Name == name {
continue
@ -32,7 +32,7 @@ func (dp *depPool) checkInnerConflict(name string, conflict string, conflicts ty
}
}
func (dp *depPool) checkForwardConflict(name string, conflict string, conflicts types.MapStringSet) {
func (dp *depPool) checkForwardConflict(name string, conflict string, conflicts stringset.MapStringSet) {
_ = dp.LocalDB.PkgCache().ForEach(func(pkg alpm.Package) error {
if pkg.Name() == name || dp.hasPackage(pkg.Name()) {
return nil
@ -50,7 +50,7 @@ func (dp *depPool) checkForwardConflict(name string, conflict string, conflicts
})
}
func (dp *depPool) checkReverseConflict(name string, conflict string, conflicts types.MapStringSet) {
func (dp *depPool) checkReverseConflict(name string, conflict string, conflicts stringset.MapStringSet) {
for _, pkg := range dp.Aur {
if pkg.Name == name {
continue
@ -80,7 +80,7 @@ func (dp *depPool) checkReverseConflict(name string, conflict string, conflicts
}
}
func (dp *depPool) checkInnerConflicts(conflicts types.MapStringSet) {
func (dp *depPool) checkInnerConflicts(conflicts stringset.MapStringSet) {
for _, pkg := range dp.Aur {
for _, conflict := range pkg.Conflicts {
dp.checkInnerConflict(pkg.Name, conflict, conflicts)
@ -95,7 +95,7 @@ func (dp *depPool) checkInnerConflicts(conflicts types.MapStringSet) {
}
}
func (dp *depPool) checkForwardConflicts(conflicts types.MapStringSet) {
func (dp *depPool) checkForwardConflicts(conflicts stringset.MapStringSet) {
for _, pkg := range dp.Aur {
for _, conflict := range pkg.Conflicts {
dp.checkForwardConflict(pkg.Name, conflict, conflicts)
@ -110,7 +110,7 @@ func (dp *depPool) checkForwardConflicts(conflicts types.MapStringSet) {
}
}
func (dp *depPool) checkReverseConflicts(conflicts types.MapStringSet) {
func (dp *depPool) checkReverseConflicts(conflicts stringset.MapStringSet) {
_ = dp.LocalDB.PkgCache().ForEach(func(pkg alpm.Package) error {
if dp.hasPackage(pkg.Name()) {
return nil
@ -125,10 +125,10 @@ func (dp *depPool) checkReverseConflicts(conflicts types.MapStringSet) {
})
}
func (dp *depPool) CheckConflicts() (types.MapStringSet, error) {
func (dp *depPool) CheckConflicts() (stringset.MapStringSet, error) {
var wg sync.WaitGroup
innerConflicts := make(types.MapStringSet)
conflicts := make(types.MapStringSet)
innerConflicts := make(stringset.MapStringSet)
conflicts := make(stringset.MapStringSet)
wg.Add(2)
fmt.Println(bold(cyan("::") + bold(" Checking for conflicts...")))
@ -182,9 +182,9 @@ func (dp *depPool) CheckConflicts() (types.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(types.StringSet)
conflicts[name] = make(stringset.StringSet)
for pkg := range pkgs {
conflicts[pkg] = make(types.StringSet)
conflicts[pkg] = make(stringset.StringSet)
}
}
@ -204,7 +204,7 @@ func (dp *depPool) CheckConflicts() (types.MapStringSet, error) {
}
type missing struct {
Good types.StringSet
Good stringset.StringSet
Missing map[string][][]string
}
@ -261,7 +261,7 @@ func (dp *depPool) _checkMissing(dep string, stack []string, missing *missing) {
func (dp *depPool) CheckMissing() error {
missing := &missing{
make(types.StringSet),
make(stringset.StringSet),
make(map[string][][]string),
}

View File

@ -2,7 +2,7 @@ package main
import (
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/stringset"
rpc "github.com/mikkeloscar/aur"
)
@ -27,14 +27,14 @@ func (b Base) URLPath() string {
type depOrder struct {
Aur []Base
Repo []*alpm.Package
Runtime types.StringSet
Runtime stringset.StringSet
}
func makeDepOrder() *depOrder {
return &depOrder{
make([]Base, 0),
make([]*alpm.Package, 0),
make(types.StringSet),
make(stringset.StringSet),
}
}

View File

@ -6,7 +6,7 @@ import (
"sync"
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/stringset"
rpc "github.com/mikkeloscar/aur"
)
@ -43,7 +43,7 @@ func (t target) String() string {
type depPool struct {
Targets []target
Explicit types.StringSet
Explicit stringset.StringSet
Repo map[string]*alpm.Package
Aur map[string]*rpc.Pkg
AurCache map[string]*rpc.Pkg
@ -65,7 +65,7 @@ func makeDepPool() (*depPool, error) {
dp := &depPool{
make([]target, 0),
make(types.StringSet),
make(stringset.StringSet),
make(map[string]*alpm.Package),
make(map[string]*rpc.Pkg),
make(map[string]*rpc.Pkg),
@ -83,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(types.StringSet)
aurTargets := make(stringset.StringSet)
pkgs = removeInvalidTargets(pkgs)
@ -173,7 +173,7 @@ func (dp *depPool) ResolveTargets(pkgs []string) error {
// positives.
//
// This method increases dependency resolve time
func (dp *depPool) findProvides(pkgs types.StringSet) error {
func (dp *depPool) findProvides(pkgs stringset.StringSet) error {
var mux sync.Mutex
var wg sync.WaitGroup
@ -220,7 +220,7 @@ func (dp *depPool) findProvides(pkgs types.StringSet) error {
return nil
}
func (dp *depPool) cacheAURPackages(_pkgs types.StringSet) error {
func (dp *depPool) cacheAURPackages(_pkgs stringset.StringSet) error {
pkgs := _pkgs.Copy()
query := make([]string, 0)
@ -261,9 +261,9 @@ func (dp *depPool) cacheAURPackages(_pkgs types.StringSet) error {
return nil
}
func (dp *depPool) resolveAURPackages(pkgs types.StringSet, explicit bool) error {
newPackages := make(types.StringSet)
newAURPackages := make(types.StringSet)
func (dp *depPool) resolveAURPackages(pkgs stringset.StringSet, explicit bool) error {
newPackages := make(stringset.StringSet)
newAURPackages := make(stringset.StringSet)
err := dp.cacheAURPackages(pkgs)
if err != nil {
@ -387,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(types.StringSet)
seen := make(stringset.StringSet)
providers := makeProviders(depName)
if dp.LocalDB.Pkg(depName) != nil {

View File

@ -11,7 +11,7 @@ import (
"sync"
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/multierror"
)
const gitDiffRefName = "AUR_SEEN"
@ -265,7 +265,7 @@ func getPkgbuilds(pkgs []string) error {
func getPkgbuildsfromABS(pkgs []string, path string) (bool, error) {
var wg sync.WaitGroup
var mux sync.Mutex
var errs types.MultiError
var errs multierror.MultiError
names := make(map[string]string)
missing := make([]string, 0)
downloaded := 0

View File

@ -11,7 +11,9 @@ import (
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/completion"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/intrange"
"github.com/Jguer/yay/v9/pkg/multierror"
"github.com/Jguer/yay/v9/pkg/stringset"
gosrc "github.com/Morganamilo/go-srcinfo"
)
@ -49,7 +51,7 @@ func asexp(parser *arguments, pkgs []string) error {
// Install handles package installs
func install(parser *arguments) (err error) {
var incompatible types.StringSet
var incompatible stringset.StringSet
var do *depOrder
var aurUp upSlice
@ -87,8 +89,8 @@ func install(parser *arguments) (err error) {
return err
}
remoteNamesCache := types.SliceToStringSet(remoteNames)
localNamesCache := types.SliceToStringSet(localNames)
remoteNamesCache := stringset.FromSlice(remoteNames)
localNamesCache := stringset.FromSlice(localNames)
requestTargets := parser.copy().targets
@ -140,7 +142,7 @@ func install(parser *arguments) (err error) {
}
}
targets := types.SliceToStringSet(parser.targets)
targets := stringset.FromSlice(parser.targets)
dp, err := getDepPool(requestTargets, warnings)
if err != nil {
@ -451,8 +453,8 @@ func earlyRefresh(parser *arguments) error {
return show(passToPacman(arguments))
}
func getIncompatible(bases []Base, srcinfos map[string]*gosrc.Srcinfo) (types.StringSet, error) {
incompatible := make(types.StringSet)
func getIncompatible(bases []Base, srcinfos map[string]*gosrc.Srcinfo) (stringset.StringSet, error) {
incompatible := make(stringset.StringSet)
basesMap := make(map[string]Base)
alpmArch, err := alpmHandle.Arch()
if err != nil {
@ -535,7 +537,7 @@ func anyExistInCache(bases []Base) bool {
return false
}
func pkgbuildNumberMenu(bases []Base, installed types.StringSet) bool {
func pkgbuildNumberMenu(bases []Base, installed stringset.StringSet) bool {
toPrint := ""
askClean := false
@ -568,7 +570,7 @@ func pkgbuildNumberMenu(bases []Base, installed types.StringSet) bool {
return askClean
}
func cleanNumberMenu(bases []Base, installed types.StringSet, hasClean bool) ([]Base, error) {
func cleanNumberMenu(bases []Base, installed stringset.StringSet, hasClean bool) ([]Base, error) {
toClean := make([]Base, 0)
if !hasClean {
@ -583,7 +585,7 @@ func cleanNumberMenu(bases []Base, installed types.StringSet, hasClean bool) ([]
return nil, err
}
cInclude, cExclude, cOtherInclude, cOtherExclude := types.ParseNumberMenu(cleanInput)
cInclude, cExclude, cOtherInclude, cOtherExclude := intrange.ParseNumberMenu(cleanInput)
cIsInclude := len(cExclude) == 0 && len(cOtherExclude) == 0
if cOtherInclude.Get("abort") || cOtherInclude.Get("ab") {
@ -637,15 +639,15 @@ func cleanNumberMenu(bases []Base, installed types.StringSet, hasClean bool) ([]
return toClean, nil
}
func editNumberMenu(bases []Base, installed types.StringSet) ([]Base, error) {
func editNumberMenu(bases []Base, installed stringset.StringSet) ([]Base, error) {
return editDiffNumberMenu(bases, installed, false)
}
func diffNumberMenu(bases []Base, installed types.StringSet) ([]Base, error) {
func diffNumberMenu(bases []Base, installed stringset.StringSet) ([]Base, error) {
return editDiffNumberMenu(bases, installed, true)
}
func editDiffNumberMenu(bases []Base, installed types.StringSet, diff bool) ([]Base, error) {
func editDiffNumberMenu(bases []Base, installed stringset.StringSet, diff bool) ([]Base, error) {
toEdit := make([]Base, 0)
var editInput string
var err error
@ -668,7 +670,7 @@ func editDiffNumberMenu(bases []Base, installed types.StringSet, diff bool) ([]B
}
}
eInclude, eExclude, eOtherInclude, eOtherExclude := types.ParseNumberMenu(editInput)
eInclude, eExclude, eOtherInclude, eOtherExclude := intrange.ParseNumberMenu(editInput)
eIsInclude := len(eExclude) == 0 && len(eOtherExclude) == 0
if eOtherInclude.Get("abort") || eOtherInclude.Get("ab") {
@ -715,8 +717,8 @@ func editDiffNumberMenu(bases []Base, installed types.StringSet, diff bool) ([]B
return toEdit, nil
}
func updatePkgbuildSeenRef(bases []Base, cloned types.StringSet) error {
var errMulti types.MultiError
func updatePkgbuildSeenRef(bases []Base, cloned stringset.StringSet) error {
var errMulti multierror.MultiError
for _, base := range bases {
pkg := base.Pkgbase()
dir := filepath.Join(config.BuildDir, pkg)
@ -730,8 +732,8 @@ func updatePkgbuildSeenRef(bases []Base, cloned types.StringSet) error {
return errMulti.Return()
}
func showPkgbuildDiffs(bases []Base, cloned types.StringSet) error {
var errMulti types.MultiError
func showPkgbuildDiffs(bases []Base, cloned stringset.StringSet) error {
var errMulti multierror.MultiError
for _, base := range bases {
pkg := base.Pkgbase()
dir := filepath.Join(config.BuildDir, pkg)
@ -840,8 +842,8 @@ func parseSrcinfoFiles(bases []Base, errIsFatal bool) (map[string]*gosrc.Srcinfo
return srcinfos, nil
}
func pkgbuildsToSkip(bases []Base, targets types.StringSet) types.StringSet {
toSkip := make(types.StringSet)
func pkgbuildsToSkip(bases []Base, targets stringset.StringSet) stringset.StringSet {
toSkip := make(stringset.StringSet)
for _, base := range bases {
isTarget := false
@ -879,12 +881,12 @@ func mergePkgbuilds(bases []Base) error {
return nil
}
func downloadPkgbuilds(bases []Base, toSkip types.StringSet, buildDir string) (types.StringSet, error) {
cloned := make(types.StringSet)
func downloadPkgbuilds(bases []Base, toSkip stringset.StringSet, buildDir string) (stringset.StringSet, error) {
cloned := make(stringset.StringSet)
downloaded := 0
var wg sync.WaitGroup
var mux sync.Mutex
var errs types.MultiError
var errs multierror.MultiError
download := func(k int, base Base) {
defer wg.Done()
@ -940,7 +942,7 @@ func downloadPkgbuilds(bases []Base, toSkip types.StringSet, buildDir string) (t
return cloned, errs.Return()
}
func downloadPkgbuildsSources(bases []Base, incompatible types.StringSet) (err error) {
func downloadPkgbuildsSources(bases []Base, incompatible stringset.StringSet) (err error) {
for _, base := range bases {
pkg := base.Pkgbase()
dir := filepath.Join(config.BuildDir, pkg)
@ -959,7 +961,7 @@ func downloadPkgbuildsSources(bases []Base, incompatible types.StringSet) (err e
return
}
func buildInstallPkgbuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc.Srcinfo, parser *arguments, incompatible types.StringSet, conflicts types.MapStringSet) error {
func buildInstallPkgbuilds(dp *depPool, do *depOrder, srcinfos map[string]*gosrc.Srcinfo, parser *arguments, incompatible stringset.StringSet, conflicts stringset.MapStringSet) error {
arguments := parser.copy()
arguments.clearTargets()
arguments.op = "U"
@ -985,8 +987,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 := types.SliceToStringSet(remoteNames)
localNamesCache := types.SliceToStringSet(localNames)
remoteNamesCache := stringset.FromSlice(remoteNames)
localNamesCache := stringset.FromSlice(localNames)
doInstall := func() error {
if len(arguments.targets) == 0 {

View File

@ -9,7 +9,7 @@ import (
"strconv"
"strings"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/stringset"
rpc "github.com/mikkeloscar/aur"
)
@ -19,7 +19,7 @@ type arguments struct {
op string
options map[string]string
globals map[string]string
doubles types.StringSet // Tracks args passed twice such as -yy and -dd
doubles stringset.StringSet // Tracks args passed twice such as -yy and -dd
targets []string
}
@ -28,7 +28,7 @@ func makeArguments() *arguments {
"",
make(map[string]string),
make(map[string]string),
make(types.StringSet),
make(stringset.StringSet),
make([]string, 0),
}
}

View File

@ -1,9 +1,11 @@
package types
package intrange
import (
"strconv"
"strings"
"unicode"
"github.com/Jguer/yay/v9/pkg/stringset"
)
// IntRange stores a max and min amount for range
@ -66,11 +68,11 @@ func Max(a, b int) int {
//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, stringset.StringSet, stringset.StringSet) {
include := make(IntRanges, 0)
exclude := make(IntRanges, 0)
otherInclude := make(StringSet)
otherExclude := make(StringSet)
otherInclude := make(stringset.StringSet)
otherExclude := make(stringset.StringSet)
words := strings.FieldsFunc(input, func(c rune) bool {
return unicode.IsSpace(c) || c == ','

View File

@ -1,15 +1,16 @@
package types
package intrange
import (
"testing"
"github.com/Jguer/yay/v9/pkg/stringset"
"testing"
)
func TestParseNumberMenu(t *testing.T) {
type result struct {
Include IntRanges
Exclude IntRanges
OtherInclude StringSet
OtherExclude StringSet
OtherInclude stringset.StringSet
OtherExclude stringset.StringSet
}
inputs := []string{
@ -28,18 +29,18 @@ 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{}, IntRanges{}, MakeStringSet("-9223372036854775809-9223372036854775809"), make(StringSet)},
{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(stringset.StringSet), make(stringset.StringSet)},
{IntRanges{makeIntRange(1, 10), makeIntRange(5, 15)}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)},
{IntRanges{makeIntRange(5, 10), makeIntRange(85, 90)}, IntRanges{}, make(stringset.StringSet), make(stringset.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.StringSet), make(stringset.StringSet)},
{IntRanges{}, IntRanges{}, stringset.Make("abort", "all", "none"), make(stringset.StringSet)},
{IntRanges{}, IntRanges{}, stringset.Make("a-b"), stringset.Make("abort", "a-b")},
{IntRanges{}, IntRanges{}, stringset.Make("-9223372036854775809-9223372036854775809"), make(stringset.StringSet)},
{IntRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, IntRanges{}, make(stringset.StringSet), make(stringset.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.StringSet), make(stringset.StringSet)},
{IntRanges{}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)},
{IntRanges{}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)},
{IntRanges{}, IntRanges{}, stringset.Make("a", "b", "c", "d", "e"), make(stringset.StringSet)},
}
for n, in := range inputs {
@ -48,8 +49,8 @@ func TestParseNumberMenu(t *testing.T) {
if !intRangesEqual(include, res.Include) ||
!intRangesEqual(exclude, res.Exclude) ||
!StringSetEqual(otherInclude, res.OtherInclude) ||
!StringSetEqual(otherExclude, res.OtherExclude) {
!stringset.Equal(otherInclude, res.OtherInclude) ||
!stringset.Equal(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)

View File

@ -1,4 +1,4 @@
package types
package multierror
import "sync"

View File

@ -1,4 +1,4 @@
package types
package stringset
// StringSet is a basic set implementation for strings.
// This is used a lot so it deserves its own type.
@ -12,6 +12,8 @@ type StringSet map[string]struct{}
type MapStringSet map[string]StringSet
// Add adds a new value to the Map.
// If n is already in the map, then v is appended to the StringSet under that key.
// Otherwise a new StringSet is creayed containing v
func (mss MapStringSet) Add(n string, v string) {
_, ok := mss[n]
if !ok {
@ -58,8 +60,8 @@ func (set StringSet) Copy() StringSet {
return newSet
}
// SliceToStringSet creates a new StringSet from an input slice
func SliceToStringSet(in []string) StringSet {
// FromSlice creates a new StringSet from an input slice
func FromSlice(in []string) StringSet {
set := make(StringSet)
for _, v := range in {
@ -69,13 +71,13 @@ func SliceToStringSet(in []string) StringSet {
return set
}
// MakeStringSet creates a new StringSet from a set of arguments
func MakeStringSet(in ...string) StringSet {
return SliceToStringSet(in)
// Make creates a new StringSet from a set of arguments
func Make(in ...string) StringSet {
return FromSlice(in)
}
// StringSetEqual compares if two StringSets have the same values
func StringSetEqual(a, b StringSet) bool {
// Equal compares if two StringSets have the same values
func Equal(a, b StringSet) bool {
if a == nil && b == nil {
return true
}

View File

@ -1,30 +0,0 @@
package types
import "unicode"
// LessRunes compares two rune values, and returns true if the first argument is lexicographicaly smaller.
func LessRunes(iRunes, jRunes []rune) bool {
max := len(iRunes)
if max > len(jRunes) {
max = len(jRunes)
}
for idx := 0; idx < max; idx++ {
ir := iRunes[idx]
jr := jRunes[idx]
lir := unicode.ToLower(ir)
ljr := unicode.ToLower(jr)
if lir != ljr {
return lir < ljr
}
// the lowercase runes are the same, so compare the original
if ir != jr {
return ir < jr
}
}
return len(iRunes) < len(jRunes)
}

View File

@ -12,7 +12,9 @@ import (
"strings"
"time"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/intrange"
"github.com/Jguer/yay/v9/pkg/stringset"
rpc "github.com/mikkeloscar/aur"
)
@ -177,8 +179,8 @@ func (u upSlice) print() {
packNameLen := len(pack.StylizedNameWithRepository())
version, _ := getVersionDiff(pack.LocalVersion, pack.RemoteVersion)
packVersionLen := len(version)
longestName = types.Max(packNameLen, longestName)
longestVersion = types.Max(packVersionLen, longestVersion)
longestName = intrange.Max(packNameLen, longestName)
longestVersion = intrange.Max(packVersionLen, longestVersion)
}
namePadding := fmt.Sprintf("%%-%ds ", longestName)
@ -390,7 +392,7 @@ func printNumberOfUpdates() error {
//TODO: Make it less hacky
func printUpdateList(parser *arguments) error {
targets := types.SliceToStringSet(parser.targets)
targets := stringset.FromSlice(parser.targets)
warnings := &aurWarnings{}
old := os.Stdout // keep backup of the real stdout
os.Stdout = nil

View File

@ -9,7 +9,10 @@ import (
"time"
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/intrange"
"github.com/Jguer/yay/v9/pkg/multierror"
"github.com/Jguer/yay/v9/pkg/stringset"
rpc "github.com/mikkeloscar/aur"
)
@ -38,9 +41,9 @@ func (q aurQuery) Less(i, j int) bool {
case "popularity":
result = q[i].Popularity > q[j].Popularity
case "name":
result = types.LessRunes([]rune(q[i].Name), []rune(q[j].Name))
result = LessRunes([]rune(q[i].Name), []rune(q[j].Name))
case "base":
result = types.LessRunes([]rune(q[i].PackageBase), []rune(q[j].PackageBase))
result = LessRunes([]rune(q[i].PackageBase), []rune(q[j].PackageBase))
case "submitted":
result = q[i].FirstSubmitted < q[j].FirstSubmitted
case "modified":
@ -363,7 +366,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(types.MapStringSet)
provides := make(stringset.MapStringSet)
packages := localDB.PkgCache()
// Mark explicit dependencies and enumerate the provides list
@ -500,7 +503,7 @@ func aurInfo(names []string, warnings *aurWarnings) ([]*rpc.Pkg, error) {
seen := make(map[string]int)
var mux sync.Mutex
var wg sync.WaitGroup
var errs types.MultiError
var errs multierror.MultiError
makeRequest := func(n, max int) {
defer wg.Done()
@ -518,7 +521,7 @@ func aurInfo(names []string, warnings *aurWarnings) ([]*rpc.Pkg, error) {
}
for n := 0; n < len(names); n += config.RequestSplitN {
max := types.Min(len(names), n+config.RequestSplitN)
max := intrange.Min(len(names), n+config.RequestSplitN)
wg.Add(1)
go makeRequest(n, max)
}

View File

@ -7,7 +7,10 @@ import (
"unicode"
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/intrange"
"github.com/Jguer/yay/v9/pkg/multierror"
"github.com/Jguer/yay/v9/pkg/stringset"
rpc "github.com/mikkeloscar/aur"
)
@ -29,14 +32,14 @@ func (u upSlice) Less(i, j int) bool {
if u[i].Repository == u[j].Repository {
iRunes := []rune(u[i].Name)
jRunes := []rune(u[j].Name)
return types.LessRunes(iRunes, jRunes)
return LessRunes(iRunes, jRunes)
}
syncDB, err := alpmHandle.SyncDBs()
if err != nil {
iRunes := []rune(u[i].Repository)
jRunes := []rune(u[j].Repository)
return types.LessRunes(iRunes, jRunes)
return LessRunes(iRunes, jRunes)
}
less := false
@ -59,7 +62,7 @@ func (u upSlice) Less(i, j int) bool {
iRunes := []rune(u[i].Repository)
jRunes := []rune(u[j].Repository)
return types.LessRunes(iRunes, jRunes)
return LessRunes(iRunes, jRunes)
}
@ -121,7 +124,7 @@ func upList(warnings *aurWarnings) (upSlice, upSlice, error) {
var repoUp upSlice
var aurUp upSlice
var errs types.MultiError
var errs multierror.MultiError
aurdata := make(map[string]*rpc.Pkg)
@ -169,7 +172,7 @@ func upList(warnings *aurWarnings) (upSlice, upSlice, error) {
printLocalNewerThanAUR(remote, aurdata)
if develUp != nil {
names := make(types.StringSet)
names := make(stringset.StringSet)
for _, up := range develUp {
names.Set(up.Name)
}
@ -330,9 +333,9 @@ func upRepo(local []alpm.Package) (upSlice, error) {
}
// upgradePkgs handles updating the cache and installing updates.
func upgradePkgs(aurUp, repoUp upSlice) (types.StringSet, types.StringSet, error) {
ignore := make(types.StringSet)
aurNames := make(types.StringSet)
func upgradePkgs(aurUp, repoUp upSlice) (stringset.StringSet, stringset.StringSet, error) {
ignore := make(stringset.StringSet)
aurNames := make(stringset.StringSet)
allUpLen := len(repoUp) + len(aurUp)
if allUpLen == 0 {
@ -364,7 +367,7 @@ func upgradePkgs(aurUp, repoUp upSlice) (types.StringSet, types.StringSet, error
//upgrade menu asks you which packages to NOT upgrade so in this case
//include and exclude are kind of swapped
//include, exclude, other := parseNumberMenu(string(numberBuf))
include, exclude, otherInclude, otherExclude := types.ParseNumberMenu(numbers)
include, exclude, otherInclude, otherExclude := intrange.ParseNumberMenu(numbers)
isInclude := len(exclude) == 0 && len(otherExclude) == 0

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"unicode"
)
const gitEmptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
@ -49,3 +50,30 @@ func removeInvalidTargets(targets []string) []string {
return filteredTargets
}
// LessRunes compares two rune values, and returns true if the first argument is lexicographicaly smaller.
func LessRunes(iRunes, jRunes []rune) bool {
max := len(iRunes)
if max > len(jRunes) {
max = len(jRunes)
}
for idx := 0; idx < max; idx++ {
ir := iRunes[idx]
jr := jRunes[idx]
lir := unicode.ToLower(ir)
ljr := unicode.ToLower(jr)
if lir != ljr {
return lir < ljr
}
// the lowercase runes are the same, so compare the original
if ir != jr {
return ir < jr
}
}
return len(iRunes) < len(jRunes)
}

View File

@ -1,4 +1,4 @@
package types
package main
import "testing"

4
vcs.go
View File

@ -9,7 +9,7 @@ import (
"sync"
"time"
"github.com/Jguer/yay/v9/pkg/types"
"github.com/Jguer/yay/v9/pkg/stringset"
gosrc "github.com/Morganamilo/go-srcinfo"
)
@ -38,7 +38,7 @@ func createDevelDB() error {
}
bases := getBases(info)
toSkip := pkgbuildsToSkip(bases, types.SliceToStringSet(remoteNames))
toSkip := pkgbuildsToSkip(bases, stringset.FromSlice(remoteNames))
_, err = downloadPkgbuilds(bases, toSkip, config.BuildDir)
if err != nil {
return err