# # # patch "src/monotone/MonotoneManager.cpp" # from [44de03b024e3c17e7f103e1232aa44ba8c42cb19] # to [a17a4f2ff69e20060d1699e699b42b1c015063cf] # # patch "src/monotone/MonotoneManager.h" # from [9298b06cfcb42318c73a0b32148ec744a0d2b18f] # to [b88dfb8198ac73168c3e313927d39ef357530964] # ============================================================ --- src/monotone/MonotoneManager.cpp 44de03b024e3c17e7f103e1232aa44ba8c42cb19 +++ src/monotone/MonotoneManager.cpp a17a4f2ff69e20060d1699e699b42b1c015063cf @@ -22,11 +22,25 @@ #include "vocab.h" #include "BasicIOParser.h" -// including this version const QString MonotoneManager::MinInterfaceVersion = MIN_MTN_INT_VERSION; -// excluding this version const QString MonotoneManager::MaxInterfaceVersion = MAX_MTN_INT_VERSION; +MonotoneManager::MonotoneManager() : threadNumber(0) {} + +MonotoneManager::~MonotoneManager() {} + +bool MonotoneManager::setMonotoneBinaryPath(const QString & mtnBinary, QString & pathVersion) +{ + pathVersion = getInterfaceVersion(mtnBinary); + if (versionCompare(pathVersion, MinInterfaceVersion) >= 0 && + versionCompare(pathVersion, MaxInterfaceVersion) < 0) + { + mtnPath = mtnBinary; + return true; + } + return false; +} + // FIXME: I think we need to care somehow if we pass // threads around - i.e. use shared ptrs or something MonotoneThread * MonotoneManager::getThreadForWorkspace(const WorkspacePath & workspace) @@ -43,6 +57,9 @@ MonotoneThread * MonotoneManager::getThr MonotoneThread * MonotoneManager::getThread(const DatabaseFile & database, const WorkspacePath & workspace) { + if (mtnPath.isEmpty()) + throw GuitoneException("Monotone binary path not set"); + // FIXME: since we cannot set the workspace directory after we've // started the process, we need to ensure that each workspace runs with // its own process @@ -161,22 +178,23 @@ void MonotoneManager::aborted(int thread Q_UNUSED(message); } -bool MonotoneManager::singleRun(const QStringList & params, QByteArray & output) +bool MonotoneManager::singleRun(const QString & mtnBinary, + const QStringList & params, QByteArray & output) { QProcess proc; - proc.start(mtnPath, params); + proc.start(mtnBinary, params); // could not be started (invalid path, not executable, ...) if (!proc.waitForStarted(5000)) { - C(QString("`mtn %1` not started").arg(params.join(" "))); + C(QString("`%1 %2` not started").arg(mtnBinary).arg(params.join(" "))); return false; } // process doesn't return, etc... if (!proc.waitForFinished(5000)) { - C(QString("`mtn %1` not finished").arg(params.join(" "))); + C(QString("`%1 %2` not finished").arg(mtnBinary).arg(params.join(" "))); return false; } @@ -185,19 +203,18 @@ bool MonotoneManager::singleRun(const QS return true; } -bool MonotoneManager::checkInterfaceVersion() +QString MonotoneManager::getInterfaceVersion(const QString & mtnBinary) { QByteArray output; - QStringList opts; - if (!singleRun(QStringList() << "automate" << "interface_version", output)) + if (!singleRun(mtnBinary, QStringList() << "automate" << "interface_version", output)) { C("Couldn't execute `automate interface_version`"); - return false; + return QString(); } + QString versionString(QString::fromUtf8(output)); QRegExp regex("^(\\d+(?:\\.\\d+))"); - QString versionString = QString::fromUtf8(output); if (regex.indexIn(versionString) == -1) { @@ -205,16 +222,7 @@ bool MonotoneManager::checkInterfaceVers return false; } - QString curVersion = regex.cap(1); - - D(QString("interface version: %1, need one between ['%2' .. '%3'[") - .arg(curVersion) - .arg(MinInterfaceVersion) - .arg(MaxInterfaceVersion) - ); - - return versionCompare(curVersion, MinInterfaceVersion) >= 0 && - versionCompare(curVersion, MaxInterfaceVersion) < 0; + return regex.cap(1); } /*! ============================================================ --- src/monotone/MonotoneManager.h 9298b06cfcb42318c73a0b32148ec744a0d2b18f +++ src/monotone/MonotoneManager.h b88dfb8198ac73168c3e313927d39ef357530964 @@ -27,11 +27,11 @@ public: { Q_OBJECT public: - MonotoneManager(const QString & p) : mtnPath(p), threadNumber(0) {}; - ~MonotoneManager() {}; + MonotoneManager(); + ~MonotoneManager(); - //! set the path to the monotone binary to use for all threads - inline void setMtnBinaryPath(const QString & path) { mtnPath = path; } + //! set the path to the monotone binary to use for all new threads + bool setMonotoneBinaryPath(const QString &, QString &); //! returns the database filepath for a given workspace path DatabaseFile getDatabaseFilePath(const WorkspacePath &); @@ -42,19 +42,23 @@ public: //! returns an appropriate MonotoneThread for the given database MonotoneThread * getThreadForDatabase(const DatabaseFile &); - //! runs a single, non-automate monotone command - bool singleRun(const QStringList &, QByteArray &); + //! runs a single command and returns its output + static bool singleRun(const QString &, const QStringList &, QByteArray &); - //! returns true if the loaded mtn binary suffices the version requirements - bool checkInterfaceVersion(); + //! returns the interface version of a given monotone binary + static QString getInterfaceVersion(const QString &); + //! compares two version strings + static int versionCompare(const QString &, const QString &); + + //! the minimum required interface version needed static const QString MinInterfaceVersion; + //! the maximum allowed interface version (excluding this particular version) static const QString MaxInterfaceVersion; private: MonotoneThread * getThread(const DatabaseFile &, const WorkspacePath &); WorkspacePath normalizeWorkspacePath(const WorkspacePath &); - int versionCompare(const QString &, const QString &); QMap threadMap; QMap workspaceMap;