mirror of
https://github.com/Jguer/yay
synced 2024-08-31 05:39:29 +00:00
Make UpSlice a struct instead of a type alias
This commit is contained in:
parent
64e5b9e93d
commit
f04a469324
|
@ -400,7 +400,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) ([]db.Upgrade, error) {
|
||||
slice := upgrade.UpSlice{}
|
||||
slice := []db.Upgrade{}
|
||||
|
||||
localDB, err := ae.handle.LocalDB()
|
||||
if err != nil {
|
||||
|
|
|
@ -49,12 +49,12 @@ func UpDevel(
|
|||
|
||||
wg.Wait()
|
||||
|
||||
toUpgrade := make(UpSlice, 0, len(toUpdate))
|
||||
toUpgrade := UpSlice{Up: make([]Upgrade, 0)}
|
||||
for _, pkg := range toUpdate {
|
||||
if pkg.ShouldIgnore() {
|
||||
printIgnoringPackage(pkg, "latest-commit")
|
||||
} else {
|
||||
toUpgrade = append(toUpgrade,
|
||||
toUpgrade.Up = append(toUpgrade.Up,
|
||||
Upgrade{
|
||||
Name: pkg.Name(),
|
||||
Repository: "devel",
|
||||
|
@ -80,7 +80,7 @@ func printIgnoringPackage(pkg db.IPackage, newPkgVersion string) {
|
|||
// UpAUR gathers foreign packages and checks if they have new versions.
|
||||
// Output: Upgrade type package list.
|
||||
func UpAUR(remote []db.IPackage, aurdata map[string]*query.Pkg, timeUpdate bool) UpSlice {
|
||||
toUpgrade := make(UpSlice, 0)
|
||||
toUpgrade := UpSlice{Up: make([]Upgrade, 0)}
|
||||
|
||||
for _, pkg := range remote {
|
||||
aurPkg, ok := aurdata[pkg.Name()]
|
||||
|
@ -93,7 +93,7 @@ func UpAUR(remote []db.IPackage, aurdata map[string]*query.Pkg, timeUpdate bool)
|
|||
if pkg.ShouldIgnore() {
|
||||
printIgnoringPackage(pkg, aurPkg.Version)
|
||||
} else {
|
||||
toUpgrade = append(toUpgrade,
|
||||
toUpgrade.Up = append(toUpgrade.Up,
|
||||
Upgrade{
|
||||
Name: aurPkg.Name,
|
||||
Repository: "aur",
|
||||
|
|
|
@ -20,20 +20,23 @@ func StylizedNameWithRepository(u Upgrade) string {
|
|||
}
|
||||
|
||||
// upSlice is a slice of Upgrades
|
||||
type UpSlice []Upgrade
|
||||
type UpSlice struct {
|
||||
Up []Upgrade
|
||||
}
|
||||
|
||||
func (u UpSlice) Len() int { return len(u) }
|
||||
func (u UpSlice) Swap(i, j int) { u[i], u[j] = u[j], u[i] }
|
||||
func (u UpSlice) Len() int { return len(u.Up) }
|
||||
func (u UpSlice) Swap(i, j int) { u.Up[i], u.Up[j] = u.Up[j], u.Up[i] }
|
||||
|
||||
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)
|
||||
up := u.Up
|
||||
if up[i].Repository == up[j].Repository {
|
||||
iRunes := []rune(up[i].Name)
|
||||
jRunes := []rune(up[j].Name)
|
||||
return text.LessRunes(iRunes, jRunes)
|
||||
}
|
||||
|
||||
iRunes := []rune(u[i].Repository)
|
||||
jRunes := []rune(u[j].Repository)
|
||||
iRunes := []rune(up[i].Repository)
|
||||
jRunes := []rune(up[j].Repository)
|
||||
return text.LessRunes(iRunes, jRunes)
|
||||
}
|
||||
|
||||
|
@ -86,7 +89,7 @@ func GetVersionDiff(oldVersion, newVersion string) (left, right string) {
|
|||
// Print prints the details of the packages to upgrade.
|
||||
func (u UpSlice) Print() {
|
||||
longestName, longestVersion := 0, 0
|
||||
for _, pack := range u {
|
||||
for _, pack := range u.Up {
|
||||
packNameLen := len(StylizedNameWithRepository(pack))
|
||||
packVersion, _ := GetVersionDiff(pack.LocalVersion, pack.RemoteVersion)
|
||||
packVersionLen := len(packVersion)
|
||||
|
@ -96,12 +99,12 @@ func (u UpSlice) Print() {
|
|||
|
||||
namePadding := fmt.Sprintf("%%-%ds ", longestName)
|
||||
versionPadding := fmt.Sprintf("%%-%ds", longestVersion)
|
||||
numberPadding := fmt.Sprintf("%%%dd ", len(fmt.Sprintf("%v", len(u))))
|
||||
numberPadding := fmt.Sprintf("%%%dd ", len(fmt.Sprintf("%v", len(u.Up))))
|
||||
|
||||
for k, i := range u {
|
||||
for k, i := range u.Up {
|
||||
left, right := GetVersionDiff(i.LocalVersion, i.RemoteVersion)
|
||||
|
||||
fmt.Print(text.Magenta(fmt.Sprintf(numberPadding, len(u)-k)))
|
||||
fmt.Print(text.Magenta(fmt.Sprintf(numberPadding, len(u.Up)-k)))
|
||||
|
||||
fmt.Printf(namePadding, StylizedNameWithRepository(i))
|
||||
|
||||
|
|
6
print.go
6
print.go
|
@ -193,7 +193,7 @@ func printNumberOfUpdates(dbExecutor db.Executor, enableDowngrade bool, filter u
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(len(aurUp) + len(repoUp))
|
||||
fmt.Println(len(aurUp.Up) + len(repoUp.Up))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ func printUpdateList(cmdArgs *settings.Arguments, dbExecutor db.Executor, enable
|
|||
noTargets := len(targets) == 0
|
||||
|
||||
if !cmdArgs.ExistsArg("m", "foreign") {
|
||||
for _, pkg := range repoUp {
|
||||
for _, pkg := range repoUp.Up {
|
||||
if noTargets || targets.Get(pkg.Name) {
|
||||
if cmdArgs.ExistsArg("q", "quiet") {
|
||||
fmt.Printf("%s\n", pkg.Name)
|
||||
|
@ -232,7 +232,7 @@ func printUpdateList(cmdArgs *settings.Arguments, dbExecutor db.Executor, enable
|
|||
}
|
||||
|
||||
if !cmdArgs.ExistsArg("n", "native") {
|
||||
for _, pkg := range aurUp {
|
||||
for _, pkg := range aurUp.Up {
|
||||
if noTargets || targets.Get(pkg.Name) {
|
||||
if cmdArgs.ExistsArg("q", "quiet") {
|
||||
fmt.Printf("%s\n", pkg.Name)
|
||||
|
|
39
upgrade.go
39
upgrade.go
|
@ -20,7 +20,7 @@ import (
|
|||
"github.com/Jguer/yay/v10/pkg/upgrade"
|
||||
)
|
||||
|
||||
func filterUpdateList(list upgrade.UpSlice, filter upgrade.Filter) upgrade.UpSlice {
|
||||
func filterUpdateList(list []db.Upgrade, filter upgrade.Filter) []db.Upgrade {
|
||||
tmp := list[:0]
|
||||
for _, pkg := range list {
|
||||
if filter(pkg) {
|
||||
|
@ -37,6 +37,7 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
|||
|
||||
var wg sync.WaitGroup
|
||||
var develUp upgrade.UpSlice
|
||||
var repoSlice []db.Upgrade
|
||||
var errs multierror.MultiError
|
||||
|
||||
aurdata := make(map[string]*rpc.Pkg)
|
||||
|
@ -51,7 +52,7 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
|||
text.OperationInfoln(gotext.Get("Searching databases for updates..."))
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
repoUp, err = dbExecutor.RepoUpgrades(enableDowngrade)
|
||||
repoSlice, err = dbExecutor.RepoUpgrades(enableDowngrade)
|
||||
errs.Add(err)
|
||||
wg.Done()
|
||||
}()
|
||||
|
@ -88,22 +89,22 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
|||
wg.Wait()
|
||||
|
||||
printLocalNewerThanAUR(remote, aurdata)
|
||||
|
||||
if develUp != nil {
|
||||
names := make(stringset.StringSet)
|
||||
for _, up := range develUp {
|
||||
for _, up := range develUp.Up {
|
||||
names.Set(up.Name)
|
||||
}
|
||||
for _, up := range aurUp {
|
||||
for _, up := range aurUp.Up {
|
||||
if !names.Get(up.Name) {
|
||||
develUp = append(develUp, up)
|
||||
develUp.Up = append(develUp.Up, up)
|
||||
}
|
||||
}
|
||||
|
||||
aurUp = develUp
|
||||
}
|
||||
|
||||
return filterUpdateList(aurUp, filter), filterUpdateList(repoUp, filter), errs.Return()
|
||||
repoUp = upgrade.UpSlice{Up: repoSlice}
|
||||
|
||||
aurUp.Up = filterUpdateList(aurUp.Up, filter)
|
||||
repoUp.Up = filterUpdateList(repoUp.Up, filter)
|
||||
return aurUp, repoUp, errs.Return()
|
||||
}
|
||||
|
||||
func printLocalNewerThanAUR(
|
||||
|
@ -144,13 +145,13 @@ func upgradePkgsMenu(aurUp, repoUp upgrade.UpSlice) (stringset.StringSet, []stri
|
|||
ignore := make(stringset.StringSet)
|
||||
targets := []string{}
|
||||
|
||||
allUpLen := len(repoUp) + len(aurUp)
|
||||
allUpLen := len(repoUp.Up) + len(aurUp.Up)
|
||||
if allUpLen == 0 {
|
||||
return ignore, nil, nil
|
||||
}
|
||||
|
||||
if !config.UpgradeMenu {
|
||||
for _, pkg := range aurUp {
|
||||
for _, pkg := range aurUp.Up {
|
||||
targets = append(targets, pkg.Name)
|
||||
}
|
||||
|
||||
|
@ -159,7 +160,7 @@ func upgradePkgsMenu(aurUp, repoUp upgrade.UpSlice) (stringset.StringSet, []stri
|
|||
|
||||
sort.Sort(repoUp)
|
||||
sort.Sort(aurUp)
|
||||
allUp := append(repoUp, aurUp...)
|
||||
allUp := upgrade.UpSlice{Up: append(repoUp.Up, aurUp.Up...)}
|
||||
fmt.Printf("%s"+text.Bold(" %d ")+"%s\n", text.Bold(text.Cyan("::")), allUpLen, text.Bold(gotext.Get("Packages to upgrade.")))
|
||||
allUp.Print()
|
||||
|
||||
|
@ -176,17 +177,17 @@ func upgradePkgsMenu(aurUp, repoUp upgrade.UpSlice) (stringset.StringSet, []stri
|
|||
|
||||
isInclude := len(exclude) == 0 && len(otherExclude) == 0
|
||||
|
||||
for i, pkg := range repoUp {
|
||||
for i, pkg := range repoUp.Up {
|
||||
if isInclude && otherInclude.Get(pkg.Repository) {
|
||||
ignore.Set(pkg.Name)
|
||||
}
|
||||
|
||||
if isInclude && !include.Get(len(repoUp)-i+len(aurUp)) {
|
||||
if isInclude && !include.Get(len(repoUp.Up)-i+len(aurUp.Up)) {
|
||||
targets = append(targets, pkg.Name)
|
||||
continue
|
||||
}
|
||||
|
||||
if !isInclude && (exclude.Get(len(repoUp)-i+len(aurUp)) || otherExclude.Get(pkg.Repository)) {
|
||||
if !isInclude && (exclude.Get(len(repoUp.Up)-i+len(aurUp.Up)) || otherExclude.Get(pkg.Repository)) {
|
||||
targets = append(targets, pkg.Name)
|
||||
continue
|
||||
}
|
||||
|
@ -194,16 +195,16 @@ func upgradePkgsMenu(aurUp, repoUp upgrade.UpSlice) (stringset.StringSet, []stri
|
|||
ignore.Set(pkg.Name)
|
||||
}
|
||||
|
||||
for i, pkg := range aurUp {
|
||||
for i, pkg := range aurUp.Up {
|
||||
if isInclude && otherInclude.Get(pkg.Repository) {
|
||||
continue
|
||||
}
|
||||
|
||||
if isInclude && !include.Get(len(aurUp)-i) {
|
||||
if isInclude && !include.Get(len(aurUp.Up)-i) {
|
||||
targets = append(targets, "aur/"+pkg.Name)
|
||||
}
|
||||
|
||||
if !isInclude && (exclude.Get(len(aurUp)-i) || otherExclude.Get(pkg.Repository)) {
|
||||
if !isInclude && (exclude.Get(len(aurUp.Up)-i) || otherExclude.Get(pkg.Repository)) {
|
||||
targets = append(targets, "aur/"+pkg.Name)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue