Skip to content

Commit

Permalink
move addUpgradeToGraph to depgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Nov 16, 2022
1 parent 2805252 commit 7f151cd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func handleCmd(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Exe
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
case "U", "upgrade":
return handleUpgrade(ctx, config, dbExecutor, cmdArgs)
return handleUpgrade(ctx, config, cmdArgs)
case "B", "build":
return handleBuild(ctx, config, dbExecutor, cmdArgs)
case "G", "getpkgbuild":
Expand Down Expand Up @@ -330,7 +330,7 @@ func handleGetpkgbuild(ctx context.Context, cmdArgs *parser.Arguments, dbExecuto
}

func handleUpgrade(ctx context.Context,
config *settings.Configuration, dbExecutor db.Executor, cmdArgs *parser.Arguments,
config *settings.Configuration, cmdArgs *parser.Arguments,
) error {
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
Expand Down
26 changes: 26 additions & 0 deletions pkg/dep/depGraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

aurc "github.com/Jguer/aur"
"github.com/Jguer/aur/metadata"
alpm "github.com/Jguer/go-alpm/v2"
gosrc "github.com/Morganamilo/go-srcinfo"
"github.com/leonelquinteros/gotext"
)
Expand Down Expand Up @@ -490,3 +491,28 @@ func archStringToString(alpmArches []string, archString []gosrc.ArchString) []st

return pkgs
}

func AddUpgradeToGraph(pkg *db.Upgrade, graph *topo.Graph[string, *InstallInfo]) {
source := Sync
if pkg.Repository == "aur" {
source = AUR
}

reason := Explicit
if pkg.Reason == alpm.PkgReasonDepend {
reason = Dep
}

graph.AddNode(pkg.Name)
graph.SetNodeInfo(pkg.Name, &topo.NodeInfo[*InstallInfo]{
Color: colorMap[reason],
Background: bgColorMap[source],
Value: &InstallInfo{
Source: source,
Reason: reason,
Version: pkg.RemoteVersion,
AURBase: &pkg.Base,
SyncDBName: &pkg.Repository,
},
})
}
33 changes: 4 additions & 29 deletions upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ func sysupgradeTargetsV2(ctx context.Context,
}

if isInclude && !include.Get(len(repoUp.Up)-i+len(aurUp.Up)) {
addUpgradeToGraph(pkg, graph)
dep.AddUpgradeToGraph(pkg, graph)
continue
}

if !isInclude && (exclude.Get(len(repoUp.Up)-i+len(aurUp.Up)) || otherExclude.Get(pkg.Repository)) {
addUpgradeToGraph(pkg, graph)
dep.AddUpgradeToGraph(pkg, graph)
continue
}

Expand All @@ -330,38 +330,13 @@ func sysupgradeTargetsV2(ctx context.Context,
}

if isInclude && !include.Get(len(aurUp.Up)-i) {
addUpgradeToGraph(pkg, graph)
dep.AddUpgradeToGraph(pkg, graph)
}

if !isInclude && (exclude.Get(len(aurUp.Up)-i) || otherExclude.Get(pkg.Repository)) {
addUpgradeToGraph(pkg, graph)
dep.AddUpgradeToGraph(pkg, graph)
}
}

return graph, ignore, err
}

func addUpgradeToGraph(pkg *db.Upgrade, graph *topo.Graph[string, *dep.InstallInfo]) {
source := dep.Sync
if pkg.Repository == "aur" {
source = dep.AUR
}

reason := dep.Explicit
if pkg.Reason == alpm.PkgReasonDepend {
reason = dep.Dep
}

graph.AddNode(pkg.Name)
graph.SetNodeInfo(pkg.Name, &topo.NodeInfo[*dep.InstallInfo]{
Color: "",
Background: "",
Value: &dep.InstallInfo{
Source: source,
Reason: reason,
Version: pkg.RemoteVersion,
AURBase: &pkg.Base,
SyncDBName: &pkg.Repository,
},
})
}

0 comments on commit 7f151cd

Please sign in to comment.