chore(upgrade): add makedep explain to the upgrade menu (#2110)

* display required by

* cutoff at 2
This commit is contained in:
Jo 2023-04-11 18:41:34 +02:00 committed by GitHub
parent 76e5ee1fa6
commit 4a9c736e2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 7 deletions

View File

@ -26,6 +26,7 @@ type Upgrade struct {
LocalVersion string LocalVersion string
RemoteVersion string RemoteVersion string
Reason alpm.PkgReason Reason alpm.PkgReason
Extra string // Extra information to be displayed
} }
type SyncUpgrade struct { type SyncUpgrade struct {

View File

@ -12,6 +12,16 @@ type (
DepMap[T comparable] map[T]NodeSet[T] DepMap[T comparable] map[T]NodeSet[T]
) )
func (n NodeSet[T]) Slice() []T {
var slice []T
for node := range n {
slice = append(slice, node)
}
return slice
}
type NodeInfo[V any] struct { type NodeInfo[V any] struct {
Color string Color string
Background string Background string
@ -253,10 +263,10 @@ func (g *Graph[T, V]) remove(node T) {
} }
func (g *Graph[T, V]) Dependencies(child T) NodeSet[T] { func (g *Graph[T, V]) Dependencies(child T) NodeSet[T] {
return g.buildTransitive(child, g.immediateDependencies) return g.buildTransitive(child, g.ImmediateDependencies)
} }
func (g *Graph[T, V]) immediateDependencies(node T) NodeSet[T] { func (g *Graph[T, V]) ImmediateDependencies(node T) NodeSet[T] {
return g.dependencies[node] return g.dependencies[node]
} }

View File

@ -2,7 +2,10 @@ package upgrade
import ( import (
"context" "context"
"fmt"
"math"
"sort" "sort"
"strings"
"github.com/Jguer/aur" "github.com/Jguer/aur"
"github.com/Jguer/go-alpm/v2" "github.com/Jguer/go-alpm/v2"
@ -20,6 +23,8 @@ import (
"github.com/Jguer/yay/v12/pkg/vcs" "github.com/Jguer/yay/v12/pkg/vcs"
) )
const cutOffExtra = 2
type UpgradeService struct { type UpgradeService struct {
grapher *dep.Grapher grapher *dep.Grapher
aurCache aur.QueryClient aurCache aur.QueryClient
@ -188,9 +193,19 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn
repoUp = UpSlice{Up: make([]Upgrade, 0, graph.Len()), Repos: u.dbExecutor.Repos()} repoUp = UpSlice{Up: make([]Upgrade, 0, graph.Len()), Repos: u.dbExecutor.Repos()}
_ = graph.ForEach(func(name string, info *dep.InstallInfo) error { _ = graph.ForEach(func(name string, info *dep.InstallInfo) error {
alpmReason := alpm.PkgReasonExplicit alpmReason := alpm.PkgReasonDepend
if info.Reason == dep.Dep { if info.Reason == dep.Explicit {
alpmReason = alpm.PkgReasonDepend alpmReason = alpm.PkgReasonExplicit
}
parents := graph.ImmediateDependencies(name)
extra := ""
if len(parents) > 0 && !info.Upgrade && info.Reason == dep.MakeDep {
reducedParents := parents.Slice()[:int(math.Min(cutOffExtra, float64(len(parents))))]
if len(parents) > cutOffExtra {
reducedParents = append(reducedParents, "...")
}
extra = fmt.Sprintf(" (%s of %s)", dep.ReasonNames[info.Reason], strings.Join(reducedParents, ", "))
} }
if info.Source == dep.AUR { if info.Source == dep.AUR {
@ -205,6 +220,7 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn
Base: *info.AURBase, Base: *info.AURBase,
LocalVersion: info.LocalVersion, LocalVersion: info.LocalVersion,
Reason: alpmReason, Reason: alpmReason,
Extra: extra,
}) })
} else if info.Source == dep.Sync { } else if info.Source == dep.Sync {
repoUp.Up = append(repoUp.Up, Upgrade{ repoUp.Up = append(repoUp.Up, Upgrade{
@ -214,6 +230,7 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn
Base: "", Base: "",
LocalVersion: info.LocalVersion, LocalVersion: info.LocalVersion,
Reason: alpmReason, Reason: alpmReason,
Extra: extra,
}) })
} }
return nil return nil

View File

@ -2,6 +2,7 @@ package upgrade
import ( import (
"fmt" "fmt"
"strings"
"unicode" "unicode"
"github.com/Jguer/yay/v12/pkg/db" "github.com/Jguer/yay/v12/pkg/db"
@ -112,18 +113,23 @@ func (u UpSlice) Print(logger *text.Logger) {
longestVersion = intrange.Max(packVersionLen, longestVersion) longestVersion = intrange.Max(packVersionLen, longestVersion)
} }
lenUp := len(u.Up)
longestNumber := len(fmt.Sprintf("%v", lenUp))
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.Up)))) numberPadding := fmt.Sprintf("%%%dd ", longestNumber)
for k := range u.Up { for k := range u.Up {
upgrade := &u.Up[k] upgrade := &u.Up[k]
left, right := GetVersionDiff(upgrade.LocalVersion, upgrade.RemoteVersion) left, right := GetVersionDiff(upgrade.LocalVersion, upgrade.RemoteVersion)
logger.Printf(text.Magenta(fmt.Sprintf(numberPadding, len(u.Up)-k))) logger.Printf(text.Magenta(fmt.Sprintf(numberPadding, lenUp-k)))
logger.Printf(namePadding, StylizedNameWithRepository(upgrade)) logger.Printf(namePadding, StylizedNameWithRepository(upgrade))
logger.Printf("%s -> %s\n", fmt.Sprintf(versionPadding, left), right) logger.Printf("%s -> %s\n", fmt.Sprintf(versionPadding, left), right)
if upgrade.Extra != "" {
logger.Println(strings.Repeat(" ", longestNumber), upgrade.Extra)
}
} }
} }