aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorJarek Kobus <[email protected]>2021-11-05 14:06:44 +0100
committerJarek Kobus <[email protected]>2021-11-08 12:22:22 +0000
commit50272f21f1d2b6c1df9ca84c5870d77614283bc2 (patch)
treec6781419274e5dc0aa03087faed0c05ba99e4ccf /src/plugins
parent3b9b9bdc0b6c6b520475e314e367af24cf841cc2 (diff)
Use QtcProcess in ClearCaseSync
Get rid of code repetition by making runProcess() a common method. Change-Id: If0b47fba4351119e7373caa250131891b9bb403d Reviewed-by: Orgad Shaneh <[email protected]>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/clearcase/clearcasesync.cpp102
1 files changed, 43 insertions, 59 deletions
diff --git a/src/plugins/clearcase/clearcasesync.cpp b/src/plugins/clearcase/clearcasesync.cpp
index ba678c70217..fff514f5c1c 100644
--- a/src/plugins/clearcase/clearcasesync.cpp
+++ b/src/plugins/clearcase/clearcasesync.cpp
@@ -28,19 +28,49 @@
#include <QDir>
#include <QFutureInterface>
-#include <QProcess>
#include <QRegularExpression>
#include <QStringList>
+
#include <utils/qtcassert.h>
+#include <utils/qtcprocess.h>
#ifdef WITH_TESTS
#include <QTest>
#include <utils/fileutils.h>
#endif
+using namespace Utils;
+
namespace ClearCase {
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) :
m_statusMap(statusMap)
{ }
@@ -132,7 +162,6 @@ void ClearCaseSync::syncSnapshotView(QFutureInterface<void> &future, QStringList
int totalFileCount = files.size();
const bool hot = (totalFileCount < 10);
- int processed = 0;
if (!hot)
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
// (we don't want it to become green)
future.setProgressRange(0, totalFileCount + 1);
- QProcess process;
- process.setWorkingDirectory(viewRoot);
-
- const QString program = settings.ccBinaryPath;
- process.start(program, args);
- if (!process.waitForStarted())
- return;
- 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));
- }
- }
- }
+ int totalProcessed = 0;
+ runProcess(future, settings, args, [&](const QString &buffer, int processed) {
+ processCleartoolLsLine(viewRootDir, buffer);
+ future.setProgressValue(qMin(totalFileCount, processed));
+ totalProcessed = processed;
+ });
if (!future.isCanceled()) {
updateStatusForNotManagedFiles(files);
future.setProgressValue(totalFileCount + 1);
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)
@@ -210,37 +219,12 @@ void ClearCaseSync::syncDynamicView(QFutureInterface<void> &future,
// Always invalidate status for all files
invalidateStatusAllFiles();
- QStringList args({"lscheckout", "-avobs", "-me", "-cview", "-s"});
-
- const QString viewRoot = ClearCasePlugin::viewData().root;
-
- QProcess process;
- 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();
+ const QStringList args({"lscheckout", "-avobs", "-me", "-cview", "-s"});
- process.waitForFinished();
+ runProcess(future, settings, args, [&](const QString &buffer, int processed) {
+ processCleartoolLscheckoutLine(buffer);
+ future.setProgressValue(processed);
+ });
}
void ClearCaseSync::run(QFutureInterface<void> &future, QStringList &files)