From e807cd637fcf46e70bef93b266cc4e3e9a63415a Mon Sep 17 00:00:00 2001 From: morganamilo Date: Mon, 26 Mar 2018 02:28:31 +0100 Subject: [PATCH] Sort upgrade menu by pacman.conf order. When printing the upgrade menu, sort the repos in the order they are defined in pacman.conf (or more technically, the order they are registered in alpm). Packages in the same repo are still sorted alphabetically. If a repo is not in pacman.conf or the database query fails it will fallback to alphabetical. --- upgrade.go | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/upgrade.go b/upgrade.go index 2196e18d..66a190b0 100644 --- a/upgrade.go +++ b/upgrade.go @@ -27,15 +27,40 @@ 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) Less(i, j int) bool { - if u[i].Repository != u[j].Repository { - iRunes := []rune(u[i].Repository) - jRunes := []rune(u[j].Repository) - return lessRunes(iRunes, jRunes) - } else { + if u[i].Repository == u[j].Repository { iRunes := []rune(u[i].Name) jRunes := []rune(u[j].Name) return lessRunes(iRunes, jRunes) } + + syncDb, err := alpmHandle.SyncDbs() + if err != nil { + iRunes := []rune(u[i].Repository) + jRunes := []rune(u[j].Repository) + return lessRunes(iRunes, jRunes) + } + + less := false + found := syncDb.ForEach(func(db alpm.Db) error { + if db.Name() == u[i].Repository { + less = true + } else if db.Name() == u[j].Repository { + less = false + } else { + return nil + } + + return fmt.Errorf("") + }) + + if found != nil { + return less + } else { + iRunes := []rune(u[i].Repository) + jRunes := []rune(u[j].Repository) + return lessRunes(iRunes, jRunes) + } + } func getVersionDiff(oldVersion, newversion string) (left, right string) {