1
0
mirror of https://github.com/Jguer/yay synced 2024-07-08 04:16:16 +00:00

fix(clean_menu): optimize any base installed

This commit is contained in:
jguer 2021-10-11 00:18:57 +02:00 committed by J Guerreiro
parent a43fbacc96
commit f3c3e2e4d4
3 changed files with 17 additions and 17 deletions

View File

@ -36,11 +36,7 @@ func cleanNumberMenu(bases []dep.Base, installed stringset.StringSet) ([]dep.Bas
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 := base.AnyIsInSet(installed)
dir := filepath.Join(config.BuildDir, pkg)
if _, err := os.Stat(dir); os.IsNotExist(err) {

View File

@ -564,12 +564,7 @@ func pkgbuildNumberMenu(bases []dep.Base, installed stringset.StringSet) {
toPrint += fmt.Sprintf(text.Magenta("%3d")+" %-40s", len(bases)-n,
text.Bold(base.String()))
anyInstalled := false
for _, b := range base {
anyInstalled = anyInstalled || installed.Get(b.Name)
}
if anyInstalled {
if base.AnyIsInSet(installed) {
toPrint += text.Bold(text.Green(gotext.Get(" (Installed)")))
}
@ -625,11 +620,7 @@ func editDiffNumberMenu(bases []dep.Base, installed stringset.StringSet, diff bo
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 := base.AnyIsInSet(installed)
if !eIsInclude && eExclude.Get(len(bases)-i) {
continue

View File

@ -1,6 +1,9 @@
package dep
import aur "github.com/Jguer/yay/v11/pkg/query"
import (
aur "github.com/Jguer/yay/v11/pkg/query"
"github.com/Jguer/yay/v11/pkg/stringset"
)
// Base is an AUR base package.
type Base []*aur.Pkg
@ -20,6 +23,16 @@ func (b Base) URLPath() string {
return b[0].URLPath
}
func (b Base) AnyIsInSet(set stringset.StringSet) bool {
for _, pkg := range b {
if set.Get(pkg.Name) {
return true
}
}
return false
}
// Packages foo and bar from a pkgbase named base would print like so:
// base (foo bar).
func (b Base) String() string {