diff --git a/src/plugins/clearcase/clearcaseplugin.cpp b/src/plugins/clearcase/clearcaseplugin.cpp index 5a8f5d72aad..583f5dafb35 100644 --- a/src/plugins/clearcase/clearcaseplugin.cpp +++ b/src/plugins/clearcase/clearcaseplugin.cpp @@ -1670,7 +1670,7 @@ ClearCasePluginPrivate::runCleartool(const FilePath &workingDir, command->addFlags(flags); command->setCodec(outputCodec); const CommandResult result = command->runCommand({FilePath::fromString(executable), arguments}, - workingDir, timeOutS); + timeOutS); delete command; response.error = result.result() != ProcessResult::FinishedWithSuccess; diff --git a/src/plugins/cvs/cvsplugin.cpp b/src/plugins/cvs/cvsplugin.cpp index a155af8a05b..bbf607e162e 100644 --- a/src/plugins/cvs/cvsplugin.cpp +++ b/src/plugins/cvs/cvsplugin.cpp @@ -1438,7 +1438,7 @@ CvsResponse CvsPluginPrivate::runCvs(const FilePath &workingDirectory, command->addFlags(flags); command->setCodec(outputCodec); const CommandResult result = command->runCommand({executable, m_settings.addOptions(arguments)}, - workingDirectory, timeOutS); + timeOutS); delete command; response.result = CvsResponse::OtherError; diff --git a/src/plugins/git/gitgrep.cpp b/src/plugins/git/gitgrep.cpp index 541fd4e132c..f8ff440dc62 100644 --- a/src/plugins/git/gitgrep.cpp +++ b/src/plugins/git/gitgrep.cpp @@ -201,7 +201,7 @@ public: QObject::connect(m_command.get(), &VcsCommand::stdOutText, [this, &fi](const QString &text) { read(fi, text); }); - const CommandResult result = m_command->runCommand({m_vcsBinary, arguments}, {}, 0); + const CommandResult result = m_command->runCommand({m_vcsBinary, arguments}, 0); switch (result.result()) { case ProcessResult::TerminatedAbnormally: case ProcessResult::StartFailed: diff --git a/src/plugins/mercurial/mercurialclient.cpp b/src/plugins/mercurial/mercurialclient.cpp index 83ef9572b69..768e566d6a8 100644 --- a/src/plugins/mercurial/mercurialclient.cpp +++ b/src/plugins/mercurial/mercurialclient.cpp @@ -175,7 +175,7 @@ bool MercurialClient::synchronousPull(const FilePath &workingDir, const QString VcsCommand *command = VcsBaseClient::createVcsCommand(workingDir, env); command->addFlags(flags); - const CommandResult result = command->runCommand({vcsBinary(), args}, workingDir, vcsTimeoutS()); + const CommandResult result = command->runCommand({vcsBinary(), args}, vcsTimeoutS()); delete command; parsePullOutput(result.cleanedStdOut().trimmed()); diff --git a/src/plugins/vcsbase/vcsbaseclient.cpp b/src/plugins/vcsbase/vcsbaseclient.cpp index aa65ffca3cb..f949de6daa6 100644 --- a/src/plugins/vcsbase/vcsbaseclient.cpp +++ b/src/plugins/vcsbase/vcsbaseclient.cpp @@ -170,7 +170,7 @@ CommandResult VcsBaseClientImpl::vcsFullySynchronousExec(const FilePath &working command.addFlags(flags); if (codec) command.setCodec(codec); - return command.runCommand(cmdLine, workingDir, timeoutS > 0 ? timeoutS : vcsTimeoutS()); + return command.runCommand(cmdLine, timeoutS > 0 ? timeoutS : vcsTimeoutS()); } void VcsBaseClientImpl::resetCachedVcsInfo(const FilePath &workingDir) @@ -214,7 +214,7 @@ CommandResult VcsBaseClientImpl::vcsSynchronousExec(const FilePath &workingDir, VcsCommand command(workingDir, env.isValid() ? env : Environment::systemEnvironment()); command.addFlags(flags); command.setCodec(outputCodec); - return command.runCommand({vcsBinary(), args}, workingDir, vcsTimeoutS()); + return command.runCommand({vcsBinary(), args}, vcsTimeoutS()); } int VcsBaseClientImpl::vcsTimeoutS() const diff --git a/src/plugins/vcsbase/vcscommand.cpp b/src/plugins/vcsbase/vcscommand.cpp index d1babf60823..af5fd5935ed 100644 --- a/src/plugins/vcsbase/vcscommand.cpp +++ b/src/plugins/vcsbase/vcscommand.cpp @@ -74,13 +74,10 @@ class VcsCommandPrivate { public: struct Job { - explicit Job(const FilePath &wd, const CommandLine &command, int t, - const ExitCodeInterpreter &interpreter); - - FilePath workingDirectory; CommandLine command; - ExitCodeInterpreter exitCodeInterpreter; - int timeoutS; + int timeoutS = 10; + FilePath workingDirectory; + ExitCodeInterpreter exitCodeInterpreter = {}; }; VcsCommandPrivate(const FilePath &defaultWorkingDirectory, const Environment &environment) @@ -119,18 +116,6 @@ public: bool m_aborted = false; }; -VcsCommandPrivate::Job::Job(const FilePath &wd, const CommandLine &command, - int t, const ExitCodeInterpreter &interpreter) : - workingDirectory(wd), - command(command), - exitCodeInterpreter(interpreter), - timeoutS(t) -{ - // Finished cookie is emitted via queued slot, needs metatype - static const int qvMetaId = qRegisterMetaType(); - Q_UNUSED(qvMetaId) -} - } // namespace Internal VcsCommand::VcsCommand(const FilePath &workingDirectory, const Environment &environment) : @@ -232,18 +217,18 @@ void VcsCommand::addFlags(unsigned f) } void VcsCommand::addJob(const CommandLine &command, - const FilePath &workingDirectory, - const ExitCodeInterpreter &interpreter) + const FilePath &workingDirectory, + const ExitCodeInterpreter &interpreter) { addJob(command, defaultTimeoutS(), workingDirectory, interpreter); } void VcsCommand::addJob(const CommandLine &command, int timeoutS, - const FilePath &workingDirectory, - const ExitCodeInterpreter &interpreter) + const FilePath &workingDirectory, + const ExitCodeInterpreter &interpreter) { - d->m_jobs.push_back(Internal::VcsCommandPrivate::Job(workDirectory(workingDirectory), command, - timeoutS, interpreter)); + d->m_jobs.push_back({command, timeoutS, !workingDirectory.isEmpty() + ? workingDirectory : d->m_defaultWorkingDirectory, interpreter}); } void VcsCommand::execute() @@ -275,13 +260,6 @@ int VcsCommand::timeoutS() const }); } -FilePath VcsCommand::workDirectory(const FilePath &wd) const -{ - if (!wd.isEmpty()) - return wd; - return defaultWorkingDirectory(); -} - void VcsCommand::run(QFutureInterface &future) { // Check that the binary path is not empty @@ -303,8 +281,8 @@ void VcsCommand::run(QFutureInterface &future) bool lastExecSuccess = true; for (int j = 0; j < count; j++) { const Internal::VcsCommandPrivate::Job &job = d->m_jobs.at(j); - const CommandResult result = runCommand(job.command, job.workingDirectory, - job.timeoutS, job.exitCodeInterpreter); + const CommandResult result = runCommand(job.command, job.timeoutS, + job.workingDirectory, job.exitCodeInterpreter); stdOut += result.cleanedStdOut(); stdErr += result.cleanedStdErr(); lastExecSuccess = result.result() == ProcessResult::FinishedWithSuccess; @@ -337,8 +315,14 @@ void VcsCommand::run(QFutureInterface &future) this->deleteLater(); } -CommandResult VcsCommand::runCommand(const CommandLine &command, const FilePath &workingDirectory, - int timeoutS, const ExitCodeInterpreter &interpreter) +CommandResult VcsCommand::runCommand(const Utils::CommandLine &command, int timeoutS) +{ + return runCommand(command, timeoutS, d->m_defaultWorkingDirectory, {}); +} + +CommandResult VcsCommand::runCommand(const CommandLine &command, int timeoutS, + const FilePath &workingDirectory, + const ExitCodeInterpreter &interpreter) { QtcProcess proc; if (command.executable().isEmpty()) @@ -347,12 +331,11 @@ CommandResult VcsCommand::runCommand(const CommandLine &command, const FilePath proc.setExitCodeInterpreter(interpreter); proc.setTimeoutS(timeoutS); - const FilePath dir = workDirectory(workingDirectory); - if (!dir.isEmpty()) - proc.setWorkingDirectory(dir); + if (!workingDirectory.isEmpty()) + proc.setWorkingDirectory(workingDirectory); if (!(d->m_flags & SuppressCommandLogging)) - emit appendCommand(dir, command); + emit appendCommand(workingDirectory, command); proc.setCommand(command); proc.setDisableUnixTerminal(); @@ -379,7 +362,7 @@ CommandResult VcsCommand::runCommand(const CommandLine &command, const FilePath emit appendError(proc.exitMessage()); } } - emit runCommandFinished(dir); + emit runCommandFinished(workingDirectory); return CommandResult(proc); } diff --git a/src/plugins/vcsbase/vcscommand.h b/src/plugins/vcsbase/vcscommand.h index da90a2149ab..00f25c676e1 100644 --- a/src/plugins/vcsbase/vcscommand.h +++ b/src/plugins/vcsbase/vcscommand.h @@ -148,9 +148,7 @@ public: // This is called once per job in a thread. // When called from the UI thread it will execute fully synchronously, so no signals will // be triggered! - CommandResult runCommand(const Utils::CommandLine &command, - const Utils::FilePath &workingDirectory = {}, - int timeoutS = 10, const Utils::ExitCodeInterpreter &interpreter = {}); + CommandResult runCommand(const Utils::CommandLine &command, int timeoutS = 10); void cancel(); signals: @@ -169,8 +167,13 @@ signals: void runCommandFinished(const Utils::FilePath &workingDirectory); private: - Utils::FilePath workDirectory(const Utils::FilePath &wd) const; void run(QFutureInterface &future); + // This is called once per job in a thread. + // When called from the UI thread it will execute fully synchronously, so no signals will + // be triggered! + CommandResult runCommand(const Utils::CommandLine &command, int timeoutS, + const Utils::FilePath &workingDirectory, + const Utils::ExitCodeInterpreter &interpreter); void addTask(const QFuture &future); void postRunCommand(const Utils::FilePath &workingDirectory);