reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 0acd3da61175cf28de4d7d3793400911f156f744
parent 115ae83c0ec5ee72c2def523a9fd4d47dc6afc30
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon,  4 Jan 2016 22:28:28 -0500

synchronize enabled remotes only

Diffstat:
Msrc/reapack.cpp | 14+++++++++-----
Msrc/remote.cpp | 14++++++++++++++
Msrc/remote.hpp | 3++-
Msrc/transaction.cpp | 6------
Msrc/transaction.hpp | 1-
Mtest/remote.cpp | 11+++++++++++
6 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -90,18 +90,22 @@ bool ReaPack::execActions(const int id, const int) void ReaPack::synchronize() { - const RemoteList *remotes = m_config->remotes(); + const vector<Remote> &remotes = m_config->remotes()->getEnabled(); - if(remotes->empty()) { - ShowMessageBox("No remote repository configured, nothing to do!", + if(remotes.empty()) { + ShowMessageBox("No remote repository enabled, nothing to do!", "ReaPack", 0); return; } Transaction *t = createTransaction(); - if(t) - m_transaction->fetch(remotes); + + if(!t) + return; + + for(const Remote &remote : remotes) + t->fetch(remote); } void ReaPack::importRemote() diff --git a/src/remote.cpp b/src/remote.cpp @@ -171,3 +171,17 @@ Remote RemoteList::get(const string &name) const else return it->second; } + +vector<Remote> RemoteList::getEnabled() const +{ + vector<Remote> list; + + for(const auto &pair : m_remotes) { + const Remote &remote = pair.second; + + if(remote.isEnabled()) + list.push_back(remote); + } + + return list; +} diff --git a/src/remote.hpp b/src/remote.hpp @@ -18,10 +18,10 @@ #ifndef REAPACK_REMOTE_HPP #define REAPACK_REMOTE_HPP -#include <boost/optional.hpp> #include <boost/range/adaptor/map.hpp> #include <map> #include <string> +#include <vector> class Remote { public: @@ -84,6 +84,7 @@ public: { return boost::adaptors::values(m_remotes).end(); } Remote get(const std::string &name) const; + std::vector<Remote> getEnabled() const; }; #endif diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -44,12 +44,6 @@ Transaction::~Transaction() delete db; } -void Transaction::fetch(const RemoteList *remotes) -{ - for(const Remote &remote : *remotes) - fetch(remote); -} - void Transaction::fetch(const Remote &remote) { Download *dl = new Download(remote.name(), remote.url()); diff --git a/src/transaction.hpp b/src/transaction.hpp @@ -50,7 +50,6 @@ public: void onFinish(const Callback &callback) { m_onFinish.connect(callback); } void onDestroy(const Callback &callback) { m_onDestroy.connect(callback); } - void fetch(const RemoteList *); void fetch(const Remote &); void run(); void cancel(); diff --git a/test/remote.cpp b/test/remote.cpp @@ -249,3 +249,14 @@ TEST_CASE("serialize remote", M) { REQUIRE(Remote("name", "url", false).toString() == "name|url|0"); } } + +TEST_CASE("get enabled remotes", M) { + RemoteList list; + list.add({"hello", "url1", true}); + list.add({"world", "url2", false}); + + const vector<Remote> array = list.getEnabled(); + + REQUIRE(array.size() == 1); + REQUIRE(array[0].name() == "hello"); +}