# # # patch "src/model/GetContentChanged.cpp" # from [fac748457f536fe8ae1e4022dfc4be9ae9e3a4eb] # to [3dc7307b83aa8f92a1a5643d7cd76f447a3beec8] # # patch "src/model/GetContentChanged.h" # from [2caf1a98c245f56c89c7036aaf0814338b7327f7] # to [174eb4b1c48da00efa1af2b3169c42f8fa620f7a] # ============================================================ --- src/model/GetContentChanged.cpp fac748457f536fe8ae1e4022dfc4be9ae9e3a4eb +++ src/model/GetContentChanged.cpp 3dc7307b83aa8f92a1a5643d7cd76f447a3beec8 @@ -20,14 +20,13 @@ #include "GetContentChanged.h" #include "BasicIOParser.h" +#include "MonotoneUtil.h" #include -GetContentChanged::GetContentChanged(QObject *parent) - : QAbstractItemModel(parent) -{ - mtnDelegate = new MonotoneDelegate(this); -} +GetContentChanged::GetContentChanged(QObject * parent, const QString & db) + : QAbstractItemModel(parent), AutomateCommand(db) +{} GetContentChanged::~GetContentChanged() { @@ -38,8 +37,6 @@ GetContentChanged::~GetContentChanged() revisions.clear(); pathInRevision.clear(); - - delete mtnDelegate; } // @@ -65,7 +62,7 @@ GetContentChanged::~GetContentChanged() // | V // |--- < --- [ get corresponding path for each parent ] -> stop if no path // -bool GetContentChanged::readChanges(const QString & path) +void GetContentChanged::readChanges(const QString & path) { revisions.clear(); pathInRevision.clear(); @@ -75,59 +72,80 @@ bool GetContentChanged::readChanges(cons // find a starting point // FIXME: we assume that the given path is part of this revision! - startRev = MonotoneDelegate::getBaseWorkspaceRevision(this); + startRev = MonotoneUtil::getBaseWorkspaceRevision(getDbPath()); I(!startRev.isNull()); startPath = path; - return queryContentChanged(startRev, startPath); + queryContentChanged(startRev, startPath); } -bool GetContentChanged::queryContentChanged(const QString & rev, const QString & path) +void GetContentChanged::queryContentChanged(const QString & rev, const QString & path) { commandStack.enqueue(ContentChanged); - QStringList cmd; - cmd << "get_content_changed" << rev << path; - return mtnDelegate->triggerCommand(cmd); + MonotoneTask task(QStringList() << "get_content_changed" << rev << path); + AutomateCommand::enqueueTask(task); } -bool GetContentChanged::queryParents(const QString & rev) +void GetContentChanged::queryParents(const QString & rev) { commandStack.enqueue(Parents); - QStringList cmd; - cmd << "parents" << rev; - return mtnDelegate->triggerCommand(cmd); + MonotoneTask task(QStringList() << "parents" << rev); + AutomateCommand::enqueueTask(task); } -bool GetContentChanged::queryCorrespondingPath(const QString & rev, const QString & path, const QString & par) +void GetContentChanged::queryCorrespondingPath(const QString & rev, const QString & path, const QString & par) { commandStack.enqueue(CorrespondingPath); - QStringList cmd; - cmd << "get_corresponding_path" << rev << path << par; - return mtnDelegate->triggerCommand(cmd); + MonotoneTask task(QStringList() << "get_corresponding_path" << rev << path << par); + AutomateCommand::enqueueTask(task); } -void GetContentChanged::parseOutput() +void GetContentChanged::processTaskResult(const MonotoneTask & task) { + if (task.getReturnCode() == 2) + { + // FIXME: this is a big hack, since we assume that the only error 2 + // we can get here for this command basically reads like + // file "foo" doesn't exists in revision "bar" + // but yeah, localized string parsing is stupid as well + if (commandStack.head() == CorrespondingPath) + { + commandStack.dequeue(); + reset(); + emit endOfLineReached(); + return; + } + } + + if (task.getReturnCode() != 0) + { + C(QString("Command returned with a non-zero return code (%1)") + .arg(task.getOutputUtf8())); + return; + } + // this method is called when we either called get_content_changed, // parents or get_corresponding_path // to decide what to do next, we need to know what was triggered // lately in the queue Command current = commandStack.dequeue(); + QString output = task.getOutputUtf8(); if (current == Parents) { - if (AutomateCommand::data.isEmpty()) + + if (output.isEmpty()) { reset(); emit rootReached(); return; } - QStringList parents = AutomateCommand::data.split( + QStringList parents = output.split( '\n', QString::SkipEmptyParts ); @@ -140,7 +158,7 @@ void GetContentChanged::parseOutput() } revsForPathStack.enqueue(par); - I(queryCorrespondingPath(startRev, startPath, par)); + queryCorrespondingPath(startRev, startPath, par); } return; } @@ -150,7 +168,7 @@ void GetContentChanged::parseOutput() // since we're looking for a file in a certain revision // _beforehand_ via get_corresponding_path, we should always // get a stanza out here - BasicIOParser parser(AutomateCommand::data); + BasicIOParser parser(output); I(parser.parse()); StanzaList stanzas = parser.getStanzas(); foreach (Stanza st, stanzas) @@ -174,12 +192,12 @@ void GetContentChanged::parseOutput() revsForPathStack.enqueue(rev); // query for the corresponding path - I(queryCorrespondingPath(startRev, startPath, rev)); + queryCorrespondingPath(startRev, startPath, rev); } // query for the parents of this revision for the // next round - I(queryParents(rev)); + queryParents(rev); } return; } @@ -189,24 +207,7 @@ void GetContentChanged::parseOutput() I(revsForPathStack.size() > 0); QString rev = revsForPathStack.dequeue(); - if (AutomateCommand::data.isEmpty()) - { - // check if this is a marked node, if so, - // we have a serious problem (node is changed in this rev, - // but has no corresponding path) - if (revisions.contains(rev)) - { - I(false); - } - - // apparently this is another, not interesting (parent) node - // note that this can happen - reset(); - emit endOfLineReached(); - return; - } - - BasicIOParser parser(AutomateCommand::data); + BasicIOParser parser(output); I(parser.parse()); StanzaList stanzas = parser.getStanzas(); I(stanzas.size() == 1); @@ -222,36 +223,16 @@ void GetContentChanged::parseOutput() pathInRevision.insert(rev, path); // try to get the next marked node - I(queryContentChanged(rev, path)); + queryContentChanged(rev, path); return; } I(false); } -bool GetContentChanged::handleError(int retCode) -{ - if (retCode == 2) - { - I(commandStack.size() > 0); - - // FIXME: this is a big hack, since we assume that the only error 2 - // we can get here for this command basically reads like - // file "foo" doesn't exists in revision "bar" - // but yeah, localized string parsing is stupid as well - if (commandStack.head() == CorrespondingPath) - { - AutomateCommand::data.clear(); - parseOutput(); - return true; - } - } - - return false; -} - int GetContentChanged::columnCount(const QModelIndex & parent) const { + Q_UNUSED(parent); return 2; } @@ -314,6 +295,7 @@ int GetContentChanged::rowCount(const QM int GetContentChanged::rowCount(const QModelIndex & parent) const { + Q_UNUSED(parent); return revisions.size(); } @@ -329,6 +311,7 @@ QModelIndex GetContentChanged::parent(co QModelIndex GetContentChanged::parent(const QModelIndex & index) const { + Q_UNUSED(index); return QModelIndex(); } ============================================================ --- src/model/GetContentChanged.h 2caf1a98c245f56c89c7036aaf0814338b7327f7 +++ src/model/GetContentChanged.h 174eb4b1c48da00efa1af2b3169c42f8fa620f7a @@ -22,7 +22,6 @@ #define GETCONTENTCHANGED_H #include "AutomateCommand.h" -#include "MonotoneDelegate.h" #include #include @@ -34,20 +33,20 @@ public: { Q_OBJECT public: - GetContentChanged(QObject*); + GetContentChanged(QObject *, const QString &); virtual ~GetContentChanged(); // needed Qt Model methods - QVariant data(const QModelIndex&, int) const; - Qt::ItemFlags flags(const QModelIndex&) const; + QVariant data(const QModelIndex &, int) const; + Qt::ItemFlags flags(const QModelIndex &) const; QVariant headerData(int, Qt::Orientation, int) const; - QModelIndex index(int, int, const QModelIndex&) const; - QModelIndex parent(const QModelIndex&) const; - int rowCount(const QModelIndex&) const; - int columnCount(const QModelIndex&) const; + QModelIndex index(int, int, const QModelIndex &) const; + QModelIndex parent(const QModelIndex &) const; + int rowCount(const QModelIndex &) const; + int columnCount(const QModelIndex &) const; public slots: - bool readChanges(const QString &); + void readChanges(const QString &); signals: // is emitted each time the algorithm reaches the end of a @@ -58,16 +57,14 @@ private: void rootReached(); private: - bool queryContentChanged(const QString &, const QString &); - bool queryParents(const QString &); - bool queryCorrespondingPath(const QString &, const QString &, const QString &); + void queryContentChanged(const QString &, const QString &); + void queryParents(const QString &); + void queryCorrespondingPath(const QString &, const QString &, const QString &); - void parseOutput(); - bool handleError(int); + void processTaskResult(const MonotoneTask &); RevisionList revisions; - MonotoneDelegate * mtnDelegate; - + enum Command { ContentChanged, CorrespondingPath, Parents }; QQueue commandStack;