commit 5dde65efff32f3f31cb53017e6ce9cf7eb1992f9
parent da7e5df2c5ee703b1da06cb97d9f0d767b8eec4a
Author: cfillion <cfillion@users.noreply.github.com>
Date: Tue, 20 Jun 2017 18:48:33 -0400
import: add repositories in the same order as they were entered in the URL text field
Diffstat:
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/src/import.cpp b/src/import.cpp
@@ -97,8 +97,7 @@ ThreadPool *Import::setupPool()
if(!m_state)
processQueue();
- queue<ImportData> clear;
- m_queue.swap(clear);
+ m_queue.clear();
delete m_pool;
m_pool = nullptr;
@@ -120,6 +119,7 @@ void Import::fetch()
const auto &opts = m_reapack->config()->network;
+ size_t index = 0;
stringstream stream(getText(m_url));
string url;
while(getline(stream, url)) {
@@ -129,12 +129,13 @@ void Import::fetch()
continue;
MemoryDownload *dl = new MemoryDownload(url, opts);
+ ++index;
dl->onFinish([=] {
switch(dl->state()) {
case ThreadTask::Success:
// copy for later use, as `dl` won't be around after this callback
- if(!read(dl))
+ if(!read(dl, index))
m_pool->abort();
break;
case ThreadTask::Failure: {
@@ -160,7 +161,7 @@ void Import::fetch()
close();
}
-bool Import::read(MemoryDownload *dl)
+bool Import::read(MemoryDownload *dl, const size_t idx)
{
auto_char msg[1024];
@@ -194,7 +195,7 @@ bool Import::read(MemoryDownload *dl)
remote.setName(index->name());
remote.setUrl(dl->url());
- m_queue.push({remote, dl->contents()});
+ m_queue.push_back({idx, remote, dl->contents()});
return true;
}
@@ -212,11 +213,13 @@ void Import::processQueue()
{
bool ok = true, commit = !m_queue.empty();
+ sort(m_queue.begin(), m_queue.end());
+
while(!m_queue.empty()) {
if(!import(m_queue.front()))
ok = false;
- m_queue.pop();
+ m_queue.pop_front();
}
if(ok)
diff --git a/src/import.hpp b/src/import.hpp
@@ -22,7 +22,7 @@
#include "remote.hpp"
-#include <queue>
+#include <deque>
#include <string>
class MemoryDownload;
@@ -46,11 +46,17 @@ private:
Close,
};
- struct ImportData { Remote remote; std::string contents; };
+ struct ImportData {
+ size_t index;
+ Remote remote;
+ std::string contents;
+
+ bool operator<(const ImportData &o) const { return index < o.index; }
+ };
ThreadPool *setupPool();
void fetch();
- bool read(MemoryDownload *);
+ bool read(MemoryDownload *, size_t index);
void processQueue();
bool import(const ImportData &);
void setWaiting(bool);
@@ -58,7 +64,7 @@ private:
ReaPack *m_reapack;
ThreadPool *m_pool;
State m_state;
- std::queue<ImportData> m_queue;
+ std::deque<ImportData> m_queue;
short m_fakePos;
HWND m_url;