# # # patch "guitone/src/monotone/Monotone.cpp" # from [62f2c36eb1d9c833b6cb10932b2894c15fb9fec9] # to [36f07b16c20c0844db126fd93f333e38e1ca17ff] # # patch "guitone/src/monotone/Monotone.h" # from [e23a053216c6941cdd5e5f5f7cd5cabad4ceb53b] # to [4082863bc15b609d153c0df708698b814d0d2340] # ============================================================ --- guitone/src/monotone/Monotone.cpp 62f2c36eb1d9c833b6cb10932b2894c15fb9fec9 +++ guitone/src/monotone/Monotone.cpp 36f07b16c20c0844db126fd93f333e38e1ca17ff @@ -113,13 +113,13 @@ void Monotone::processTerminated(int cod emit criticalError(tr("The connection to the monotone process was terminated (Code %1). Check your configuration and reload the current workspace afterwards.").arg(code)); } -bool Monotone::executeCommand(const QStringList & command) +bool Monotone::executeCommand(const QStringList & command, int & retCode) { QStringList opts; - return executeCommand(command, opts); + return executeCommand(command, opts, retCode); } -bool Monotone::executeCommand(const QStringList & command, const QStringList & options) +bool Monotone::executeCommand(const QStringList & command, const QStringList & options, int & retCode) { SignalWaiter waiter(process, SIGNAL(readyReadStandardOutput())); @@ -131,11 +131,8 @@ bool Monotone::executeCommand(const QStr while (waiter.wait(1000)) { - input.append(process->readAllStandardOutput()); - // check if we already could parse the complete stdio output - int dummy; - if (!parseStdio(dummy)) + if (!readAndParseStdout(retCode)) { qWarning("Monotone::executeCommand: Contents incomplete/invalid."); continue; @@ -147,6 +144,7 @@ bool Monotone::executeCommand(const QStr } qWarning("Monotone::executeCommand: Timed out waiting for output."); + isProcessingData = false; return false; } @@ -160,7 +158,7 @@ bool Monotone::triggerCommand(AutomateCo // read & parse mtn's output as soon as it gets available connect( process, SIGNAL(readyReadStandardOutput()), - this, SLOT(readStdout()) + this, SLOT(readAndProcessCommand()) ); // connect the caller with us so he knows when the command is finished @@ -208,9 +206,10 @@ bool Monotone::writeStdin(const QStringL commandLine += "o"; for (int i=0, c=options.size(); ireadAllStandardOutput()); - int retCode = 0; - // check if we already could parse the complete stdio output - if (!parseStdio(retCode)) + if (!readAndParseStdout(retCode)) { - qWarning("Monotone::readStdout: Contents incomplete/invalid."); + qWarning("Monotone::readAndProcessInput: Contents incomplete/invalid."); return; } @@ -270,7 +265,7 @@ void Monotone::readStdout() disconnect( process, SIGNAL(readyReadStandardOutput()), - this, SLOT(readStdout()) + this, SLOT(readAndProcessCommand()) ); disconnect( @@ -281,7 +276,7 @@ void Monotone::readStdout() // emit a critical error which closes the app later emit criticalError( tr("Unable to process command '%1': %2") - .arg(commandLine) + .arg(commandLine.left(commandLine.size() - 1)) .arg(output) ); return; @@ -291,7 +286,7 @@ void Monotone::readStdout() disconnect( process, SIGNAL(readyReadStandardOutput()), - this, SLOT(readStdout()) + this, SLOT(readAndProcessCommand()) ); disconnect( @@ -300,8 +295,11 @@ void Monotone::readStdout() ); } -bool Monotone::parseStdio(int & retCode) +bool Monotone::readAndParseStdout(int & retCode) { + QByteArray byteArray = process->readAllStandardOutput(); + input.append(byteArray); + // parse out the contents of each line QRegExp regex("^(\\d+):(\\d+):([ml]):(\\d+):"); @@ -321,6 +319,8 @@ bool Monotone::parseStdio(int & retCode) // when subsequent data are flushed and processed here if (input.length() < outBytes) { + qDebug("%d <> %d (%s)", input.length(), outBytes, qPrintable(input)); + // prepend the data header again input.prepend(QString("%1:%2:%3:%4:") .arg(list[1]) @@ -331,8 +331,11 @@ bool Monotone::parseStdio(int & retCode) return false; } - // add the byte amount to the output string - output.append(input.left(outBytes)); + // add the byte amount to the output string, make sure that these + // contents are properly recognized as UTF-8 encoded + QByteArray newOutput = input.left(outBytes).toAscii(); + const char * data = newOutput.data(); + output.append(QString::fromUtf8(data)); // and remove it from the input string input = input.right(input.length() - outBytes); ============================================================ --- guitone/src/monotone/Monotone.h e23a053216c6941cdd5e5f5f7cd5cabad4ceb53b +++ guitone/src/monotone/Monotone.h 4082863bc15b609d153c0df708698b814d0d2340 @@ -41,16 +41,17 @@ class Monotone : public QObject bool triggerCommand(AutomateCommand*, const QStringList &); bool triggerCommand(AutomateCommand*, const QStringList &, const QStringList &); - bool executeCommand(const QStringList &); - bool executeCommand(const QStringList &, const QStringList &); + bool executeCommand(const QStringList &, int &); + bool executeCommand(const QStringList &, const QStringList &, int &); inline QString getOutput() { return output; } private: + Monotone(QObject *); + bool writeStdin(const QStringList &, const QStringList &); - bool parseStdio(int &); + bool readAndParseStdout(int &); - Monotone(QObject *); QString input; QString output; QString commandLine; @@ -61,7 +62,7 @@ class Monotone : public QObject QProcess * process; private slots: - void readStdout(); + void readAndProcessCommand(); void processTerminated(int, QProcess::ExitStatus); void startupError(QProcess::ProcessError);