summaryrefslogtreecommitdiff
path: root/gentoobrowse-api/service/utils
diff options
context:
space:
mode:
Diffstat (limited to 'gentoobrowse-api/service/utils')
-rw-r--r--gentoobrowse-api/service/utils/dbUtils.cpp85
-rw-r--r--gentoobrowse-api/service/utils/dbUtils.h24
-rw-r--r--gentoobrowse-api/service/utils/ebuildCacheParser.cpp50
-rw-r--r--gentoobrowse-api/service/utils/ebuildCacheParser.h27
-rw-r--r--gentoobrowse-api/service/utils/entityWhereFilter.cpp84
-rw-r--r--gentoobrowse-api/service/utils/entityWhereFilter.h31
-rw-r--r--gentoobrowse-api/service/utils/git.cpp167
-rw-r--r--gentoobrowse-api/service/utils/git.h85
-rw-r--r--gentoobrowse-api/service/utils/splitEbuildProps.cpp36
-rw-r--r--gentoobrowse-api/service/utils/splitEbuildProps.h28
-rw-r--r--gentoobrowse-api/service/utils/xmlUtils.cpp28
-rw-r--r--gentoobrowse-api/service/utils/xmlUtils.h19
12 files changed, 301 insertions, 363 deletions
diff --git a/gentoobrowse-api/service/utils/dbUtils.cpp b/gentoobrowse-api/service/utils/dbUtils.cpp
index c281265..d0ae626 100644
--- a/gentoobrowse-api/service/utils/dbUtils.cpp
+++ b/gentoobrowse-api/service/utils/dbUtils.cpp
@@ -5,53 +5,48 @@
#include <buffer.h>
#include <tablepatch.h>
-namespace Gentoo {
- namespace Utils {
- namespace Database {
- std::string
- emptyClone(DB::Connection * db, const std::string & orig)
- {
- auto tempTable = orig;
- auto dot = tempTable.rfind('.');
- if (dot != std::string::npos) {
- tempTable = tempTable.substr(dot + 1);
- }
- tempTable += "_clone_" + boost::lexical_cast<std::string>(db);
- db->execute("CREATE TEMPORARY TABLE " + tempTable + " AS SELECT * FROM " + orig + " WHERE false");
- return tempTable;
- }
+namespace Gentoo::Utils::Database {
+ std::string
+ emptyClone(DB::Connection * db, const std::string & orig)
+ {
+ auto tempTable = orig;
+ auto dot = tempTable.rfind('.');
+ if (dot != std::string::npos) {
+ tempTable = tempTable.substr(dot + 1);
+ }
+ tempTable += "_clone_" + boost::lexical_cast<std::string>(db);
+ db->execute("CREATE TEMPORARY TABLE " + tempTable + " AS SELECT * FROM " + orig + " WHERE false");
+ return tempTable;
+ }
- std::pair<std::string, DB::ModifyCommandPtr>
- namedTemp(DB::Connection * db, const std::string & tempTable,
- const std::map<std::string, const std::string> & cols)
- {
- std::set<std::string> keys;
- std::set<std::string> defs;
- for (auto c : cols) {
- keys.insert(c.first);
- defs.insert(c.first + " " + c.second);
- }
- db->execute("CREATE TEMPORARY TABLE " + tempTable + "(" + boost::join(defs, ",") + ")");
- return {tempTable, tablePatchInserter(db, tempTable, keys)};
- }
+ std::pair<std::string, DB::ModifyCommandPtr>
+ namedTemp(DB::Connection * db, const std::string & tempTable, const std::map<std::string, const std::string> & cols)
+ {
+ std::set<std::string> keys;
+ std::set<std::string> defs;
+ for (const auto & c : cols) {
+ keys.insert(c.first);
+ defs.insert(c.first + " " + c.second);
+ }
+ db->execute("CREATE TEMPORARY TABLE " + tempTable + "(" + boost::join(defs, ",") + ")");
+ return {tempTable, tablePatchInserter(db, tempTable, keys)};
+ }
- void
- drop(DB::Connection * db, const std::string & table)
- {
- db->execute("DROP TABLE " + table);
- }
+ void
+ drop(DB::Connection * db, const std::string & table)
+ {
+ db->execute("DROP TABLE " + table);
+ }
- DB::ModifyCommandPtr
- tablePatchInserter(DB::Connection * dbc, const DB::TablePatch & p)
- {
- return tablePatchInserter(dbc, p.src, p.cols);
- }
- DB::ModifyCommandPtr
- tablePatchInserter(DB::Connection * dbc, const std::string & t, const std::set<std::string> & c)
- {
- return dbc->modify("INSERT INTO " + t + "(" + boost::algorithm::join(c, ", ") + ") VALUES("
- + boost::algorithm::join(std::vector<std::string>(c.size(), "?"), ", ") + ")");
- }
- }
+ DB::ModifyCommandPtr
+ tablePatchInserter(DB::Connection * dbc, const DB::TablePatch & p)
+ {
+ return tablePatchInserter(dbc, p.src, p.cols);
+ }
+ DB::ModifyCommandPtr
+ tablePatchInserter(DB::Connection * dbc, const std::string & t, const std::set<std::string> & c)
+ {
+ return dbc->modify("INSERT INTO " + t + "(" + boost::algorithm::join(c, ", ") + ") VALUES("
+ + boost::algorithm::join(std::vector<std::string>(c.size(), "?"), ", ") + ")");
}
}
diff --git a/gentoobrowse-api/service/utils/dbUtils.h b/gentoobrowse-api/service/utils/dbUtils.h
index cdd9c07..dee1b2d 100644
--- a/gentoobrowse-api/service/utils/dbUtils.h
+++ b/gentoobrowse-api/service/utils/dbUtils.h
@@ -1,5 +1,4 @@
-#ifndef GENTOOBROWSE_API_SERVICE_DBUTILS_H
-#define GENTOOBROWSE_API_SERVICE_DBUTILS_H
+#pragma once
#include <IceUtil/Exception.h>
#include <IceUtil/Optional.h>
@@ -7,18 +6,11 @@
#include <connection.h>
#include <modifycommand.h>
-namespace Gentoo {
- namespace Utils {
- namespace Database {
- std::string emptyClone(DB::Connection *, const std::string &);
- std::pair<std::string, DB::ModifyCommandPtr> namedTemp(
- DB::Connection *, const std::string &, const std::map<std::string, const std::string> & cols);
- void drop(DB::Connection *, const std::string &);
- DB::ModifyCommandPtr tablePatchInserter(DB::Connection *, const DB::TablePatch &);
- DB::ModifyCommandPtr tablePatchInserter(
- DB::Connection *, const std::string &, const std::set<std::string> &);
- }
- }
+namespace Gentoo::Utils::Database {
+ std::string emptyClone(DB::Connection *, const std::string &);
+ std::pair<std::string, DB::ModifyCommandPtr> namedTemp(
+ DB::Connection *, const std::string &, const std::map<std::string, const std::string> & cols);
+ void drop(DB::Connection *, const std::string &);
+ DB::ModifyCommandPtr tablePatchInserter(DB::Connection *, const DB::TablePatch &);
+ DB::ModifyCommandPtr tablePatchInserter(DB::Connection *, const std::string &, const std::set<std::string> &);
}
-
-#endif
diff --git a/gentoobrowse-api/service/utils/ebuildCacheParser.cpp b/gentoobrowse-api/service/utils/ebuildCacheParser.cpp
index cd50d1a..c3fef41 100644
--- a/gentoobrowse-api/service/utils/ebuildCacheParser.cpp
+++ b/gentoobrowse-api/service/utils/ebuildCacheParser.cpp
@@ -1,36 +1,34 @@
#include "ebuildCacheParser.h"
-namespace Gentoo {
- namespace Utils {
- EbuildCacheParser::EbuildCacheParser(const std::filesystem::path & p) : AdHoc::FileUtils::MemMap(p)
- {
- auto chardata = sv();
- for (auto eq = chardata.find('='); eq != std::string_view::npos; eq = chardata.find('=')) {
- if (auto nl = chardata.find('\n', eq + 1); nl != std::string_view::npos) {
- kvs.insert({chardata.substr(0, eq), chardata.substr(eq + 1, nl - eq - 1)});
- chardata.remove_prefix(nl + 1);
- }
+namespace Gentoo::Utils {
+ EbuildCacheParser::EbuildCacheParser(const std::filesystem::path & p) : AdHoc::FileUtils::MemMap(p)
+ {
+ auto chardata = sv();
+ for (auto eq = chardata.find('='); eq != std::string_view::npos; eq = chardata.find('=')) {
+ if (auto nl = chardata.find('\n', eq + 1); nl != std::string_view::npos) {
+ kvs.insert({chardata.substr(0, eq), chardata.substr(eq + 1, nl - eq - 1)});
+ chardata.remove_prefix(nl + 1);
}
}
+ }
- std::optional<Glib::ustring>
- EbuildCacheParser::get(const std::string & key) const
- {
- auto kvi = kvs.find(key);
- if (kvi == kvs.end()) {
- return {};
- }
- return Glib::ustring(kvi->second.data(), kvi->second.length());
+ std::optional<Glib::ustring>
+ EbuildCacheParser::get(const std::string & key) const
+ {
+ auto kvi = kvs.find(key);
+ if (kvi == kvs.end()) {
+ return {};
}
+ return Glib::ustring(kvi->second.data(), kvi->second.length());
+ }
- std::optional<std::string_view>
- EbuildCacheParser::getRange(const std::string & key) const
- {
- auto kvi = kvs.find(key);
- if (kvi == kvs.end()) {
- return {};
- }
- return kvi->second;
+ std::optional<std::string_view>
+ EbuildCacheParser::getRange(const std::string & key) const
+ {
+ auto kvi = kvs.find(key);
+ if (kvi == kvs.end()) {
+ return {};
}
+ return kvi->second;
}
}
diff --git a/gentoobrowse-api/service/utils/ebuildCacheParser.h b/gentoobrowse-api/service/utils/ebuildCacheParser.h
index 4fed766..ee3977f 100644
--- a/gentoobrowse-api/service/utils/ebuildCacheParser.h
+++ b/gentoobrowse-api/service/utils/ebuildCacheParser.h
@@ -1,5 +1,4 @@
-#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_EBUILDCACHEPARSER_H
-#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_EBUILDCACHEPARSER_H
+#pragma once
#include "wrap/ustring.h"
#include <fileUtils.h>
@@ -8,21 +7,17 @@
#include <optional>
#include <string_view>
-namespace Gentoo {
- namespace Utils {
- class EbuildCacheParser : public AdHoc::FileUtils::MemMap {
- public:
- typedef std::map<std::string_view, const std::string_view> KVs;
+namespace Gentoo::Utils {
+ class EbuildCacheParser : public AdHoc::FileUtils::MemMap {
+ public:
+ using KVs = std::map<std::string_view, const std::string_view, std::less<>>;
- explicit EbuildCacheParser(const std::filesystem::path & p);
+ explicit EbuildCacheParser(const std::filesystem::path & p);
- std::optional<Glib::ustring> get(const std::string & key) const;
- std::optional<std::string_view> getRange(const std::string & key) const;
+ [[nodiscard]] std::optional<Glib::ustring> get(const std::string & key) const;
+ [[nodiscard]] std::optional<std::string_view> getRange(const std::string & key) const;
- private:
- KVs kvs;
- };
- }
+ private:
+ KVs kvs;
+ };
}
-
-#endif
diff --git a/gentoobrowse-api/service/utils/entityWhereFilter.cpp b/gentoobrowse-api/service/utils/entityWhereFilter.cpp
index 1deb6ef..be74f2e 100644
--- a/gentoobrowse-api/service/utils/entityWhereFilter.cpp
+++ b/gentoobrowse-api/service/utils/entityWhereFilter.cpp
@@ -2,57 +2,55 @@
#include <buffer.h>
#include <command.h>
-namespace Gentoo {
- namespace Utils {
- template<typename T> EntityWhereFilter<T>::EntityWhereFilter(const std::string & en) : entityColName(en) { }
+namespace Gentoo::Utils {
+ template<typename T> EntityWhereFilter<T>::EntityWhereFilter(std::string en) : entityColName(std::move(en)) { }
- template<typename T>
- EntityWhereFilter<T>::EntityWhereFilter(const std::string & en, const T & e) : entityColName(en)
- {
- entityIds.insert(e);
- }
+ template<typename T>
+ EntityWhereFilter<T>::EntityWhereFilter(std::string en, T e) :
+ entityIds {std::move(e)}, entityColName(std::move(en))
+ {
+ }
- template<typename T>
- EntityWhereFilter<T>::EntityWhereFilter(const std::string & en, const EntityIds & e) :
- entityIds(e), entityColName(en)
- {
- }
+ template<typename T>
+ EntityWhereFilter<T>::EntityWhereFilter(std::string en, EntityIds e) :
+ entityIds(std::move(e)), entityColName(std::move(en))
+ {
+ }
- template<typename T>
- void
- EntityWhereFilter<T>::writeSql(AdHoc::Buffer & sql)
- {
- sql.appendbf("a.%s IN (", entityColName);
- for (auto ei = entityIds.begin(); ei != entityIds.end(); ++ei) {
- if (ei != entityIds.begin()) {
- sql.append(", ?");
- }
- else {
- sql.append("?");
- }
+ template<typename T>
+ void
+ EntityWhereFilter<T>::writeSql(AdHoc::Buffer & sql)
+ {
+ sql.appendbf("a.%s IN (", entityColName);
+ for (auto ei = entityIds.begin(); ei != entityIds.end(); ++ei) {
+ if (ei != entityIds.begin()) {
+ sql.append(", ?");
}
- sql.append(")");
- }
-
- template<>
- void
- EntityWhereFilter<int64_t>::bindParams(DB::Command * c, unsigned int & offset)
- {
- for (const auto & entityId : entityIds) {
- c->bindParamI(offset++, entityId);
+ else {
+ sql.append("?");
}
}
+ sql.append(")");
+ }
- template<>
- void
- EntityWhereFilter<std::string>::bindParams(DB::Command * c, unsigned int & offset)
- {
- for (const auto & entityId : entityIds) {
- c->bindParamS(offset++, entityId);
- }
+ template<>
+ void
+ EntityWhereFilter<int64_t>::bindParams(DB::Command * c, unsigned int & offset)
+ {
+ for (const auto & entityId : entityIds) {
+ c->bindParamI(offset++, entityId);
}
+ }
- template class EntityWhereFilter<int64_t>;
- template class EntityWhereFilter<std::string>;
+ template<>
+ void
+ EntityWhereFilter<std::string>::bindParams(DB::Command * c, unsigned int & offset)
+ {
+ for (const auto & entityId : entityIds) {
+ c->bindParamS(offset++, entityId);
+ }
}
+
+ template class EntityWhereFilter<int64_t>;
+ template class EntityWhereFilter<std::string>;
}
diff --git a/gentoobrowse-api/service/utils/entityWhereFilter.h b/gentoobrowse-api/service/utils/entityWhereFilter.h
index 0c172dd..ccb92a0 100644
--- a/gentoobrowse-api/service/utils/entityWhereFilter.h
+++ b/gentoobrowse-api/service/utils/entityWhereFilter.h
@@ -1,26 +1,21 @@
-#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_ENTITYWHEREFILTER_H
-#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_ENTITYWHEREFILTER_H
+#pragma once
#include <set>
#include <sqlWriter.h>
-namespace Gentoo {
- namespace Utils {
- template<typename T> class EntityWhereFilter : public DB::SqlWriter {
- public:
- typedef std::set<T> EntityIds;
+namespace Gentoo::Utils {
+ template<typename T> class EntityWhereFilter : public DB::SqlWriter {
+ public:
+ using EntityIds = std::set<T>;
- explicit EntityWhereFilter(const std::string & en);
- EntityWhereFilter(const std::string & en, const T & e);
- EntityWhereFilter(const std::string & en, const EntityIds & e);
+ explicit EntityWhereFilter(std::string en);
+ EntityWhereFilter(std::string en, T e);
+ EntityWhereFilter(std::string en, EntityIds e);
- void writeSql(AdHoc::Buffer & sql) override;
- void bindParams(DB::Command * c, unsigned int & offset) override;
+ void writeSql(AdHoc::Buffer & sql) override;
+ void bindParams(DB::Command * c, unsigned int & offset) override;
- EntityIds entityIds;
- const std::string entityColName;
- };
- }
+ EntityIds entityIds;
+ const std::string entityColName;
+ };
}
-
-#endif
diff --git a/gentoobrowse-api/service/utils/git.cpp b/gentoobrowse-api/service/utils/git.cpp
index b21edf2..c2e94b7 100644
--- a/gentoobrowse-api/service/utils/git.cpp
+++ b/gentoobrowse-api/service/utils/git.cpp
@@ -4,99 +4,88 @@
#include <logger.h>
#include <maintenance.h>
-namespace Gentoo {
- namespace Utils {
- namespace Git {
- void
- throwError(void * const func, int err)
- {
-#if LIBGIT2_VER_MINOR >= 28
- const git_error * e = git_error_last();
-#else
- const git_error * e = giterr_last();
-#endif
- char ** fn = backtrace_symbols(&func, 1);
- assert(fn);
- assert(*fn);
- std::string funcName(*fn);
- free(fn);
- throw ::Gentoo::GitError(funcName, err, e->klass, e->message);
- }
+namespace Gentoo::Utils::Git {
+ void
+ throwError(void * const func, int err)
+ {
+ const git_error * e = git_error_last();
+ std::unique_ptr<char *, decltype(&free)> fn {backtrace_symbols(&func, 1), free};
+ assert(fn);
+ assert(*fn);
+ throw ::Gentoo::GitError(*fn, err, e->klass, e->message);
+ }
- std::string
- operator*(const git_oid & oid)
- {
- std::string str(GIT_OID_HEXSZ, ' ');
- git_oid_tostr(&str.front(), GIT_OID_HEXSZ + 1, &oid);
- return str;
- }
+ std::string
+ operator*(const git_oid & oid)
+ {
+ std::string str(GIT_OID_HEXSZ, ' ');
+ git_oid_tostr(&str.front(), GIT_OID_HEXSZ + 1, &oid);
+ return str;
+ }
- AdHocFormatter(RefSpec, "refs/heads/%?:refs/remotes/%?/%?");
- GitAnnotatedCommitPtr
- gitFetch(git_repository * repo, git_remote * remote, const char * remoteBranchName)
- {
- auto opts = gitSafeGet(git_fetch_init_options, static_cast<unsigned int>(GIT_FETCH_OPTIONS_VERSION));
- opts.prune = GIT_FETCH_PRUNE;
- opts.update_fetchhead = 1;
- auto localBranch = gitSafeGet(git_repository_head, git_reference_free, repo);
- auto localBranchName = gitSafeGet(git_branch_name, localBranch.get());
- auto refspec = RefSpec::get(localBranchName, git_remote_name(remote), remoteBranchName);
- char * s[] = {&refspec.front()};
- git_strarray refs = {s, 1};
- gitSafe(git_remote_fetch, remote, &refs, &opts, nullptr);
- return gitSafeGet(git_annotated_commit_from_revspec, git_annotated_commit_free, repo, "FETCH_HEAD");
- }
+ AdHocFormatter(RefSpec, "refs/heads/%?:refs/remotes/%?/%?");
+ GitAnnotatedCommitPtr
+ gitFetch(git_repository * repo, git_remote * remote, const char * remoteBranchName)
+ {
+ auto opts = gitSafeGet(git_fetch_init_options, static_cast<unsigned int>(GIT_FETCH_OPTIONS_VERSION));
+ opts.prune = GIT_FETCH_PRUNE;
+ opts.update_fetchhead = 1;
+ auto localBranch = gitSafeGet(git_repository_head, git_reference_free, repo);
+ auto localBranchName = gitSafeGet(git_branch_name, localBranch.get());
+ auto refspec = RefSpec::get(localBranchName, git_remote_name(remote), remoteBranchName);
+ std::array<char *, 1> s {refspec.data()};
+ git_strarray refs = {s.data(), 1};
+ gitSafe(git_remote_fetch, remote, &refs, &opts, nullptr);
+ return gitSafeGet(git_annotated_commit_from_revspec, git_annotated_commit_free, repo, "FETCH_HEAD");
+ }
- AdHocFormatter(FastForward, "Performing fast-forward %? -> %?");
- AdHocFormatter(CheckOut, "Checking out %?");
- git_oid
- gitFastForward(git_repository * repo, const git_annotated_commit * fetch_head)
- {
- auto log = LOGMANAGER()->getLogger(__FUNCTION__);
- // Test fast-forward is possible
- const git_annotated_commit * heads[] = {fetch_head};
- git_merge_analysis_t analysis = GIT_MERGE_ANALYSIS_NONE;
- git_merge_preference_t preference = GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY;
- gitSafe(git_merge_analysis, &analysis, &preference, repo, heads, 1LU);
+ AdHocFormatter(FastForward, "Performing fast-forward %? -> %?");
+ AdHocFormatter(CheckOut, "Checking out %?");
+ git_oid
+ gitFastForward(git_repository * repo, const git_annotated_commit * fetch_head)
+ {
+ auto log = LOGMANAGER()->getLogger(__FUNCTION__);
+ // Test fast-forward is possible
+ std::array<const git_annotated_commit *, 1> heads {fetch_head};
+ git_merge_analysis_t analysis = GIT_MERGE_ANALYSIS_NONE;
+ git_merge_preference_t preference = GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY;
+ gitSafe(git_merge_analysis, &analysis, &preference, repo, heads.data(), 1LU);
- auto head = gitSafeGet(git_repository_head, git_reference_free, repo);
- if (analysis == GIT_MERGE_ANALYSIS_UP_TO_DATE) {
- return *git_reference_target(head.get());
- }
- if (!(analysis & (GIT_MERGE_ANALYSIS_NORMAL | GIT_MERGE_ANALYSIS_FASTFORWARD))) {
- throw GitError("Merge analysis", 0, 0, "Could not fast-forward branch");
- }
+ auto head = gitSafeGet(git_repository_head, git_reference_free, repo);
+ if (analysis == GIT_MERGE_ANALYSIS_UP_TO_DATE) {
+ return *git_reference_target(head.get());
+ }
+ if (!(analysis & (GIT_MERGE_ANALYSIS_NORMAL | GIT_MERGE_ANALYSIS_FASTFORWARD))) {
+ throw GitError("Merge analysis", 0, 0, "Could not fast-forward branch");
+ }
- // Perform fast-forward
- auto fetch_head_id = *git_annotated_commit_id(fetch_head);
- auto fetch_head_object
- = gitSafeGet(git_object_lookup, git_object_free, repo, &fetch_head_id, GIT_OBJ_ANY);
- log->messagectf<FastForward>(
- IceTray::Logging::LogLevel::INFO, *git_reference_target(head.get()), fetch_head_id);
- gitSafeGet(git_reference_set_target, git_reference_free, head.get(), &fetch_head_id, "fast-forward");
+ // Perform fast-forward
+ auto fetch_head_id = *git_annotated_commit_id(fetch_head);
+ auto fetch_head_object = gitSafeGet(git_object_lookup, git_object_free, repo, &fetch_head_id, GIT_OBJ_ANY);
+ log->messagectf<FastForward>(
+ IceTray::Logging::LogLevel::INFO, *git_reference_target(head.get()), fetch_head_id);
+ gitSafeGet(git_reference_set_target, git_reference_free, head.get(), &fetch_head_id, "fast-forward");
- // Checkout new head
- log->messagectf<CheckOut>(IceTray::Logging::LogLevel::INFO, fetch_head_id);
- auto checkout_options = gitSafeGet(git_checkout_init_options, 0u + GIT_CHECKOUT_OPTIONS_VERSION);
- checkout_options.checkout_strategy = GIT_CHECKOUT_FORCE;
- gitSafe(git_checkout_head, repo, &checkout_options);
- return fetch_head_id;
- }
+ // Checkout new head
+ log->messagectf<CheckOut>(IceTray::Logging::LogLevel::INFO, fetch_head_id);
+ auto checkout_options = gitSafeGet(git_checkout_init_options, 0U + GIT_CHECKOUT_OPTIONS_VERSION);
+ checkout_options.checkout_strategy = GIT_CHECKOUT_FORCE;
+ gitSafe(git_checkout_head, repo, &checkout_options);
+ return fetch_head_id;
+ }
- AdHocFormatter(Updating, "Updating repository in %? from %?/%?");
- AdHocFormatter(UpdateComplete, "Update complete to %?");
- void
- updateRepository(const std::string & path, const std::string & upstream, const std::string & branch)
- {
- auto log = LOGMANAGER()->getLogger(__FUNCTION__);
- log->messagectf<Updating>(IceTray::Logging::LogLevel::INFO, path, upstream, branch);
- auto repo = gitSafeGet(git_repository_open, git_repository_free, path.c_str());
- auto origin = gitSafeGet(git_remote_lookup, git_remote_free, repo.get(), upstream.c_str());
- auto fetchHead = gitFetch(repo.get(), origin.get(), branch.c_str());
- auto oid = gitFastForward(repo.get(), fetchHead.get());
- log->messagectf<UpdateComplete>(IceTray::Logging::LogLevel::INFO, oid);
- }
- }
+ AdHocFormatter(Updating, "Updating repository in %? from %?/%?");
+ AdHocFormatter(UpdateComplete, "Update complete to %?");
+ void
+ updateRepository(const std::string & path, const std::string & upstream, const std::string & branch)
+ {
+ auto log = LOGMANAGER()->getLogger(__FUNCTION__);
+ log->messagectf<Updating>(IceTray::Logging::LogLevel::INFO, path, upstream, branch);
+ auto repo = gitSafeGet(git_repository_open, git_repository_free, path.c_str());
+ auto origin = gitSafeGet(git_remote_lookup, git_remote_free, repo.get(), upstream.c_str());
+ auto fetchHead = gitFetch(repo.get(), origin.get(), branch.c_str());
+ auto oid = gitFastForward(repo.get(), fetchHead.get());
+ log->messagectf<UpdateComplete>(IceTray::Logging::LogLevel::INFO, oid);
}
}
@@ -104,9 +93,9 @@ namespace std {
std::ostream &
operator<<(std::ostream & s, const git_oid & oid)
{
- char str[GIT_OID_HEXSZ + 1];
- git_oid_tostr(str, sizeof(str), &oid);
- s.write(str, GIT_OID_HEXSZ);
+ std::array<char, GIT_OID_HEXSZ + 1> str {};
+ git_oid_tostr(str.data(), str.size(), &oid);
+ s.write(str.data(), GIT_OID_HEXSZ);
return s;
}
}
diff --git a/gentoobrowse-api/service/utils/git.h b/gentoobrowse-api/service/utils/git.h
index b9191e1..d240b51 100644
--- a/gentoobrowse-api/service/utils/git.h
+++ b/gentoobrowse-api/service/utils/git.h
@@ -1,58 +1,51 @@
-#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_GIT_H
-#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_GIT_H
+#pragma once
#include <git2.h>
#include <memory>
#include <ostream>
-namespace Gentoo {
- namespace Utils {
- namespace Git {
- void throwError(void * const func, int err);
-
- template<typename... P, typename... A>
- void
- gitSafe(int (*func)(P...), A... p)
- {
- if (int giterror_ = func(p...) < 0) {
- throwError(reinterpret_cast<void * const>(func), giterror_);
- }
- }
-
- template<typename T> using GitTPtr = std::unique_ptr<T, void (*)(T *)>;
-
- template<typename R, typename... P, typename... A>
- GitTPtr<R>
- gitSafeGet(int (*get)(R **, P...), void (*release)(R *), A... p)
- {
- R * r = nullptr;
- gitSafe(get, &r, p...);
- return GitTPtr<R>(r, release);
- }
-
- template<typename R, typename... P, typename... A>
- R
- gitSafeGet(int (*get)(R *, P...), A... p)
- {
- R r;
- gitSafe(get, &r, p...);
- return r;
- }
-
- std::string operator*(const git_oid &);
-
- using GitAnnotatedCommitPtr = GitTPtr<git_annotated_commit>;
- GitAnnotatedCommitPtr gitFetch(git_repository * repo, git_remote * remote, const char * branch);
-
- git_oid gitFastForward(git_repository * repo, const git_annotated_commit * fetch_head);
-
- void updateRepository(const std::string & path, const std::string & upstream, const std::string & branch);
+namespace Gentoo::Utils::Git {
+ void throwError(void * const func, int err);
+
+ template<typename... P, typename... A>
+ void
+ gitSafe(int (*func)(P...), A... p)
+ {
+ if (int giterror_ = func(p...) < 0) {
+ throwError(reinterpret_cast<void * const>(func), giterror_);
}
}
+
+ template<typename T> using GitTPtr = std::unique_ptr<T, void (*)(T *)>;
+
+ template<typename R, typename... P, typename... A>
+ GitTPtr<R>
+ gitSafeGet(int (*get)(R **, P...), void (*release)(R *), A... p)
+ {
+ R * r = nullptr;
+ gitSafe(get, &r, p...);
+ return GitTPtr<R>(r, release);
+ }
+
+ template<typename R, typename... P, typename... A>
+ R
+ gitSafeGet(int (*get)(R *, P...), A... p)
+ {
+ R r {};
+ gitSafe(get, &r, p...);
+ return r;
+ }
+
+ std::string operator*(const git_oid &);
+
+ using GitAnnotatedCommitPtr = GitTPtr<git_annotated_commit>;
+ GitAnnotatedCommitPtr gitFetch(git_repository * repo, git_remote * remote, const char * branch);
+
+ git_oid gitFastForward(git_repository * repo, const git_annotated_commit * fetch_head);
+
+ void updateRepository(const std::string & path, const std::string & upstream, const std::string & branch);
}
namespace std {
std::ostream & operator<<(std::ostream &, const git_oid &);
}
-
-#endif
diff --git a/gentoobrowse-api/service/utils/splitEbuildProps.cpp b/gentoobrowse-api/service/utils/splitEbuildProps.cpp
index ec9df6b..f9e1b6e 100644
--- a/gentoobrowse-api/service/utils/splitEbuildProps.cpp
+++ b/gentoobrowse-api/service/utils/splitEbuildProps.cpp
@@ -3,27 +3,23 @@
#include <buffer.h>
#include <command.h>
-namespace Gentoo {
- namespace Utils {
- SplitEbuildProps::SplitEbuildProps(
- const std::string & ce, int64_t e, const std::string & cp, const std::optional<Glib::ustring> & p) :
- entityId(e),
- colEntityName(ce), colPropName(cp), props(p)
- {
- }
+namespace Gentoo::Utils {
+ SplitEbuildProps::SplitEbuildProps(std::string ce, int64_t e, std::string cp, std::optional<Glib::ustring> p) :
+ entityId(e), colEntityName(std::move(ce)), colPropName(std::move(cp)), props(std::move(p))
+ {
+ }
- void
- SplitEbuildProps::writeSql(AdHoc::Buffer & sql)
- {
- sql.appendbf("(SELECT DISTINCT ?::int %s, trim(regexp_split_to_table(?, '\\s+'), '+') %s)", colEntityName,
- colPropName);
- }
+ void
+ SplitEbuildProps::writeSql(AdHoc::Buffer & sql)
+ {
+ sql.appendbf("(SELECT DISTINCT ?::int %s, trim(regexp_split_to_table(?, '\\s+'), '+') %s)", colEntityName,
+ colPropName);
+ }
- void
- SplitEbuildProps::bindParams(DB::Command * c, unsigned int & offset)
- {
- c->bindParamI(offset++, entityId);
- c->bindParamS(offset++, props);
- }
+ void
+ SplitEbuildProps::bindParams(DB::Command * c, unsigned int & offset)
+ {
+ c->bindParamI(offset++, entityId);
+ c->bindParamS(offset++, props);
}
}
diff --git a/gentoobrowse-api/service/utils/splitEbuildProps.h b/gentoobrowse-api/service/utils/splitEbuildProps.h
index 3945b6a..c413a51 100644
--- a/gentoobrowse-api/service/utils/splitEbuildProps.h
+++ b/gentoobrowse-api/service/utils/splitEbuildProps.h
@@ -1,25 +1,19 @@
-#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_SPLITEBUILDPROPS_H
-#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_SPLITEBUILDPROPS_H
+#pragma once
#include "wrap/ustring.h"
#include <optional>
#include <sqlWriter.h>
-namespace Gentoo {
- namespace Utils {
- class SplitEbuildProps : public DB::SqlWriter {
- public:
- SplitEbuildProps(
- const std::string & ce, int64_t e, const std::string & cp, const std::optional<Glib::ustring> & p);
+namespace Gentoo::Utils {
+ class SplitEbuildProps : public DB::SqlWriter {
+ public:
+ SplitEbuildProps(std::string ce, int64_t e, std::string cp, std::optional<Glib::ustring> p);
- void writeSql(AdHoc::Buffer & sql) override;
- void bindParams(DB::Command * c, unsigned int & offset) override;
+ void writeSql(AdHoc::Buffer & sql) override;
+ void bindParams(DB::Command * c, unsigned int & offset) override;
- const int64_t entityId;
- const std::string colEntityName, colPropName;
- const std::optional<Glib::ustring> props;
- };
- }
+ const int64_t entityId;
+ const std::string colEntityName, colPropName;
+ const std::optional<Glib::ustring> props;
+ };
}
-
-#endif
diff --git a/gentoobrowse-api/service/utils/xmlUtils.cpp b/gentoobrowse-api/service/utils/xmlUtils.cpp
index 1ddc16e..195b054 100644
--- a/gentoobrowse-api/service/utils/xmlUtils.cpp
+++ b/gentoobrowse-api/service/utils/xmlUtils.cpp
@@ -1,22 +1,20 @@
#include "xmlUtils.h"
-namespace Gentoo {
- namespace Utils {
- XmlDoc::XmlDoc(const std::filesystem::path & path) : xmlpp::DomParser(path) { }
+namespace Gentoo::Utils {
+ XmlDoc::XmlDoc(const std::filesystem::path & path) : xmlpp::DomParser(path) { }
- std::optional<Glib::ustring>
- XmlDoc::getXPathValue(const Glib::ustring & xp)
- {
- auto ns = get_document()->get_root_node()->find(xp);
- if (ns.size() >= 1) {
- if (auto cn = dynamic_cast<const xmlpp::ContentNode *>(ns.front())) {
- return cn->get_content();
- }
+ std::optional<Glib::ustring>
+ XmlDoc::getXPathValue(const Glib::ustring & xp)
+ {
+ auto ns = get_document()->get_root_node()->find(xp);
+ if (ns.size() >= 1) {
+ if (auto cn = dynamic_cast<const xmlpp::ContentNode *>(ns.front())) {
+ return cn->get_content();
}
- else if (ns.size() > 1) {
- throw std::logic_error("Ambiguous xpath " + xp);
- }
- return {};
}
+ else if (ns.size() > 1) {
+ throw std::logic_error("Ambiguous xpath " + xp);
+ }
+ return {};
}
}
diff --git a/gentoobrowse-api/service/utils/xmlUtils.h b/gentoobrowse-api/service/utils/xmlUtils.h
index 51da33a..0e44a73 100644
--- a/gentoobrowse-api/service/utils/xmlUtils.h
+++ b/gentoobrowse-api/service/utils/xmlUtils.h
@@ -1,19 +1,14 @@
-#ifndef GENTOOBROWSE_API_SERVICE_XMLUTILS_H
-#define GENTOOBROWSE_API_SERVICE_XMLUTILS_H
+#pragma once
#include "wrap/domparser.h"
#include <filesystem>
#include <optional>
-namespace Gentoo {
- namespace Utils {
- class XmlDoc : public xmlpp::DomParser {
- public:
- explicit XmlDoc(const std::filesystem::path &);
+namespace Gentoo::Utils {
+ class XmlDoc : public xmlpp::DomParser {
+ public:
+ explicit XmlDoc(const std::filesystem::path &);
- std::optional<Glib::ustring> getXPathValue(const Glib::ustring &);
- };
- }
+ std::optional<Glib::ustring> getXPathValue(const Glib::ustring &);
+ };
}
-
-#endif