forked from qt-creator/qt-creator
Use QtcProcess in ClearCaseSync
Get rid of code repetition by making runProcess() a common method. Change-Id: If0b47fba4351119e7373caa250131891b9bb403d Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -28,19 +28,49 @@
|
|||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFutureInterface>
|
#include <QFutureInterface>
|
||||||
#include <QProcess>
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace ClearCase {
|
namespace ClearCase {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
static void runProcess(QFutureInterface<void> &future,
|
||||||
|
const ClearCaseSettings &settings,
|
||||||
|
const QStringList &args,
|
||||||
|
std::function<void(const QString &buffer, int processed)> processLine)
|
||||||
|
{
|
||||||
|
const QString viewRoot = ClearCasePlugin::viewData().root;
|
||||||
|
QtcProcess process;
|
||||||
|
process.setWorkingDirectory(viewRoot);
|
||||||
|
process.setCommand({FilePath::fromString(settings.ccBinaryPath), args});
|
||||||
|
process.start();
|
||||||
|
if (!process.waitForStarted())
|
||||||
|
return;
|
||||||
|
|
||||||
|
int processed = 0;
|
||||||
|
QString buffer;
|
||||||
|
while (process.waitForReadyRead() && !future.isCanceled()) {
|
||||||
|
buffer += QString::fromLocal8Bit(process.readAllStandardOutput());
|
||||||
|
while (const int index = buffer.indexOf('\n') != -1) {
|
||||||
|
const QString line = buffer.left(index + 1);
|
||||||
|
processLine(line, ++processed);
|
||||||
|
buffer = buffer.mid(index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!buffer.isEmpty())
|
||||||
|
processLine(buffer, ++processed);
|
||||||
|
}
|
||||||
|
|
||||||
ClearCaseSync::ClearCaseSync(QSharedPointer<StatusMap> statusMap) :
|
ClearCaseSync::ClearCaseSync(QSharedPointer<StatusMap> statusMap) :
|
||||||
m_statusMap(statusMap)
|
m_statusMap(statusMap)
|
||||||
{ }
|
{ }
|
||||||
@@ -132,7 +162,6 @@ void ClearCaseSync::syncSnapshotView(QFutureInterface<void> &future, QStringList
|
|||||||
|
|
||||||
int totalFileCount = files.size();
|
int totalFileCount = files.size();
|
||||||
const bool hot = (totalFileCount < 10);
|
const bool hot = (totalFileCount < 10);
|
||||||
int processed = 0;
|
|
||||||
if (!hot)
|
if (!hot)
|
||||||
totalFileCount = settings.totalFiles.value(view, totalFileCount);
|
totalFileCount = settings.totalFiles.value(view, totalFileCount);
|
||||||
|
|
||||||
@@ -159,40 +188,20 @@ void ClearCaseSync::syncSnapshotView(QFutureInterface<void> &future, QStringList
|
|||||||
// adding 1 for initial sync in which total is not accurate, to prevent finishing
|
// adding 1 for initial sync in which total is not accurate, to prevent finishing
|
||||||
// (we don't want it to become green)
|
// (we don't want it to become green)
|
||||||
future.setProgressRange(0, totalFileCount + 1);
|
future.setProgressRange(0, totalFileCount + 1);
|
||||||
QProcess process;
|
|
||||||
process.setWorkingDirectory(viewRoot);
|
|
||||||
|
|
||||||
const QString program = settings.ccBinaryPath;
|
int totalProcessed = 0;
|
||||||
|
runProcess(future, settings, args, [&](const QString &buffer, int processed) {
|
||||||
process.start(program, args);
|
processCleartoolLsLine(viewRootDir, buffer);
|
||||||
if (!process.waitForStarted())
|
future.setProgressValue(qMin(totalFileCount, processed));
|
||||||
return;
|
totalProcessed = processed;
|
||||||
QString buffer;
|
});
|
||||||
while (process.waitForReadyRead() && !future.isCanceled()) {
|
|
||||||
while (process.state() == QProcess::Running &&
|
|
||||||
process.bytesAvailable() && !future.isCanceled())
|
|
||||||
{
|
|
||||||
const QString line = QString::fromLocal8Bit(process.readLine().constData());
|
|
||||||
buffer += line;
|
|
||||||
if (buffer.endsWith(QLatin1Char('\n')) || process.atEnd()) {
|
|
||||||
processCleartoolLsLine(viewRootDir, buffer);
|
|
||||||
buffer.clear();
|
|
||||||
future.setProgressValue(qMin(totalFileCount, ++processed));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!future.isCanceled()) {
|
if (!future.isCanceled()) {
|
||||||
updateStatusForNotManagedFiles(files);
|
updateStatusForNotManagedFiles(files);
|
||||||
future.setProgressValue(totalFileCount + 1);
|
future.setProgressValue(totalFileCount + 1);
|
||||||
if (!hot)
|
if (!hot)
|
||||||
updateTotalFilesCount(view, settings, processed);
|
updateTotalFilesCount(view, settings, totalProcessed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.state() == QProcess::Running)
|
|
||||||
process.kill();
|
|
||||||
|
|
||||||
process.waitForFinished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearCaseSync::processCleartoolLscheckoutLine(const QString &buffer)
|
void ClearCaseSync::processCleartoolLscheckoutLine(const QString &buffer)
|
||||||
@@ -210,37 +219,12 @@ void ClearCaseSync::syncDynamicView(QFutureInterface<void> &future,
|
|||||||
// Always invalidate status for all files
|
// Always invalidate status for all files
|
||||||
invalidateStatusAllFiles();
|
invalidateStatusAllFiles();
|
||||||
|
|
||||||
QStringList args({"lscheckout", "-avobs", "-me", "-cview", "-s"});
|
const QStringList args({"lscheckout", "-avobs", "-me", "-cview", "-s"});
|
||||||
|
|
||||||
const QString viewRoot = ClearCasePlugin::viewData().root;
|
runProcess(future, settings, args, [&](const QString &buffer, int processed) {
|
||||||
|
processCleartoolLscheckoutLine(buffer);
|
||||||
QProcess process;
|
future.setProgressValue(processed);
|
||||||
process.setWorkingDirectory(viewRoot);
|
});
|
||||||
|
|
||||||
const QString program = settings.ccBinaryPath;
|
|
||||||
process.start(program, args);
|
|
||||||
if (!process.waitForStarted())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QString buffer;
|
|
||||||
int processed = 0;
|
|
||||||
while (process.waitForReadyRead() && !future.isCanceled()) {
|
|
||||||
while (process.state() == QProcess::Running &&
|
|
||||||
process.bytesAvailable() && !future.isCanceled()) {
|
|
||||||
const QString line = QString::fromLocal8Bit(process.readLine().constData());
|
|
||||||
buffer += line;
|
|
||||||
if (buffer.endsWith(QLatin1Char('\n')) || process.atEnd()) {
|
|
||||||
processCleartoolLscheckoutLine(buffer);
|
|
||||||
buffer.clear();
|
|
||||||
future.setProgressValue(++processed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.state() == QProcess::Running)
|
|
||||||
process.kill();
|
|
||||||
|
|
||||||
process.waitForFinished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearCaseSync::run(QFutureInterface<void> &future, QStringList &files)
|
void ClearCaseSync::run(QFutureInterface<void> &future, QStringList &files)
|
||||||
|
Reference in New Issue
Block a user