Blame SOURCES/0012-Revert-Add-compatible-layer-for-MdDocuments-v2.patch

379fd8
From 833966d8a8a6c87a3d51447f2adf2aa76190ecd8 Mon Sep 17 00:00:00 2001
379fd8
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
379fd8
Date: Sun, 25 Apr 2021 19:47:53 +0200
379fd8
Subject: [PATCH 12/19] Revert "Add compatible layer for MdDocuments v2"
379fd8
379fd8
This reverts commit 32ccf6743cb9ce1579ff88804855a94f30876860.
379fd8
---
379fd8
 libdnf/module/ModulePackageContainer.cpp  | 68 +----------------------
379fd8
 libdnf/module/modulemd/ModuleMetadata.cpp | 11 +---
379fd8
 libdnf/module/modulemd/ModuleMetadata.hpp |  2 +-
379fd8
 3 files changed, 4 insertions(+), 77 deletions(-)
379fd8
379fd8
diff --git a/libdnf/module/ModulePackageContainer.cpp b/libdnf/module/ModulePackageContainer.cpp
379fd8
index 3f30037e..6e6134d2 100644
379fd8
--- a/libdnf/module/ModulePackageContainer.cpp
379fd8
+++ b/libdnf/module/ModulePackageContainer.cpp
379fd8
@@ -69,23 +69,6 @@ void goal2name_query(libdnf::Goal & goal, libdnf::Query & query)
379fd8
     query.addFilter(HY_PKG_NAME, HY_EQ, module_names.data());
379fd8
 }
379fd8
 
379fd8
-/**
379fd8
- * @brief In python => ";".join(list.sort())
379fd8
- */
379fd8
-std::string concentrateVectorString(std::vector<std::string> & list)
379fd8
-{
379fd8
-    if (list.empty()) {
379fd8
-        return {};
379fd8
-    }
379fd8
-    std::sort(list.begin(), list.end());
379fd8
-    std::ostringstream ss;
379fd8
-    ss << *list.begin();
379fd8
-    for (auto require = std::next(list.begin()); require != list.end(); ++require) {
379fd8
-        ss << ";" << *require;
379fd8
-    }
379fd8
-    return ss.str();
379fd8
-}
379fd8
-
379fd8
 }
379fd8
 
379fd8
 namespace std {
379fd8
@@ -189,8 +172,6 @@ public:
379fd8
         const std::vector<ModulePackage *> & modules, bool debugSolver);
379fd8
     bool insert(const std::string &moduleName, const char *path);
379fd8
     std::vector<ModulePackage *> getLatestActiveEnabledModules();
379fd8
-    /// Required to call after all modules v3 are in metadata
379fd8
-    void addVersion2Modules();
379fd8
 
379fd8
 private:
379fd8
     friend struct ModulePackageContainer;
379fd8
@@ -204,8 +185,6 @@ private:
379fd8
     ModuleMetadata moduleMetadata;
379fd8
 
379fd8
     std::map<std::string, std::string> moduleDefaults;
379fd8
-    std::vector<std::tuple<LibsolvRepo *, ModulemdModuleStream *, std::string>> modulesV2;
379fd8
-
379fd8
     bool isEnabled(const std::string &name, const std::string &stream);
379fd8
 };
379fd8
 
379fd8
@@ -339,7 +318,6 @@ ModulePackageContainer::add(DnfSack * sack)
379fd8
                             exception.what()));
379fd8
         }
379fd8
     }
379fd8
-    pImpl->addVersion2Modules();
379fd8
 }
379fd8
 
379fd8
 void ModulePackageContainer::addDefaultsFromDisk()
379fd8
@@ -375,7 +353,7 @@ ModulePackageContainer::add(const std::string &fileContent, const std::string &
379fd8
         if (strcmp(r->name, "available") == 0) {
379fd8
             g_autofree gchar * path = g_build_filename(pImpl->installRoot.c_str(),
379fd8
                                                       "/etc/dnf/modules.d", NULL);
379fd8
-            auto packages = md.getAllModulePackages(pImpl->moduleSack, r, repoID, pImpl->modulesV2);
379fd8
+            std::vector<ModulePackage *> packages = md.getAllModulePackages(pImpl->moduleSack, r, repoID);
379fd8
             for(auto const& modulePackagePtr: packages) {
379fd8
                 std::unique_ptr<ModulePackage> modulePackage(modulePackagePtr);
379fd8
                 pImpl->modules.insert(std::make_pair(modulePackage->getId(), std::move(modulePackage)));
379fd8
@@ -1701,50 +1679,6 @@ std::vector<ModulePackage *> ModulePackageContainer::Impl::getLatestActiveEnable
379fd8
     return latest;
379fd8
 }
379fd8
 
379fd8
-void ModulePackageContainer::Impl::addVersion2Modules()
379fd8
-{
379fd8
-    if (modulesV2.empty()) {
379fd8
-        return;
379fd8
-    }
379fd8
-    std::map<std::string, std::map<std::string, std::vector<ModulePackage *>>> v3_context_map;
379fd8
-    for (auto const & module_pair : modules) {
379fd8
-        auto * module = module_pair.second.get();
379fd8
-        auto requires = module->getRequires(true);
379fd8
-        auto concentratedRequires = concentrateVectorString(requires);
379fd8
-        v3_context_map[module->getNameStream()][concentratedRequires].push_back(module);
379fd8
-    }
379fd8
-    libdnf::LibsolvRepo * repo;
379fd8
-    ModulemdModuleStream * mdStream;
379fd8
-    std::string repoID;
379fd8
-    g_autofree gchar * path = g_build_filename(installRoot.c_str(), "/etc/dnf/modules.d", NULL);
379fd8
-    for (auto & module_tuple : modulesV2) {
379fd8
-        std::tie(repo, mdStream, repoID) = module_tuple;
379fd8
-        auto nameStream = ModulePackage::getNameStream(mdStream);
379fd8
-        auto requires = ModulePackage::getRequires(mdStream, true);
379fd8
-        auto concentratedRequires = concentrateVectorString(requires);
379fd8
-        auto streamIterator = v3_context_map.find(nameStream);
379fd8
-        if (streamIterator != v3_context_map.end()) {
379fd8
-            auto contextIterator = streamIterator->second.find(concentratedRequires);
379fd8
-            if (contextIterator != streamIterator->second.end()) {
379fd8
-                auto v3_context = contextIterator->second[0]->getContext();
379fd8
-                std::unique_ptr<ModulePackage> modulePackage(new ModulePackage(moduleSack, repo, mdStream, repoID, v3_context));
379fd8
-                persistor->insert(modulePackage->getName(), path);
379fd8
-                modules.insert(std::make_pair(modulePackage->getId(), std::move(modulePackage)));
379fd8
-                g_object_unref(mdStream);
379fd8
-                continue;
379fd8
-            }
379fd8
-        }
379fd8
-        if (concentratedRequires.empty()) {
379fd8
-            concentratedRequires.append("NoRequires");
379fd8
-        }
379fd8
-        std::unique_ptr<ModulePackage> modulePackage(new ModulePackage(moduleSack, repo, mdStream, repoID, concentratedRequires));
379fd8
-        persistor->insert(modulePackage->getName(), path);
379fd8
-        modules.insert(std::make_pair(modulePackage->getId(), std::move(modulePackage)));
379fd8
-        g_object_unref(mdStream);
379fd8
-    }
379fd8
-    modulesV2.clear();
379fd8
-}
379fd8
-
379fd8
 void ModulePackageContainer::updateFailSafeData()
379fd8
 {
379fd8
     auto fileNames = getYamlFilenames(pImpl->persistDir.c_str());
379fd8
diff --git a/libdnf/module/modulemd/ModuleMetadata.cpp b/libdnf/module/modulemd/ModuleMetadata.cpp
379fd8
index 07817ce1..fbdd8a13 100644
379fd8
--- a/libdnf/module/modulemd/ModuleMetadata.cpp
379fd8
+++ b/libdnf/module/modulemd/ModuleMetadata.cpp
379fd8
@@ -126,8 +126,7 @@ void ModuleMetadata::resolveAddedMetadata()
379fd8
 
379fd8
 std::vector<ModulePackage *> ModuleMetadata::getAllModulePackages(DnfSack * moduleSack,
379fd8
                                                                   LibsolvRepo * repo,
379fd8
-                                                                  const std::string & repoID,
379fd8
-                                                                  std::vector<std::tuple<LibsolvRepo *, ModulemdModuleStream *, std::string>> & modulesV2)
379fd8
+                                                                  const std::string & repoID)
379fd8
 {
379fd8
     std::vector<ModulePackage *> result;
379fd8
     if (!resultingModuleIndex)
379fd8
@@ -141,13 +140,7 @@ std::vector<ModulePackage *> ModuleMetadata::getAllModulePackages(DnfSack * modu
379fd8
         //TODO(amatej): replace with
379fd8
         //GPtrArray * streams = modulemd_module_index_search_streams_by_nsvca_glob(resultingModuleIndex, NULL);
379fd8
         for (unsigned int i = 0; i < streams->len; i++){
379fd8
-            ModulemdModuleStream * moduleMdStream = static_cast<ModulemdModuleStream *>(g_ptr_array_index(streams, i));
379fd8
-            if (modulemd_module_stream_get_mdversion(moduleMdStream) > 2) {
379fd8
-                result.push_back(new ModulePackage(moduleSack, repo, moduleMdStream, repoID));
379fd8
-            } else {
379fd8
-                g_object_ref(moduleMdStream);
379fd8
-                modulesV2.push_back(std::make_tuple(repo, moduleMdStream, repoID));
379fd8
-            }
379fd8
+            result.push_back(new ModulePackage(moduleSack, repo, (ModulemdModuleStream *) g_ptr_array_index(streams, i), repoID));
379fd8
         }
379fd8
     }
379fd8
 
379fd8
diff --git a/libdnf/module/modulemd/ModuleMetadata.hpp b/libdnf/module/modulemd/ModuleMetadata.hpp
379fd8
index 901d7402..df753b11 100644
379fd8
--- a/libdnf/module/modulemd/ModuleMetadata.hpp
379fd8
+++ b/libdnf/module/modulemd/ModuleMetadata.hpp
379fd8
@@ -36,7 +36,7 @@ public:
379fd8
     ~ModuleMetadata();
379fd8
     void addMetadataFromString(const std::string & yaml, int priority);
379fd8
     void resolveAddedMetadata();
379fd8
-    std::vector<ModulePackage *> getAllModulePackages(DnfSack * moduleSack, LibsolvRepo * repo, const std::string & repoID, std::vector<std::tuple<LibsolvRepo *, ModulemdModuleStream *, std::string>> & modulesV2);
379fd8
+    std::vector<ModulePackage *> getAllModulePackages(DnfSack * moduleSack, LibsolvRepo * repo, const std::string & repoID);
379fd8
     std::map<std::string, std::string> getDefaultStreams();
379fd8
     std::vector<std::string> getDefaultProfiles(std::string moduleName, std::string moduleStream);
379fd8
     ModulemdObsoletes * getNewestActiveObsolete(ModulePackage *p);
379fd8
-- 
379fd8
2.31.1
379fd8