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