summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gentoobrowse-api/service/maintenance/masksProcessor.cpp53
-rw-r--r--gentoobrowse-api/service/mask.cpp46
-rw-r--r--gentoobrowse-api/service/mask.h27
3 files changed, 86 insertions, 40 deletions
diff --git a/gentoobrowse-api/service/maintenance/masksProcessor.cpp b/gentoobrowse-api/service/maintenance/masksProcessor.cpp
index 5a0bf53..c28f458 100644
--- a/gentoobrowse-api/service/maintenance/masksProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/masksProcessor.cpp
@@ -7,20 +7,11 @@
#include "utils/dbUtils.h"
#include <glibmm/regex.h>
#include <fileUtils.h>
-#include <lexer-regex.h>
-#include <lexer.h>
+#include <mask.h>
#include "sql/maintenance/masksSets.sql.h"
#include "sql/maintenance/masksFixDates.sql.h"
#include "sql/maintenance/masksEbuilds.sql.h"
-static AdHoc::Lexer::PatternPtr maskHead = AdHoc::LexerMatchers::regex(
- "^# ([^<\n]+)? ?(<(.+?@[^\n>]+)>?)? \\((\\d{1,2} *(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\\w* \\d{4})\\)$\n",
- (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_CASELESS | G_REGEX_UNGREEDY | G_REGEX_MULTILINE));
-static AdHoc::Lexer::PatternPtr maskDesc = AdHoc::LexerMatchers::regex("^# *([^\n]*)$\n", G_REGEX_MULTILINE);
-static AdHoc::Lexer::PatternPtr atom = AdHoc::LexerMatchers::regex("^([^\n/]+/[^\n]*)$\n?", G_REGEX_MULTILINE);
-static AdHoc::Lexer::PatternPtr end = AdHoc::LexerMatchers::regex("^$\n", G_REGEX_MULTILINE);
-static AdHoc::Lexer::PatternPtr discard = AdHoc::LexerMatchers::regex("^([^\n]*)$\n?", G_REGEX_MULTILINE);
-
namespace Gentoo {
namespace Service {
unsigned char MasksProcessor::phase() const { return 2; }
@@ -48,45 +39,27 @@ namespace Gentoo {
{ "atomSpec", "text[]" }
});
- Glib::ustring date;
- boost::optional<Glib::ustring> person, email;
- std::set<std::string> atoms;
- std::list<std::string> message;
- int n = 0;
auto i = tempTable.second;
AdHoc::FileUtils::MemMap f(path);
- AdHoc::Lexer l({
- { { AdHoc::Lexer::InitialState }, maskHead, [&](auto e)
- {
- person = e->pattern()->match(1);
- email = e->pattern()->match(3);
- date = *e->pattern()->match(4);
- e->pushState("mask");
- } },
- { { "mask" }, maskDesc, [&](auto e)
- {
- message.push_back(*e->pattern()->match(1));
- } },
- { { "mask" }, atom, [&](auto e)
- {
- atoms.insert(*e->pattern()->match(1));
- } },
- { { "mask" }, end, [&](auto e)
+ class MaskInserter : public Portage::Utils::Masks {
+ public:
+ MaskInserter(DB::ModifyCommand * i) : i(i) { }
+
+ protected:
+ void consume() const override
{
i->bindParamS(0, "{" + boost::algorithm::join(atoms, ",") + "}");
i->bindParamS(1, date);
if (email) i->bindParamS(2, *email); else i->bindNull(2);
i->bindParamS(3, boost::algorithm::join(message, " "));
- i->bindParamI(4, ++n);
+ i->bindParamI(4, n);
if (person) i->bindParamS(5, *person); else i->bindNull(5);
i->execute();
- atoms.clear();
- message.clear();
- e->popState();
- } },
- { { AdHoc::Lexer::InitialState }, discard, [&](auto) { } }
- });
- l.extract((gchar *)f.data, f.getStat().st_size);
+ }
+ DB::ModifyCommand * i;
+ };
+ MaskInserter(tempTable.second.get())
+ .extract((gchar *)f.data, f.getStat().st_size);
// Dates are hand-typed and sometimes typos occur... ensure they're at
// least within the range of Boost ptimes.
while (sql::maintenance::masksFixDates.modify(dbc)->execute()) ;
diff --git a/gentoobrowse-api/service/mask.cpp b/gentoobrowse-api/service/mask.cpp
new file mode 100644
index 0000000..e3cc677
--- /dev/null
+++ b/gentoobrowse-api/service/mask.cpp
@@ -0,0 +1,46 @@
+#include <mask.h>
+#include <lexer-regex.h>
+
+namespace Portage {
+ namespace Utils {
+ static AdHoc::Lexer::PatternPtr maskHead = AdHoc::LexerMatchers::regex(
+ "^# ([^<\n]+)? ?(<(.+?@[^\n>]+)>?)? \\((\\d{1,2} *(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\\w* \\d{4})\\)$\n",
+ (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_CASELESS | G_REGEX_UNGREEDY | G_REGEX_MULTILINE));
+ static AdHoc::Lexer::PatternPtr maskDesc = AdHoc::LexerMatchers::regex("^# *([^\n]*)$\n", G_REGEX_MULTILINE);
+ static AdHoc::Lexer::PatternPtr atom = AdHoc::LexerMatchers::regex("^([^\n/]+/[^\n]*)$\n?", G_REGEX_MULTILINE);
+ static AdHoc::Lexer::PatternPtr end = AdHoc::LexerMatchers::regex("^$\n", G_REGEX_MULTILINE);
+ static AdHoc::Lexer::PatternPtr discard = AdHoc::LexerMatchers::regex("^([^\n]*)$\n?", G_REGEX_MULTILINE);
+
+ Masks::Masks() :
+ AdHoc::Lexer({
+ { { AdHoc::Lexer::InitialState }, maskHead, [&](auto e)
+ {
+ person = e->pattern()->match(1);
+ email = e->pattern()->match(3);
+ date = *e->pattern()->match(4);
+ e->pushState("mask");
+ } },
+ { { "mask" }, maskDesc, [&](auto e)
+ {
+ message.push_back(*e->pattern()->match(1));
+ } },
+ { { "mask" }, atom, [&](auto e)
+ {
+ atoms.insert(*e->pattern()->match(1));
+ } },
+ { { "mask" }, end, [&](auto e)
+ {
+ ++n;
+ consume();
+ atoms.clear();
+ message.clear();
+ e->popState();
+ } },
+ { { AdHoc::Lexer::InitialState }, discard, [&](auto) { } }
+ }),
+ n(0)
+ {
+ }
+ }
+}
+
diff --git a/gentoobrowse-api/service/mask.h b/gentoobrowse-api/service/mask.h
new file mode 100644
index 0000000..f37b152
--- /dev/null
+++ b/gentoobrowse-api/service/mask.h
@@ -0,0 +1,27 @@
+#ifndef GENTOOBROWSE_SERVICE_MASK_H
+#define GENTOOBROWSE_SERVICE_MASK_H
+
+#include <lexer.h>
+#include <list>
+#include <glibmm/ustring.h>
+#include <boost/optional.hpp>
+
+namespace Portage {
+ namespace Utils {
+ class Masks : public AdHoc::Lexer {
+ protected:
+ Masks();
+
+ virtual void consume() const = 0;
+
+ Glib::ustring date;
+ boost::optional<Glib::ustring> person, email;
+ std::set<std::string> atoms;
+ std::list<std::string> message;
+ int n;
+ };
+ }
+}
+
+#endif
+