VcsCommand: Change the default logic for fully sync

Remove VcsCommand::FullySynchronous flag.
Rename VcsCommand::NoFullySync into UseEventLoop.
By default the command will run fully synchronous
(i.e. without nested event loop). Only when
UseEventLoop is specified, and the command runs in
main thread, the nested event loop will be used.

This change should preserve the current behavior
on all code paths.

Change-Id: Id4bbaf68402ceed5e3fcc6f294521e87eb0b8d4d
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-10-05 11:14:41 +02:00
parent 3e69ea863f
commit f4233a1c22
5 changed files with 37 additions and 38 deletions

View File

@@ -103,9 +103,6 @@ const char CMD_ID_UPDATE_VIEW[] = "ClearCase.UpdateView";
const char CMD_ID_CHECKIN_ALL[] = "ClearCase.CheckInAll"; const char CMD_ID_CHECKIN_ALL[] = "ClearCase.CheckInAll";
const char CMD_ID_STATUS[] = "ClearCase.Status"; const char CMD_ID_STATUS[] = "ClearCase.Status";
const int s_silentRun = VcsCommand::NoOutput | VcsCommand::FullySynchronously;
const int s_verboseRun = VcsCommand::ShowStdOut | VcsCommand::FullySynchronously;
const VcsBaseEditorParameters logEditorParameters { const VcsBaseEditorParameters logEditorParameters {
LogOutput, LogOutput,
"ClearCase File Log Editor", // id "ClearCase File Log Editor", // id
@@ -381,8 +378,8 @@ QStringList ClearCasePluginPrivate::getVobList() const
{ {
QStringList args(QLatin1String("lsvob")); QStringList args(QLatin1String("lsvob"));
args << QLatin1String("-s"); args << QLatin1String("-s");
const CommandResult result = const CommandResult result = runCleartool(currentState().topLevel(), args, m_settings.timeOutS,
runCleartool(currentState().topLevel(), args, m_settings.timeOutS, s_silentRun); VcsCommand::NoOutput);
return result.cleanedStdOut().split(QLatin1Char('\n'), Qt::SkipEmptyParts); return result.cleanedStdOut().split(QLatin1Char('\n'), Qt::SkipEmptyParts);
} }
@@ -504,7 +501,8 @@ FileStatus::Status ClearCasePluginPrivate::getFileStatus(const QString &fileName
QString ClearCasePluginPrivate::ccManagesDirectory(const FilePath &directory) const QString ClearCasePluginPrivate::ccManagesDirectory(const FilePath &directory) const
{ {
QStringList args(QLatin1String("pwv")); QStringList args(QLatin1String("pwv"));
const CommandResult result = runCleartool(directory, args, m_settings.timeOutS, s_silentRun); const CommandResult result = runCleartool(directory, args, m_settings.timeOutS,
VcsCommand::NoOutput);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return {}; return {};
@@ -549,10 +547,9 @@ QString ClearCasePluginPrivate::ccViewRoot(const FilePath &directory) const
{ {
QStringList args(QLatin1String("pwv")); QStringList args(QLatin1String("pwv"));
args << QLatin1String("-root"); args << QLatin1String("-root");
const CommandResult result = runCleartool(directory, args, m_settings.timeOutS, s_silentRun); const CommandResult result = runCleartool(directory, args, m_settings.timeOutS,
VcsCommand::NoOutput);
QString root = result.cleanedStdOut().trimmed(); QString root = result.cleanedStdOut().trimmed();
if (root.isEmpty()) { if (root.isEmpty()) {
if (HostOsInfo::isWindowsHost()) if (HostOsInfo::isWindowsHost())
root = getDriveLetterOfPath(directory.toString()); root = getDriveLetterOfPath(directory.toString());
@@ -825,8 +822,8 @@ QString ClearCasePluginPrivate::ccGetPredecessor(const QString &version) const
{ {
QStringList args(QLatin1String("describe")); QStringList args(QLatin1String("describe"));
args << QLatin1String("-fmt") << QLatin1String("%En@@%PSn") << version; args << QLatin1String("-fmt") << QLatin1String("%En@@%PSn") << version;
const CommandResult result = const CommandResult result = runCleartool(currentState().topLevel(), args, m_settings.timeOutS,
runCleartool(currentState().topLevel(), args, m_settings.timeOutS, s_silentRun); VcsCommand::NoOutput);
if (result.result() != ProcessResult::FinishedWithSuccess if (result.result() != ProcessResult::FinishedWithSuccess
|| result.cleanedStdOut().endsWith(QLatin1Char('@'))) {// <name-unknown>@@ || result.cleanedStdOut().endsWith(QLatin1Char('@'))) {// <name-unknown>@@
return {}; return {};
@@ -841,8 +838,8 @@ QStringList ClearCasePluginPrivate::ccGetActiveVobs() const
QStringList args(QLatin1String("lsvob")); QStringList args(QLatin1String("lsvob"));
const QString theViewRoot = viewRoot(); const QString theViewRoot = viewRoot();
const CommandResult result = const CommandResult result = runCleartool(FilePath::fromString(theViewRoot), args,
runCleartool(FilePath::fromString(theViewRoot), args, m_settings.timeOutS, s_silentRun); m_settings.timeOutS, VcsCommand::NoOutput);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return {}; return {};
@@ -895,7 +892,7 @@ QString ClearCasePluginPrivate::ccGetFileActivity(const FilePath &workingDir, co
QStringList args(QLatin1String("lscheckout")); QStringList args(QLatin1String("lscheckout"));
args << QLatin1String("-fmt") << QLatin1String("%[activity]p"); args << QLatin1String("-fmt") << QLatin1String("%[activity]p");
args << file; args << file;
return runCleartool(workingDir, args, m_settings.timeOutS, s_silentRun).cleanedStdOut(); return runCleartool(workingDir, args, m_settings.timeOutS, VcsCommand::NoOutput).cleanedStdOut();
} }
ClearCaseSubmitEditor *ClearCasePluginPrivate::openClearCaseSubmitEditor(const FilePath &filePath, bool isUcm) ClearCaseSubmitEditor *ClearCasePluginPrivate::openClearCaseSubmitEditor(const FilePath &filePath, bool isUcm)
@@ -1110,7 +1107,8 @@ bool ClearCasePluginPrivate::vcsUndoCheckOut(const FilePath &workingDir, const Q
args << QLatin1String(keep ? "-keep" : "-rm"); args << QLatin1String(keep ? "-keep" : "-rm");
args << QDir::toNativeSeparators(fileName); args << QDir::toNativeSeparators(fileName);
const CommandResult result = runCleartool(workingDir, args, m_settings.timeOutS, s_verboseRun); const CommandResult result = runCleartool(workingDir, args, m_settings.timeOutS,
VcsCommand::ShowStdOut);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return false; return false;
@@ -1140,7 +1138,8 @@ bool ClearCasePluginPrivate::vcsUndoHijack(const FilePath &workingDir, const QSt
args << QLatin1String("/dev/null"); args << QLatin1String("/dev/null");
args << QDir::toNativeSeparators(fileName); args << QDir::toNativeSeparators(fileName);
const CommandResult result = runCleartool(workingDir, args, m_settings.timeOutS, s_verboseRun); const CommandResult result = runCleartool(workingDir, args, m_settings.timeOutS,
VcsCommand::ShowStdOut);
if (result.result() == ProcessResult::FinishedWithSuccess) if (result.result() == ProcessResult::FinishedWithSuccess)
return false; return false;
@@ -1248,7 +1247,8 @@ QStringList ClearCasePluginPrivate::ccGetActivityVersions(const FilePath &workin
{ {
QStringList args(QLatin1String("lsactivity")); QStringList args(QLatin1String("lsactivity"));
args << QLatin1String("-fmt") << QLatin1String("%[versions]Cp") << activity; args << QLatin1String("-fmt") << QLatin1String("%[versions]Cp") << activity;
const CommandResult result = runCleartool(workingDir, args, m_settings.timeOutS, s_silentRun); const CommandResult result = runCleartool(workingDir, args, m_settings.timeOutS,
VcsCommand::NoOutput);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return {}; return {};
QStringList versions = result.cleanedStdOut().split(QLatin1String(", ")); QStringList versions = result.cleanedStdOut().split(QLatin1String(", "));
@@ -1648,7 +1648,7 @@ void ClearCasePluginPrivate::commitFromEditor()
QString ClearCasePluginPrivate::runCleartoolSync(const FilePath &workingDir, QString ClearCasePluginPrivate::runCleartoolSync(const FilePath &workingDir,
const QStringList &arguments) const const QStringList &arguments) const
{ {
return runCleartool(workingDir, arguments, m_settings.timeOutS, s_silentRun).cleanedStdOut(); return runCleartool(workingDir, arguments, m_settings.timeOutS, VcsCommand::NoOutput).cleanedStdOut();
} }
CommandResult ClearCasePluginPrivate::runCleartool(const FilePath &workingDir, CommandResult ClearCasePluginPrivate::runCleartool(const FilePath &workingDir,
@@ -1781,7 +1781,7 @@ bool ClearCasePluginPrivate::vcsOpen(const FilePath &workingDir, const QString &
} }
args << file; args << file;
CommandResult result = runCleartool(topLevel, args, m_settings.timeOutS, CommandResult result = runCleartool(topLevel, args, m_settings.timeOutS,
s_verboseRun | VcsCommand::SuppressStdErr); VcsCommand::ShowStdOut | VcsCommand::SuppressStdErr);
if (result.result() != ProcessResult::FinishedWithSuccess) { if (result.result() != ProcessResult::FinishedWithSuccess) {
if (result.cleanedStdErr().contains(QLatin1String("Versions other than the selected version"))) { if (result.cleanedStdErr().contains(QLatin1String("Versions other than the selected version"))) {
VersionSelector selector(file, result.cleanedStdErr()); VersionSelector selector(file, result.cleanedStdErr());
@@ -1790,7 +1790,7 @@ bool ClearCasePluginPrivate::vcsOpen(const FilePath &workingDir, const QString &
ccUpdate(workingDir, QStringList(file)); ccUpdate(workingDir, QStringList(file));
else else
args.removeOne(QLatin1String("-query")); args.removeOne(QLatin1String("-query"));
result = runCleartool(topLevel, args, m_settings.timeOutS, s_verboseRun); result = runCleartool(topLevel, args, m_settings.timeOutS, VcsCommand::ShowStdOut);
} }
} else { } else {
VcsOutputWindow::append(result.cleanedStdOut()); VcsOutputWindow::append(result.cleanedStdOut());
@@ -1935,7 +1935,7 @@ bool ClearCasePluginPrivate::ccFileOp(const FilePath &workingDir, const QString
QStringList args; QStringList args;
args << QLatin1String("checkout") << commentArg << dirName; args << QLatin1String("checkout") << commentArg << dirName;
const CommandResult coResult = runCleartool(workingDir, args, m_settings.timeOutS, const CommandResult coResult = runCleartool(workingDir, args, m_settings.timeOutS,
s_verboseRun); VcsCommand::ShowStdOut);
if (coResult.result() != ProcessResult::FinishedWithSuccess) { if (coResult.result() != ProcessResult::FinishedWithSuccess) {
if (coResult.cleanedStdErr().contains(QLatin1String("already checked out"))) if (coResult.cleanedStdErr().contains(QLatin1String("already checked out")))
noCheckout = true; noCheckout = true;
@@ -1949,7 +1949,7 @@ bool ClearCasePluginPrivate::ccFileOp(const FilePath &workingDir, const QString
if (!file2.isEmpty()) if (!file2.isEmpty())
args << QDir::toNativeSeparators(file2); args << QDir::toNativeSeparators(file2);
const CommandResult opResult = runCleartool(workingDir, args, m_settings.timeOutS, const CommandResult opResult = runCleartool(workingDir, args, m_settings.timeOutS,
s_verboseRun); VcsCommand::ShowStdOut);
if (opResult.result() != ProcessResult::FinishedWithSuccess) { if (opResult.result() != ProcessResult::FinishedWithSuccess) {
// on failure - undo checkout for the directory // on failure - undo checkout for the directory
if (!noCheckout) if (!noCheckout)
@@ -1964,7 +1964,7 @@ bool ClearCasePluginPrivate::ccFileOp(const FilePath &workingDir, const QString
args.clear(); args.clear();
args << QLatin1String("checkin") << commentArg << dirName; args << QLatin1String("checkin") << commentArg << dirName;
const CommandResult ciResult = runCleartool(workingDir, args, m_settings.timeOutS, const CommandResult ciResult = runCleartool(workingDir, args, m_settings.timeOutS,
s_verboseRun); VcsCommand::ShowStdOut);
return ciResult.result() == ProcessResult::FinishedWithSuccess; return ciResult.result() == ProcessResult::FinishedWithSuccess;
} }
@@ -2244,7 +2244,8 @@ QString ClearCasePluginPrivate::getFile(const QString &nativeFile, const QString
} }
QStringList args(QLatin1String("get")); QStringList args(QLatin1String("get"));
args << QLatin1String("-to") << tempFile << nativeFile; args << QLatin1String("-to") << tempFile << nativeFile;
const CommandResult result = runCleartool(m_topLevel, args, m_settings.timeOutS, s_silentRun); const CommandResult result = runCleartool(m_topLevel, args, m_settings.timeOutS,
VcsCommand::NoOutput);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return {}; return {};
QFile::setPermissions(tempFile, QFile::ReadOwner | QFile::ReadUser | QFile::setPermissions(tempFile, QFile::ReadOwner | QFile::ReadUser |

View File

@@ -2967,7 +2967,7 @@ bool GitClient::addAndCommit(const FilePath &repositoryDirectory,
} }
const CommandResult result = vcsSynchronousExec(repositoryDirectory, arguments, const CommandResult result = vcsSynchronousExec(repositoryDirectory, arguments,
VcsCommand::NoFullySync); VcsCommand::UseEventLoop);
if (result.result() == ProcessResult::FinishedWithSuccess) { if (result.result() == ProcessResult::FinishedWithSuccess) {
VcsOutputWindow::appendMessage(msgCommitted(amendSHA1, commitCount)); VcsOutputWindow::appendMessage(msgCommitted(amendSHA1, commitCount));
GitPlugin::updateCurrentBranch(); GitPlugin::updateCurrentBranch();

View File

@@ -69,7 +69,7 @@ bool SubversionClient::doCommit(const FilePath &repositoryRoot,
<< commitMessageFile << commitMessageFile
<< escapeFiles(files); << escapeFiles(files);
const CommandResult result = vcsSynchronousExec(repositoryRoot, args, const CommandResult result = vcsSynchronousExec(repositoryRoot, args,
VcsCommand::ShowStdOut | VcsCommand::NoFullySync); VcsCommand::ShowStdOut | VcsCommand::UseEventLoop);
return result.result() == ProcessResult::FinishedWithSuccess; return result.result() == ProcessResult::FinishedWithSuccess;
} }

View File

@@ -86,7 +86,7 @@ public:
void cleanup(); void cleanup();
void setupProcess(QtcProcess *process, const Job &job); void setupProcess(QtcProcess *process, const Job &job);
void installStdCallbacks(QtcProcess *process); void installStdCallbacks(QtcProcess *process);
bool isFullySynchronous() const; EventLoopMode eventLoopMode() const;
void handleDone(QtcProcess *process); void handleDone(QtcProcess *process);
void startAll(); void startAll();
void startNextJob(); void startNextJob();
@@ -214,10 +214,11 @@ void VcsCommandPrivate::installStdCallbacks(QtcProcess *process)
// m_process->setTimeOutMessageBoxEnabled(true); // m_process->setTimeOutMessageBoxEnabled(true);
} }
bool VcsCommandPrivate::isFullySynchronous() const EventLoopMode VcsCommandPrivate::eventLoopMode() const
{ {
return (m_flags & VcsCommand::FullySynchronously) || (!(m_flags & VcsCommand::NoFullySync) if ((m_flags & VcsCommand::UseEventLoop) && QThread::currentThread() == qApp->thread())
&& QThread::currentThread() == QCoreApplication::instance()->thread()); return EventLoopMode::On;
return EventLoopMode::Off;
} }
void VcsCommandPrivate::handleDone(QtcProcess *process) void VcsCommandPrivate::handleDone(QtcProcess *process)
@@ -392,9 +393,8 @@ CommandResult VcsCommand::runCommand(const CommandLine &command, int timeoutS)
d->setupProcess(&process, {command, timeoutS, d->m_defaultWorkingDirectory, {}}); d->setupProcess(&process, {command, timeoutS, d->m_defaultWorkingDirectory, {}});
EventLoopMode eventLoopMode = EventLoopMode::Off; const EventLoopMode eventLoopMode = d->eventLoopMode();
if (!d->isFullySynchronous()) { if (eventLoopMode == EventLoopMode::On) {
eventLoopMode = EventLoopMode::On;
connect(this, &VcsCommand::terminate, &process, [&process] { connect(this, &VcsCommand::terminate, &process, [&process] {
process.stop(); process.stop();
process.waitForFinished(); process.waitForFinished();

View File

@@ -90,11 +90,9 @@ public:
SuppressCommandLogging = 0x10, // No command log entry. SuppressCommandLogging = 0x10, // No command log entry.
ShowSuccessMessage = 0x20, // Show message about successful completion of command. ShowSuccessMessage = 0x20, // Show message about successful completion of command.
ForceCLocale = 0x40, // Force C-locale for commands whose output is parsed. ForceCLocale = 0x40, // Force C-locale for commands whose output is parsed.
FullySynchronously = 0x80, // Suppress local event loop (in case UI actions are SilentOutput = 0x80, // Suppress user notifications about the output happening.
// triggered by file watchers). UseEventLoop = 0x100, // Use event loop when executed in UI thread.
SilentOutput = 0x100, // Suppress user notifications about the output happening. ExpectRepoChanges = 0x200, // Expect changes in repository by the command
NoFullySync = 0x200, // Avoid fully synchronous execution even in UI thread.
ExpectRepoChanges = 0x400, // Expect changes in repository by the command
NoOutput = SuppressStdErr | SuppressFailMessage | SuppressCommandLogging NoOutput = SuppressStdErr | SuppressFailMessage | SuppressCommandLogging
}; };