mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 09:07:21 +01:00
chore(yay): add local newer to AUR warnings (#2113)
This commit is contained in:
parent
161fede450
commit
83214fbc1c
@ -8,15 +8,17 @@ import (
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/stringset"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
type AURWarnings struct {
|
||||
Orphans []string
|
||||
OutOfDate []string
|
||||
Missing []string
|
||||
Ignore stringset.StringSet
|
||||
Orphans []string
|
||||
OutOfDate []string
|
||||
Missing []string
|
||||
LocalNewer []string
|
||||
Ignore stringset.StringSet
|
||||
|
||||
log *text.Logger
|
||||
}
|
||||
@ -42,6 +44,17 @@ func (warnings *AURWarnings) AddToWarnings(remote map[string]alpm.IPackage, aurP
|
||||
if aurPkg.OutOfDate != 0 && !pkg.ShouldIgnore() {
|
||||
warnings.OutOfDate = append(warnings.OutOfDate, name)
|
||||
}
|
||||
|
||||
if !pkg.ShouldIgnore() && !isDevelPackage(pkg) && db.VerCmp(pkg.Version(), aurPkg.Version) > 0 {
|
||||
left, right := GetVersionDiff(pkg.Version(), aurPkg.Version)
|
||||
|
||||
newerMsg := gotext.Get("%s: local (%s) is newer than AUR (%s)",
|
||||
text.Cyan(name),
|
||||
left, right,
|
||||
)
|
||||
|
||||
warnings.LocalNewer = append(warnings.LocalNewer, newerMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func (warnings *AURWarnings) CalculateMissing(remoteNames []string, remote map[string]alpm.IPackage, aurData map[string]*aur.Pkg) {
|
||||
@ -70,6 +83,12 @@ func (warnings *AURWarnings) Print() {
|
||||
if len(warnings.OutOfDate) > 0 {
|
||||
warnings.log.Warnln(gotext.Get("Flagged Out Of Date AUR Packages:"), formatNames(warnings.OutOfDate))
|
||||
}
|
||||
|
||||
if len(warnings.LocalNewer) > 0 {
|
||||
for _, newer := range warnings.LocalNewer {
|
||||
warnings.log.Warnln(newer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func filterDebugPkgs(names []string) (normal, debug []string) {
|
||||
|
73
pkg/query/version_diff.go
Normal file
73
pkg/query/version_diff.go
Normal file
@ -0,0 +1,73 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
)
|
||||
|
||||
func GetVersionDiff(oldVersion, newVersion string) (left, right string) {
|
||||
if oldVersion == newVersion {
|
||||
return oldVersion + text.Red(""), newVersion + text.Green("")
|
||||
}
|
||||
|
||||
diffPosition := 0
|
||||
|
||||
checkWords := func(str string, index int, words ...string) bool {
|
||||
for _, word := range words {
|
||||
wordLength := len(word)
|
||||
|
||||
nextIndex := index + 1
|
||||
if (index < len(str)-wordLength) &&
|
||||
(str[nextIndex:(nextIndex+wordLength)] == word) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
for index, char := range oldVersion {
|
||||
charIsSpecial := !(unicode.IsLetter(char) || unicode.IsNumber(char))
|
||||
|
||||
if (index >= len(newVersion)) || (char != rune(newVersion[index])) {
|
||||
if charIsSpecial {
|
||||
diffPosition = index
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if charIsSpecial ||
|
||||
(((index == len(oldVersion)-1) || (index == len(newVersion)-1)) &&
|
||||
((len(oldVersion) != len(newVersion)) ||
|
||||
(oldVersion[index] == newVersion[index]))) ||
|
||||
checkWords(oldVersion, index, "rc", "pre", "alpha", "beta") {
|
||||
diffPosition = index + 1
|
||||
}
|
||||
}
|
||||
|
||||
samePart := oldVersion[0:diffPosition]
|
||||
|
||||
left = samePart + text.Red(oldVersion[diffPosition:])
|
||||
right = samePart + text.Green(newVersion[diffPosition:])
|
||||
|
||||
return left, right
|
||||
}
|
||||
|
||||
func isDevelName(name string) bool {
|
||||
for _, suffix := range []string{"git", "svn", "hg", "bzr", "nightly", "insiders-bin"} {
|
||||
if strings.HasSuffix(name, "-"+suffix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Contains(name, "-always-")
|
||||
}
|
||||
|
||||
func isDevelPackage(pkg alpm.IPackage) bool {
|
||||
return isDevelName(pkg.Name()) || isDevelName(pkg.Base())
|
||||
}
|
@ -54,7 +54,7 @@ func UpDevel(
|
||||
}
|
||||
|
||||
func printIgnoringPackage(log *text.Logger, pkg db.IPackage, newPkgVersion string) {
|
||||
left, right := GetVersionDiff(pkg.Version(), newPkgVersion)
|
||||
left, right := query.GetVersionDiff(pkg.Version(), newPkgVersion)
|
||||
|
||||
pkgName := pkg.Name()
|
||||
log.Warnln(gotext.Get("%s: ignoring package upgrade (%s => %s)",
|
||||
|
@ -3,10 +3,10 @@ package upgrade
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/db"
|
||||
"github.com/Jguer/yay/v12/pkg/intrange"
|
||||
"github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
@ -51,55 +51,6 @@ func (u UpSlice) Less(i, j int) bool {
|
||||
return text.LessRunes(iRunes, jRunes)
|
||||
}
|
||||
|
||||
func GetVersionDiff(oldVersion, newVersion string) (left, right string) {
|
||||
if oldVersion == newVersion {
|
||||
return oldVersion + text.Red(""), newVersion + text.Green("")
|
||||
}
|
||||
|
||||
diffPosition := 0
|
||||
|
||||
checkWords := func(str string, index int, words ...string) bool {
|
||||
for _, word := range words {
|
||||
wordLength := len(word)
|
||||
|
||||
nextIndex := index + 1
|
||||
if (index < len(str)-wordLength) &&
|
||||
(str[nextIndex:(nextIndex+wordLength)] == word) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
for index, char := range oldVersion {
|
||||
charIsSpecial := !(unicode.IsLetter(char) || unicode.IsNumber(char))
|
||||
|
||||
if (index >= len(newVersion)) || (char != rune(newVersion[index])) {
|
||||
if charIsSpecial {
|
||||
diffPosition = index
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if charIsSpecial ||
|
||||
(((index == len(oldVersion)-1) || (index == len(newVersion)-1)) &&
|
||||
((len(oldVersion) != len(newVersion)) ||
|
||||
(oldVersion[index] == newVersion[index]))) ||
|
||||
checkWords(oldVersion, index, "rc", "pre", "alpha", "beta") {
|
||||
diffPosition = index + 1
|
||||
}
|
||||
}
|
||||
|
||||
samePart := oldVersion[0:diffPosition]
|
||||
|
||||
left = samePart + text.Red(oldVersion[diffPosition:])
|
||||
right = samePart + text.Green(newVersion[diffPosition:])
|
||||
|
||||
return left, right
|
||||
}
|
||||
|
||||
// Print prints the details of the packages to upgrade.
|
||||
func (u UpSlice) Print(logger *text.Logger) {
|
||||
longestName, longestVersion := 0, 0
|
||||
@ -107,7 +58,7 @@ func (u UpSlice) Print(logger *text.Logger) {
|
||||
for k := range u.Up {
|
||||
upgrade := &u.Up[k]
|
||||
packNameLen := len(StylizedNameWithRepository(upgrade))
|
||||
packVersion, _ := GetVersionDiff(upgrade.LocalVersion, upgrade.RemoteVersion)
|
||||
packVersion, _ := query.GetVersionDiff(upgrade.LocalVersion, upgrade.RemoteVersion)
|
||||
packVersionLen := len(packVersion)
|
||||
longestName = intrange.Max(packNameLen, longestName)
|
||||
longestVersion = intrange.Max(packVersionLen, longestVersion)
|
||||
@ -121,7 +72,7 @@ func (u UpSlice) Print(logger *text.Logger) {
|
||||
|
||||
for k := range u.Up {
|
||||
upgrade := &u.Up[k]
|
||||
left, right := GetVersionDiff(upgrade.LocalVersion, upgrade.RemoteVersion)
|
||||
left, right := query.GetVersionDiff(upgrade.LocalVersion, upgrade.RemoteVersion)
|
||||
|
||||
logger.Printf(text.Magenta(fmt.Sprintf(numberPadding, lenUp-k)))
|
||||
|
||||
|
@ -3,6 +3,7 @@ package upgrade
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Jguer/yay/v12/pkg/query"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
@ -57,7 +58,7 @@ func TestGetVersionDiff(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, pair := range in {
|
||||
o, n := GetVersionDiff(pair.Old, pair.New)
|
||||
o, n := query.GetVersionDiff(pair.Old, pair.New)
|
||||
|
||||
if o != out[i].Old || n != out[i].New {
|
||||
t.Errorf("Test %-2d failed for update: expected (%s => %s) got (%s => %s) %d %d %d %d",
|
||||
|
@ -159,7 +159,7 @@ func printLocalNewerThanAUR(
|
||||
continue
|
||||
}
|
||||
|
||||
left, right := upgrade.GetVersionDiff(pkg.Version(), aurPkg.Version)
|
||||
left, right := query.GetVersionDiff(pkg.Version(), aurPkg.Version)
|
||||
|
||||
if !isDevelPackage(pkg) && db.VerCmp(pkg.Version(), aurPkg.Version) > 0 {
|
||||
text.Warnln(gotext.Get("%s: local (%s) is newer than AUR (%s)",
|
||||
|
Loading…
Reference in New Issue
Block a user