diff options
7 files changed, 33 insertions, 14 deletions
diff --git a/gentoobrowse-api/service/maintenance/updatesProcessor.cpp b/gentoobrowse-api/service/maintenance/updatesProcessor.cpp index 3cd4f7c..852829a 100644 --- a/gentoobrowse-api/service/maintenance/updatesProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/updatesProcessor.cpp @@ -12,6 +12,7 @@ #include <sql/maintenance/updatesMovePackages.sql.h> #include <sql/maintenance/updatesMoveUserPackages.sql.h> #include <sql/maintenance/updatesMoveFilelist.sql.h> +#include <sql/maintenance/updatesMergeFilelistEntries.sql.h> #include <sql/portage/findPackage.sql.h> using namespace AdHoc::FileUtils; @@ -128,6 +129,9 @@ namespace Gentoo { { if (!up->updatePacks.entityIds.empty()) { dbc->patchTable(up); + if (vcsMode) { + sql::maintenance::updatesMergeFilelistEntries.modify(dbc)->execute(); + } } } diff --git a/gentoobrowse-api/service/maintenanceGitOperations.cpp b/gentoobrowse-api/service/maintenanceGitOperations.cpp index 0f8adb1..76445ab 100644 --- a/gentoobrowse-api/service/maintenanceGitOperations.cpp +++ b/gentoobrowse-api/service/maintenanceGitOperations.cpp @@ -14,6 +14,8 @@ #include <sql/maintenance/gitListCreateRaw.sql.h> #include <sql/maintenance/gitListCreate.sql.h> #include <sql/maintenance/gitListCreateIdx.sql.h> +#include <sql/maintenance/filelistPhases.sql.h> +#include <sql/maintenance/gitListChangesInPhase.sql.h> #include <portage-models.h> #include "utils/git.h" #include "converters.h" @@ -150,7 +152,6 @@ namespace Gentoo { default: throw GitError("Insert Git file changes", 0, 0, "Unexpected change status."); } - // fprintf(stderr, "%d %s\n", delta->status, delta->new_file.path); ins->execute(); return 0; } @@ -209,22 +210,19 @@ namespace Gentoo { funcs["D"] = boost::bind(&FileProcessor::deleted, _1, dbc.get(), _2, _3); funcs["M"] = boost::bind(&FileProcessor::modified, _1, dbc.get(), _2, _3, _4); funcs["A"] = boost::bind(&FileProcessor::created, _1, dbc.get(), _2, _3, _4); - auto phases = dbc->select("SELECT phase FROM filelist GROUP BY phase ORDER BY phase"); + auto phases = sql::maintenance::filelistPhases.select(dbc.get()); for (const auto & phaseRow : phases->as<int64_t>()) { const auto & phase = phaseRow.value<0>(); - fprintf(stderr, "Phase %ld\n", phase); - auto files = dbc->select("SELECT repoId, filename, fileTypeId, pathParts, status FROM filelist WHERE phase = ? ORDER BY POSITION(status IN 'DMA'), updateOrder NULLS LAST"); + auto files = sql::maintenance::gitListChangesInPhase.select(dbc.get()); files->bindParamI(0, phase); std::set<int64_t> usedTypes; - for (const auto & fileRow : files->as<int64_t, std::string, int64_t, std::string, std::string>()) { - const auto & fileTypeId = fileRow.value<2>(); + for (const auto & fileRow : files->as<int64_t, int64_t, std::string, std::string>()) { + const auto & fileTypeId = fileRow.value<1>(); if (fps.find(fileTypeId) != fps.end()) { const auto & repoId = fileRow.value<0>(); - const auto & filename = fileRow.value<1>(); - const auto & pathParts = fileRow.value<3>(); - const auto & status = fileRow.value<4>(); - usedTypes.insert(fileRow.value<2>()); - fprintf(stderr, "%s: %s\n", status.c_str(), filename.c_str()); + const auto & pathParts = fileRow.value<2>(); + const auto & status = fileRow.value<3>(); + usedTypes.insert(fileTypeId); this->fileHandle(fileTypeId, &fps, &repos, repoId, pathParts, repoRoot, funcs[status]); } } diff --git a/gentoobrowse-api/service/sql/maintenance/filelistPhases.sql b/gentoobrowse-api/service/sql/maintenance/filelistPhases.sql new file mode 100644 index 0000000..5234f51 --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/filelistPhases.sql @@ -0,0 +1,4 @@ +SELECT phase +FROM filelist +GROUP BY phase +ORDER BY phase diff --git a/gentoobrowse-api/service/sql/maintenance/gitListChangesInPhase.sql b/gentoobrowse-api/service/sql/maintenance/gitListChangesInPhase.sql new file mode 100644 index 0000000..17dfdb3 --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/gitListChangesInPhase.sql @@ -0,0 +1,5 @@ +SELECT repoId, fileTypeId, pathParts, status +FROM filelist +WHERE phase = ? +AND status IS NOT NULL +ORDER BY POSITION(status IN 'DMA'), updateOrder NULLS LAST diff --git a/gentoobrowse-api/service/sql/maintenance/gitListCreate.sql b/gentoobrowse-api/service/sql/maintenance/gitListCreate.sql index df9f947..20ca804 100644 --- a/gentoobrowse-api/service/sql/maintenance/gitListCreate.sql +++ b/gentoobrowse-api/service/sql/maintenance/gitListCreate.sql @@ -2,7 +2,6 @@ CREATE TEMPORARY TABLE filelist AS SELECT fl.repoid, fl.status, - fl.filename, ft.filetypeid, ft.updateOrder, ft.phase, diff --git a/gentoobrowse-api/service/sql/maintenance/updatesMergeFilelistEntries.sql b/gentoobrowse-api/service/sql/maintenance/updatesMergeFilelistEntries.sql new file mode 100644 index 0000000..68cdbee --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/updatesMergeFilelistEntries.sql @@ -0,0 +1,9 @@ +UPDATE filelist SET + status = CASE WHEN status = 'A' THEN 'M' END +WHERE pathparts IN ( + SELECT pathparts + FROM filelist + WHERE filetypeid = 1 + AND status IN ('A', 'D') + GROUP BY pathparts + HAVING COUNT(*) = 2) diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp index 7c016fc..dd5d5ad 100644 --- a/gentoobrowse-api/unittests/testMaintenance.cpp +++ b/gentoobrowse-api/unittests/testMaintenance.cpp @@ -210,8 +210,8 @@ BOOST_AUTO_TEST_CASE( testRefreshGitRepository ) } BOOST_TEST_CONTEXT("Original ebuilds in moved package were not deleted and replaced") { SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.packageid = 9)SQL", int64_t, 2); - // SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 2); - // SQL_REQUIRE_EQUAL(R"SQL(SELECT MIN(e.packageid) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 9); + SQL_REQUIRE_EQUAL(R"SQL(SELECT COUNT(*) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 2); + SQL_REQUIRE_EQUAL(R"SQL(SELECT MIN(e.packageid) FROM gentoobrowse.ebuilds e WHERE e.ebuildid in (12, 13))SQL", int64_t, 9); } } } |