mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 17:17:22 +01:00
Sort upslice by pacman repo order
This commit is contained in:
parent
f04a469324
commit
29f4c43227
1
go.mod
1
go.mod
@ -1,6 +1,7 @@
|
||||
module github.com/Jguer/yay/v10
|
||||
|
||||
require (
|
||||
github.com/Jguer/go-alpm v0.0.0-20200405152916-a3feea4322e9 // indirect
|
||||
github.com/Jguer/go-alpm/v2 v2.0.2
|
||||
github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f
|
||||
github.com/Morganamilo/go-srcinfo v1.0.0
|
||||
|
2
go.sum
2
go.sum
@ -1,3 +1,5 @@
|
||||
github.com/Jguer/go-alpm v0.0.0-20200405152916-a3feea4322e9 h1:lLQSUe6iRdtFrP0zkDV7n8I8XKSxRHQTEU1KRh4IOLg=
|
||||
github.com/Jguer/go-alpm v0.0.0-20200405152916-a3feea4322e9/go.mod h1:D5SUcIS9Yiz/L8cjRzq/992eERnx6ugYmGlc4e7xdus=
|
||||
github.com/Jguer/go-alpm/v2 v2.0.2 h1:BbF/6dg2tXISEJiCtxlX6J/TCSoB/g+31bCfEiH9D0c=
|
||||
github.com/Jguer/go-alpm/v2 v2.0.2/go.mod h1:zU4iKCtNkDARfj5BrKJXYAQ5nIjtZbySfa0paboSmTQ=
|
||||
github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f h1:ptFKynTV1p8JCzqk81NcMj0DV0Xle+PdKxfHjPbdIOU=
|
||||
|
@ -43,4 +43,5 @@ type Executor interface {
|
||||
SyncPackages(...string) []IPackage
|
||||
SyncSatisfier(string) IPackage
|
||||
SyncSatisfierExists(string) bool
|
||||
Repos() []string
|
||||
}
|
||||
|
@ -478,3 +478,11 @@ func (ae *AlpmExecutor) Cleanup() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) Repos() (repos []string) {
|
||||
_ = ae.syncDB.ForEach(func(db alpm.IDB) error {
|
||||
repos = append(repos, db.Name())
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func UpDevel(
|
||||
|
||||
wg.Wait()
|
||||
|
||||
toUpgrade := UpSlice{Up: make([]Upgrade, 0)}
|
||||
toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"devel"}}
|
||||
for _, pkg := range toUpdate {
|
||||
if pkg.ShouldIgnore() {
|
||||
printIgnoringPackage(pkg, "latest-commit")
|
||||
@ -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 := UpSlice{Up: make([]Upgrade, 0)}
|
||||
toUpgrade := UpSlice{Up: make([]Upgrade, 0), Repos: []string{"aur"}}
|
||||
|
||||
for _, pkg := range remote {
|
||||
aurPkg, ok := aurdata[pkg.Name()]
|
||||
|
@ -45,7 +45,7 @@ func Test_upAUR(t *testing.T) {
|
||||
},
|
||||
timeUpdate: false,
|
||||
},
|
||||
want: UpSlice{},
|
||||
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{}},
|
||||
},
|
||||
{
|
||||
name: "Simple Update",
|
||||
@ -54,7 +54,7 @@ func Test_upAUR(t *testing.T) {
|
||||
aurdata: map[string]*rpc.Pkg{"hello": {Version: "2.1.0", Name: "hello"}},
|
||||
timeUpdate: false,
|
||||
},
|
||||
want: UpSlice{Upgrade{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.1.0"}},
|
||||
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.1.0"}}},
|
||||
},
|
||||
{
|
||||
name: "Time Update",
|
||||
@ -63,7 +63,7 @@ func Test_upAUR(t *testing.T) {
|
||||
aurdata: map[string]*rpc.Pkg{"hello": {Version: "2.0.0", Name: "hello", LastModified: int(time.Now().AddDate(0, 0, 2).Unix())}},
|
||||
timeUpdate: true,
|
||||
},
|
||||
want: UpSlice{Upgrade{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.0.0"}},
|
||||
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.0.0"}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@ -147,7 +147,7 @@ func Test_upDevel(t *testing.T) {
|
||||
"ignored": {Version: "2.0.0", Name: "ignored"},
|
||||
},
|
||||
},
|
||||
want: UpSlice{},
|
||||
want: UpSlice{Repos: []string{"devel"}},
|
||||
},
|
||||
{
|
||||
name: "Simple Update",
|
||||
@ -203,19 +203,18 @@ func Test_upDevel(t *testing.T) {
|
||||
"hello4": {Version: "2.0.0", Name: "hello4"},
|
||||
},
|
||||
},
|
||||
want: UpSlice{
|
||||
Upgrade{
|
||||
Name: "hello",
|
||||
Repository: "devel",
|
||||
LocalVersion: "2.0.0",
|
||||
RemoteVersion: "latest-commit",
|
||||
},
|
||||
Upgrade{
|
||||
want: UpSlice{Repos: []string{"devel"}, Up: []Upgrade{{
|
||||
Name: "hello",
|
||||
Repository: "devel",
|
||||
LocalVersion: "2.0.0",
|
||||
RemoteVersion: "latest-commit",
|
||||
},
|
||||
{
|
||||
Name: "hello4",
|
||||
Repository: "devel",
|
||||
LocalVersion: "4.0.0",
|
||||
RemoteVersion: "latest-commit",
|
||||
},
|
||||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -238,7 +237,7 @@ func Test_upDevel(t *testing.T) {
|
||||
remote: []alpm.IPackage{&mock.Package{PName: "hello", PVersion: "2.0.0"}},
|
||||
aurdata: map[string]*rpc.Pkg{"hello": {Version: "2.0.0", Name: "hello"}},
|
||||
},
|
||||
want: UpSlice{},
|
||||
want: UpSlice{Repos: []string{"devel"}},
|
||||
},
|
||||
{
|
||||
name: "No update returned - ignored",
|
||||
@ -260,14 +259,14 @@ func Test_upDevel(t *testing.T) {
|
||||
remote: []alpm.IPackage{&mock.Package{PName: "hello", PVersion: "2.0.0", PShouldIgnore: true}},
|
||||
aurdata: map[string]*rpc.Pkg{"hello": {Version: "2.0.0", Name: "hello"}},
|
||||
},
|
||||
want: UpSlice{},
|
||||
want: UpSlice{Repos: []string{"devel"}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
config.Runtime.CmdRunner.(*MockRunner).t = t
|
||||
got := UpDevel(tt.args.remote, tt.args.aurdata, &tt.args.cached)
|
||||
assert.ElementsMatch(t, tt.want, got)
|
||||
assert.ElementsMatch(t, tt.want.Up, got.Up)
|
||||
assert.Equal(t, tt.finalLen, len(tt.args.cached.OriginsByPackage))
|
||||
})
|
||||
}
|
||||
|
@ -21,22 +21,30 @@ func StylizedNameWithRepository(u Upgrade) string {
|
||||
|
||||
// upSlice is a slice of Upgrades
|
||||
type UpSlice struct {
|
||||
Up []Upgrade
|
||||
Up []Upgrade
|
||||
Repos []string
|
||||
}
|
||||
|
||||
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 {
|
||||
up := u.Up
|
||||
if up[i].Repository == up[j].Repository {
|
||||
iRunes := []rune(up[i].Name)
|
||||
jRunes := []rune(up[j].Name)
|
||||
if u.Up[i].Repository == u.Up[j].Repository {
|
||||
iRunes := []rune(u.Up[i].Name)
|
||||
jRunes := []rune(u.Up[j].Name)
|
||||
return text.LessRunes(iRunes, jRunes)
|
||||
}
|
||||
|
||||
iRunes := []rune(up[i].Repository)
|
||||
jRunes := []rune(up[j].Repository)
|
||||
for _, db := range u.Repos {
|
||||
if db == u.Up[i].Repository {
|
||||
return true
|
||||
} else if db == u.Up[j].Repository {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
iRunes := []rune(u.Up[i].Repository)
|
||||
jRunes := []rune(u.Up[j].Repository)
|
||||
return text.LessRunes(iRunes, jRunes)
|
||||
}
|
||||
|
||||
|
@ -99,8 +99,9 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
||||
}
|
||||
}
|
||||
aurUp = develUp
|
||||
aurUp.Repos = []string{"aur", "devel"}
|
||||
|
||||
repoUp = upgrade.UpSlice{Up: repoSlice}
|
||||
repoUp = upgrade.UpSlice{Up: repoSlice, Repos: dbExecutor.Repos()}
|
||||
|
||||
aurUp.Up = filterUpdateList(aurUp.Up, filter)
|
||||
repoUp.Up = filterUpdateList(repoUp.Up, filter)
|
||||
@ -160,7 +161,7 @@ func upgradePkgsMenu(aurUp, repoUp upgrade.UpSlice) (stringset.StringSet, []stri
|
||||
|
||||
sort.Sort(repoUp)
|
||||
sort.Sort(aurUp)
|
||||
allUp := upgrade.UpSlice{Up: append(repoUp.Up, aurUp.Up...)}
|
||||
allUp := upgrade.UpSlice{Up: append(repoUp.Up, aurUp.Up...), Repos: append(repoUp.Repos, aurUp.Repos...)}
|
||||
fmt.Printf("%s"+text.Bold(" %d ")+"%s\n", text.Bold(text.Cyan("::")), allUpLen, text.Bold(gotext.Get("Packages to upgrade.")))
|
||||
allUp.Print()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user