moved Upgrade to db

to reduce dependencies
This commit is contained in:
Jannis M. Hoffmann 2021-02-16 16:49:38 +01:00 committed by J Guerreiro
parent 5d2c763fdb
commit df1361aa05
8 changed files with 44 additions and 47 deletions

View file

@ -4,13 +4,23 @@ import (
"time"
alpm "github.com/Jguer/go-alpm/v2"
"github.com/Jguer/yay/v10/pkg/upgrade"
)
type IPackage = alpm.IPackage
type Depend = alpm.Depend
func VerCmp(a string, b string) int {
return alpm.VerCmp(a, b)
}
type Upgrade struct {
Name string
Repository string
LocalVersion string
RemoteVersion string
Reason alpm.PkgReason
}
type Executor interface {
AlpmArch() (string, error)
BiggestPackages() []IPackage
@ -28,7 +38,7 @@ type Executor interface {
PackageProvides(IPackage) []Depend
PackagesFromGroup(string) []IPackage
RefreshHandle() error
RepoUpgrades(bool) (upgrade.UpSlice, error)
RepoUpgrades(bool) ([]Upgrade, error)
SyncPackage(string) IPackage
SyncPackages(...string) []IPackage
SyncSatisfier(string) IPackage

View file

@ -12,6 +12,7 @@ import (
pacmanconf "github.com/Morganamilo/go-pacmanconf"
"github.com/leonelquinteros/gotext"
"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/settings"
"github.com/Jguer/yay/v10/pkg/text"
"github.com/Jguer/yay/v10/pkg/upgrade"
@ -398,7 +399,7 @@ func (ae *AlpmExecutor) PackageGroups(pkg alpm.IPackage) []string {
// upRepo gathers local packages and checks if they have new versions.
// Output: Upgrade type package list.
func (ae *AlpmExecutor) RepoUpgrades(enableDowngrade bool) (upgrade.UpSlice, error) {
func (ae *AlpmExecutor) RepoUpgrades(enableDowngrade bool) ([]db.Upgrade, error) {
slice := upgrade.UpSlice{}
localDB, err := ae.handle.LocalDB()

View file

@ -3,8 +3,6 @@ package dep
import (
"strings"
alpm "github.com/Jguer/go-alpm/v2"
"github.com/Jguer/yay/v10/pkg/db"
rpc "github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/text"
@ -93,15 +91,15 @@ func provideSatisfies(provide, dep, pkgVersion string) bool {
func verSatisfies(ver1, mod, ver2 string) bool {
switch mod {
case "=":
return alpm.VerCmp(ver1, ver2) == 0
return db.VerCmp(ver1, ver2) == 0
case "<":
return alpm.VerCmp(ver1, ver2) < 0
return db.VerCmp(ver1, ver2) < 0
case "<=":
return alpm.VerCmp(ver1, ver2) <= 0
return db.VerCmp(ver1, ver2) <= 0
case ">":
return alpm.VerCmp(ver1, ver2) > 0
return db.VerCmp(ver1, ver2) > 0
case ">=":
return alpm.VerCmp(ver1, ver2) >= 0
return db.VerCmp(ver1, ver2) >= 0
}
return true
@ -121,7 +119,7 @@ func satisfiesAur(dep string, pkg *rpc.Pkg) bool {
return false
}
func satisfiesRepo(dep string, pkg alpm.IPackage, dbExecutor db.Executor) bool {
func satisfiesRepo(dep string, pkg db.IPackage, dbExecutor db.Executor) bool {
if pkgSatisfies(pkg.Name(), pkg.Version(), dep) {
return true
}

View file

@ -3,8 +3,7 @@ package dep
import (
"fmt"
alpm "github.com/Jguer/go-alpm/v2"
"github.com/Jguer/yay/v10/pkg/db"
rpc "github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/stringset"
"github.com/Jguer/yay/v10/pkg/text"
@ -12,14 +11,14 @@ import (
type Order struct {
Aur []Base
Repo []alpm.IPackage
Repo []db.IPackage
Runtime stringset.StringSet
}
func makeOrder() *Order {
return &Order{
make([]Base, 0),
make([]alpm.IPackage, 0),
make([]db.IPackage, 0),
make(stringset.StringSet),
}
}
@ -78,7 +77,7 @@ func (do *Order) orderPkgAur(pkg *rpc.Pkg, dp *Pool, runtime bool) {
do.Aur = append(do.Aur, Base{pkg})
}
func (do *Order) orderPkgRepo(pkg alpm.IPackage, dp *Pool, runtime bool) {
func (do *Order) orderPkgRepo(pkg db.IPackage, dp *Pool, runtime bool) {
if runtime {
do.Runtime.Set(pkg.Name())
}

View file

@ -11,8 +11,6 @@ import (
"github.com/leonelquinteros/gotext"
alpm "github.com/Jguer/go-alpm/v2"
"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/settings"
@ -54,7 +52,7 @@ func (t Target) String() string {
type Pool struct {
Targets []Target
Explicit stringset.StringSet
Repo map[string]alpm.IPackage
Repo map[string]db.IPackage
Aur map[string]*query.Pkg
AurCache map[string]*query.Pkg
Groups []string
@ -66,7 +64,7 @@ func makePool(dbExecutor db.Executor) *Pool {
dp := &Pool{
make([]Target, 0),
make(stringset.StringSet),
make(map[string]alpm.IPackage),
make(map[string]db.IPackage),
make(map[string]*query.Pkg),
make(map[string]*query.Pkg),
make([]string, 0),
@ -100,7 +98,7 @@ func (dp *Pool) ResolveTargets(pkgs []string,
continue
}
var foundPkg alpm.IPackage
var foundPkg db.IPackage
// aur/ prefix means we only check the aur
if target.DB == "aur" || mode == settings.ModeAUR {
@ -326,7 +324,7 @@ func (dp *Pool) resolveAURPackages(pkgs stringset.StringSet,
return err
}
func (dp *Pool) ResolveRepoDependency(pkg alpm.IPackage) {
func (dp *Pool) ResolveRepoDependency(pkg db.IPackage) {
dp.Repo[pkg.Name()] = pkg
for _, dep := range dp.AlpmExecutor.PackageDepends(pkg) {
@ -440,7 +438,7 @@ func (dp *Pool) findSatisfierAurCache(dep string, ignoreProviders, noConfirm, pr
return nil
}
func (dp *Pool) findSatisfierRepo(dep string) alpm.IPackage {
func (dp *Pool) findSatisfierRepo(dep string) db.IPackage {
for _, pkg := range dp.Repo {
if satisfiesRepo(dep, pkg, dp.AlpmExecutor) {
return pkg

View file

@ -3,8 +3,6 @@ package query
import (
"github.com/leonelquinteros/gotext"
"github.com/Jguer/go-alpm/v2"
"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/settings"
"github.com/Jguer/yay/v10/pkg/text"
@ -25,7 +23,7 @@ func GetPackageNamesBySource(dbExecutor db.Executor) (local, remote []string, er
// GetRemotePackages returns packages with no correspondence in SyncDBS.
func GetRemotePackages(dbExecutor db.Executor) (
remote []alpm.IPackage,
remote []db.IPackage,
remoteNames []string) {
for _, localpkg := range dbExecutor.LocalPackages() {
pkgName := localpkg.Name()

View file

@ -3,19 +3,19 @@ package upgrade
import (
"sync"
alpm "github.com/Jguer/go-alpm/v2"
"github.com/leonelquinteros/gotext"
rpc "github.com/mikkeloscar/aur"
"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/text"
"github.com/Jguer/yay/v10/pkg/vcs"
)
func UpDevel(
remote []alpm.IPackage,
aurdata map[string]*rpc.Pkg,
remote []db.IPackage,
aurdata map[string]*query.Pkg,
localCache *vcs.InfoStore) UpSlice {
toUpdate := make([]alpm.IPackage, 0, len(aurdata))
toUpdate := make([]db.IPackage, 0, len(aurdata))
toRemove := make([]string, 0)
var mux1, mux2 sync.Mutex
@ -68,7 +68,7 @@ func UpDevel(
return toUpgrade
}
func printIgnoringPackage(pkg alpm.IPackage, newPkgVersion string) {
func printIgnoringPackage(pkg db.IPackage, newPkgVersion string) {
left, right := GetVersionDiff(pkg.Version(), newPkgVersion)
text.Warnln(gotext.Get("%s: ignoring package upgrade (%s => %s)",
@ -79,7 +79,7 @@ func printIgnoringPackage(pkg alpm.IPackage, newPkgVersion string) {
// UpAUR gathers foreign packages and checks if they have new versions.
// Output: Upgrade type package list.
func UpAUR(remote []alpm.IPackage, aurdata map[string]*rpc.Pkg, timeUpdate bool) UpSlice {
func UpAUR(remote []db.IPackage, aurdata map[string]*query.Pkg, timeUpdate bool) UpSlice {
toUpgrade := make(UpSlice, 0)
for _, pkg := range remote {
@ -89,7 +89,7 @@ func UpAUR(remote []alpm.IPackage, aurdata map[string]*rpc.Pkg, timeUpdate bool)
}
if (timeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) ||
(alpm.VerCmp(pkg.Version(), aurPkg.Version) < 0) {
(db.VerCmp(pkg.Version(), aurPkg.Version) < 0) {
if pkg.ShouldIgnore() {
printIgnoringPackage(pkg, aurPkg.Version)
} else {

View file

@ -4,25 +4,18 @@ import (
"fmt"
"unicode"
"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/intrange"
"github.com/Jguer/yay/v10/pkg/text"
alpm "github.com/Jguer/go-alpm/v2"
)
// Filter decides if specific package should be included in theincluded in the results.
type Filter func(Upgrade) bool
// Upgrade type describes a system upgrade.
type Upgrade struct {
Name string
Repository string
LocalVersion string
RemoteVersion string
Reason alpm.PkgReason
}
type Upgrade = db.Upgrade
func (u *Upgrade) StylizedNameWithRepository() string {
func StylizedNameWithRepository(u *Upgrade) string {
return text.Bold(text.ColorHash(u.Repository)) + "/" + text.Bold(u.Name)
}
@ -94,7 +87,7 @@ func GetVersionDiff(oldVersion, newVersion string) (left, right string) {
func (u UpSlice) Print() {
longestName, longestVersion := 0, 0
for _, pack := range u {
packNameLen := len(pack.StylizedNameWithRepository())
packNameLen := len(StylizedNameWithRepository(&pack))
packVersion, _ := GetVersionDiff(pack.LocalVersion, pack.RemoteVersion)
packVersionLen := len(packVersion)
longestName = intrange.Max(packNameLen, longestName)
@ -110,7 +103,7 @@ func (u UpSlice) Print() {
fmt.Print(text.Magenta(fmt.Sprintf(numberPadding, len(u)-k)))
fmt.Printf(namePadding, i.StylizedNameWithRepository())
fmt.Printf(namePadding, StylizedNameWithRepository(&i))
fmt.Printf("%s -> %s\n", fmt.Sprintf(versionPadding, left), right)
}