summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gentoobrowse-api/domain/converters.cpp69
-rw-r--r--gentoobrowse-api/domain/converters.h11
-rw-r--r--gentoobrowse-api/domain/unpackPqTextArray.h20
-rw-r--r--gentoobrowse-api/domain/unpackPqTextArray.ll26
-rw-r--r--gentoobrowse-api/service/maintenanceGitOperations.cpp37
5 files changed, 93 insertions, 70 deletions
diff --git a/gentoobrowse-api/domain/converters.cpp b/gentoobrowse-api/domain/converters.cpp
index 33a479f..aa51c26 100644
--- a/gentoobrowse-api/domain/converters.cpp
+++ b/gentoobrowse-api/domain/converters.cpp
@@ -6,6 +6,15 @@
#include <boost/algorithm/string/split.hpp>
namespace Slicer {
+ static
+ void
+ unpackPqTextArray(const std::string & s, ::Gentoo::StringList & list)
+ {
+ std::stringstream ss(s);
+ UnpackPqTextArray l(ss, list);
+ l.yylex();
+ }
+
template<typename T>
PqArray<T>::PqArray(std::vector<T> & l) :
ModelPartForSequence<std::vector<T>>(l)
@@ -24,11 +33,11 @@ namespace Slicer {
std::string v;
s->set(v);
if (v.size() < 3) return;
- typedef boost::algorithm::split_iterator<std::string::iterator> string_split_iterator;
+ typedef boost::algorithm::split_iterator<std::string::iterator> string_split_iterator;
string_split_iterator sfi(++v.begin(), --v.end(), boost::algorithm::first_finder(",", boost::algorithm::is_iequal()));
for(auto it = sfi; it != string_split_iterator(); ++it) {
this->Model.push_back(boost::lexical_cast<T>(*it));
- }
+ }
}
void PqArray<std::string>::SetValue(ValueSourcePtr s)
@@ -36,32 +45,20 @@ namespace Slicer {
Model.clear();
std::string v;
s->set(v);
- std::stringstream ss(v);
- ::Portage::Utils::UnpackPqTextArray l(ss, Model);
- l.yylex();
+ unpackPqTextArray(v, Model);
}
template<typename T>
- void PqArray<T>::GetValue(ValueTargetPtr s)
+ void
+ PqArray<T>::GetValue(ValueTargetPtr s)
{
- if (this->Model.empty()) s->get("{}");
- std::vector<std::string> l2;
- l2.reserve(this->Model.size());
- for(const auto & i : this->Model) {
- l2.push_back(boost::lexical_cast<std::string>(i));
- }
- s->get("{" + boost::algorithm::join(l2, ",") + "}");
+ s->get(packPqArray(this->Model));
}
- void PqArray<std::string>::GetValue(ValueTargetPtr s)
+ void
+ PqArray<std::string>::GetValue(ValueTargetPtr s)
{
- if (Model.empty()) s->get("{}");
- ::Gentoo::StringList l2(Model);
- for(auto & i : l2) {
- boost::algorithm::replace_all(i, "\"", "\\\"");
- i = "\"" + i + "\"";
- }
- s->get("{" + boost::algorithm::join(l2, ",") + "}");
+ s->get(packPqArray(this->Model));
}
template class PqArray<Ice::Int>;
@@ -70,23 +67,37 @@ namespace Slicer {
unpackPqTextArray(const std::string & s)
{
::Gentoo::StringList list;
- std::stringstream ss(s);
- ::Portage::Utils::UnpackPqTextArray l(ss, list);
- l.yylex();
+ unpackPqTextArray(s, list);
return list;
}
+ template<typename T>
std::string
- packPqTextArray(const ::Gentoo::StringList & l)
+ packPqArray(const T & l)
{
if (l.empty()) return "{}";
- ::Gentoo::StringList l2(l);
- for(auto & i : l2) {
- boost::algorithm::replace_all(i, "\"", "\\\"");
- i = "\"" + i + "\"";
+ std::vector<std::string> l2;
+ l2.reserve(l.size());
+ for(const auto & i : l) {
+ l2.push_back(packPqVar(i));
}
return "{" + boost::algorithm::join(l2, ",") + "}";
}
+ template std::string packPqArray<std::set<std::string>>(const std::set<std::string> &);
+
+ template<typename T>
+ std::string
+ packPqVar(const T & l)
+ {
+ return boost::lexical_cast<std::string>(l);
+ }
+
+ template<>
+ std::string
+ packPqVar(const std::string & l)
+ {
+ return "\"" + boost::algorithm::replace_all_copy(l, "\"", "\\\"") + "\"";
+ }
boost::posix_time::ptime
shortDateToPosixTime(const std::string & s)
diff --git a/gentoobrowse-api/domain/converters.h b/gentoobrowse-api/domain/converters.h
index 84fd859..0bd7e91 100644
--- a/gentoobrowse-api/domain/converters.h
+++ b/gentoobrowse-api/domain/converters.h
@@ -29,9 +29,18 @@ namespace Slicer {
::Gentoo::StringList
unpackPqTextArray(const std::string & s);
+ template<typename T>
DLL_PUBLIC
std::string
- packPqTextArray(const ::Gentoo::StringList & l);
+ packPqArray(const T & l);
+
+ template<typename T>
+ std::string
+ packPqVar(const T & l);
+
+ template<>
+ std::string
+ packPqVar(const std::string & l);
DLL_PUBLIC
boost::posix_time::ptime
diff --git a/gentoobrowse-api/domain/unpackPqTextArray.h b/gentoobrowse-api/domain/unpackPqTextArray.h
index 246be71..aefaddd 100644
--- a/gentoobrowse-api/domain/unpackPqTextArray.h
+++ b/gentoobrowse-api/domain/unpackPqTextArray.h
@@ -7,19 +7,17 @@
#include <FlexLexer.h>
#endif
-namespace Portage {
- namespace Utils {
- class UnpackPqTextArray : public yyFlexLexer {
- public:
- UnpackPqTextArray(std::istream &, ::Gentoo::StringList & sl);
+namespace Slicer {
+ class UnpackPqTextArray : public yyFlexLexer {
+ public:
+ UnpackPqTextArray(std::istream &, ::Gentoo::StringList & sl);
- int yylex() override;
- void LexerError(const char * msg) override;
+ int yylex() override;
+ void LexerError(const char * msg) override;
- private:
- ::Gentoo::StringList & list;
- };
- }
+ private:
+ ::Gentoo::StringList & list;
+ };
}
#endif
diff --git a/gentoobrowse-api/domain/unpackPqTextArray.ll b/gentoobrowse-api/domain/unpackPqTextArray.ll
index e4b0ccd..f8cce5f 100644
--- a/gentoobrowse-api/domain/unpackPqTextArray.ll
+++ b/gentoobrowse-api/domain/unpackPqTextArray.ll
@@ -4,7 +4,7 @@
%option 8bit
%option stack
%option yylineno
-%option yyclass="Portage::Utils::UnpackPqTextArray"
+%option yyclass="Slicer::UnpackPqTextArray"
%option prefix="pqBase"
%{
@@ -57,19 +57,17 @@ char [^"]
%%
-namespace Portage {
- namespace Utils {
- UnpackPqTextArray::UnpackPqTextArray(std::istream & f, ::Gentoo::StringList & sl) :
- yyFlexLexer(&f, NULL),
- list(sl)
- {
- }
+namespace Slicer {
+ UnpackPqTextArray::UnpackPqTextArray(std::istream & f, ::Gentoo::StringList & sl) :
+ yyFlexLexer(&f, NULL),
+ list(sl)
+ {
+ }
- void
- UnpackPqTextArray::LexerError(const char * msg)
- {
- throw std::runtime_error(msg);
- }
- }
+ void
+ UnpackPqTextArray::LexerError(const char * msg)
+ {
+ throw std::runtime_error(msg);
+ }
}
diff --git a/gentoobrowse-api/service/maintenanceGitOperations.cpp b/gentoobrowse-api/service/maintenanceGitOperations.cpp
index feba275..b178100 100644
--- a/gentoobrowse-api/service/maintenanceGitOperations.cpp
+++ b/gentoobrowse-api/service/maintenanceGitOperations.cpp
@@ -21,22 +21,23 @@ namespace Gentoo {
namespace Service {
using namespace Utils::Git;
+ typedef std::set<std::string> StringSet;
+
static
int
- onFile(const git_diff_delta * delta, float, void * fileset)
+ onFile(const git_diff_delta * delta, void * fileset)
{
- static_cast<StringList *>(fileset)->push_back(delta->old_file.path);
- static_cast<StringList *>(fileset)->push_back(delta->new_file.path);
+ static_cast<StringSet *>(fileset)->insert(delta->old_file.path);
+ static_cast<StringSet *>(fileset)->insert(delta->new_file.path);
return 0;
}
+ template<typename T>
static
int
- onBinaryFile(const git_diff_delta * delta, const git_diff_binary *, void * fileset)
+ onFile(const git_diff_delta * delta, T, void * fileset)
{
- static_cast<StringList *>(fileset)->push_back(delta->old_file.path);
- static_cast<StringList *>(fileset)->push_back(delta->new_file.path);
- return 0;
+ return onFile(delta, fileset);
}
static
@@ -70,11 +71,8 @@ namespace Gentoo {
// Get tree to tree diff
auto diff = gitSafeGet(git_diff_tree_to_tree, git_diff_free, repo, currentTree.get(), parentTree.get(), nullptr);
// Compare trees
- StringList fs;
- git_diff_foreach(diff.get(), onFile, onBinaryFile, nullptr, nullptr, &fs);
- // Remove duplicate mentions of files
- std::sort(fs.begin(), fs.end());
- fs.erase(std::unique(fs.begin(), fs.end()), fs.end());
+ StringSet fs;
+ gitSafe(git_diff_foreach, diff.get(), onFile<float>, onFile<const git_diff_binary *>, nullptr, nullptr, &fs);
// Insert commit into DB
git_oid_tostr(str, sizeof(str), &oid);
@@ -85,7 +83,7 @@ namespace Gentoo {
cli->bindParamS(4, git_commit_body(commit.get()));
cli->bindParamS(5, sig->name);
cli->bindParamS(6, sig->email);
- cli->bindParamS(7, Slicer::packPqTextArray(fs));
+ cli->bindParamS(7, Slicer::packPqArray(fs));
cli->execute();
}
}
@@ -97,8 +95,9 @@ namespace Gentoo {
sql::maintenance::reposToUpdate.select(dbc.get())->forEachRow<std::string, std::string, std::string>(&updateRepository);
}
+ static
int
- insertFileChange(const git_diff_delta * delta, float, void * ptr)
+ insertFileChange(const git_diff_delta * delta, void * ptr)
{
auto ins = static_cast<DB::ModifyCommand *>(ptr);
switch (delta->status) {
@@ -121,6 +120,14 @@ namespace Gentoo {
return 0;
}
+ template<typename T>
+ static
+ int
+ insertFileChangeT(const git_diff_delta * delta, T, void * ptr)
+ {
+ return insertFileChange(delta, ptr);
+ }
+
static
void
writeChangesToFileList(DB::Connection * db, int64_t repoId, git_repository * repo, const git_oid & last, const git_oid & head);
@@ -155,7 +162,7 @@ namespace Gentoo {
auto diff = gitSafeGet(git_diff_tree_to_tree, git_diff_free, repo, lastTree.get(), headTree.get(), nullptr);
auto ins = db->modify("INSERT INTO filelistraw(repoid, status, filename) VALUES(?, ?, ?)");
ins->bindParamI(0, repoId);
- gitSafe(git_diff_foreach, diff.get(), insertFileChange, nullptr, nullptr, nullptr, ins.get());
+ gitSafe(git_diff_foreach, diff.get(), insertFileChangeT<float>, insertFileChangeT<const git_diff_binary *>, nullptr, nullptr, ins.get());
}
void