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
RemoteVersion string
Reason alpm.PkgReason
Extra string // Extra information to be displayed
}
type SyncUpgrade struct {

View file

@ -12,6 +12,16 @@ type (
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 {
Color 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] {
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]
}

View file

@ -2,7 +2,10 @@ package upgrade
import (
"context"
"fmt"
"math"
"sort"
"strings"
"github.com/Jguer/aur"
"github.com/Jguer/go-alpm/v2"
@ -20,6 +23,8 @@ import (
"github.com/Jguer/yay/v12/pkg/vcs"
)
const cutOffExtra = 2
type UpgradeService struct {
grapher *dep.Grapher
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()}
_ = graph.ForEach(func(name string, info *dep.InstallInfo) error {
alpmReason := alpm.PkgReasonExplicit
if info.Reason == dep.Dep {
alpmReason = alpm.PkgReasonDepend
alpmReason := alpm.PkgReasonDepend
if info.Reason == dep.Explicit {
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 {
@ -205,6 +220,7 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn
Base: *info.AURBase,
LocalVersion: info.LocalVersion,
Reason: alpmReason,
Extra: extra,
})
} else if info.Source == dep.Sync {
repoUp.Up = append(repoUp.Up, Upgrade{
@ -214,6 +230,7 @@ func (u *UpgradeService) graphToUpSlice(graph *topo.Graph[string, *dep.InstallIn
Base: "",
LocalVersion: info.LocalVersion,
Reason: alpmReason,
Extra: extra,
})
}
return nil

View file

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