Simplify ordering check

we don't need a map[string]map[string]interface{}, as we don't need to
keep the data around
This commit is contained in:
Ettore Di Giacinto 2020-05-04 17:34:29 +02:00
parent b68634b58a
commit 20cb96e0cc
No known key found for this signature in database
GPG Key ID: 1ADA699B145A2D1C

View File

@ -170,9 +170,9 @@ func (assertions PackagesAssertions) Order(definitiondb pkg.PackageDatabase, fin
sort.Sort(unorderedAssertions) sort.Sort(unorderedAssertions)
// Build a topological graph // Build a topological graph
added := map[string]map[string]interface{}{}
for _, a := range unorderedAssertions { for _, a := range unorderedAssertions {
currentPkg := a.Package currentPkg := a.Package
added := map[string]interface{}{}
REQUIRES: REQUIRES:
for _, requiredDef := range currentPkg.GetRequires() { for _, requiredDef := range currentPkg.GetRequires() {
if def, err := definitiondb.FindPackage(requiredDef); err == nil { // Provides: Get a chance of being override here if def, err := definitiondb.FindPackage(requiredDef); err == nil { // Provides: Get a chance of being override here
@ -185,15 +185,12 @@ func (assertions PackagesAssertions) Order(definitiondb pkg.PackageDatabase, fin
if req != nil { if req != nil {
requiredDef = req.Package requiredDef = req.Package
} }
if _, ok := added[currentPkg.GetFingerPrint()][requiredDef.GetFingerPrint()]; ok { if _, ok := added[requiredDef.GetFingerPrint()]; ok {
continue REQUIRES continue REQUIRES
} }
// Expand also here, as we need to order them (or instead the solver should give back the dep correctly?) // Expand also here, as we need to order them (or instead the solver should give back the dep correctly?)
graph.AddEdge(currentPkg.GetFingerPrint(), requiredDef.GetFingerPrint()) graph.AddEdge(currentPkg.GetFingerPrint(), requiredDef.GetFingerPrint())
if _, ok := added[currentPkg.GetFingerPrint()]; !ok { added[requiredDef.GetFingerPrint()] = nil
added[currentPkg.GetFingerPrint()] = map[string]interface{}{}
}
added[currentPkg.GetFingerPrint()][requiredDef.GetFingerPrint()] = nil
} }
} }
result, err := graph.TopSort(fingerprint) result, err := graph.TopSort(fingerprint)