diff options
author | hjk <hjk@qt.io> | 2024-02-07 12:16:47 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2024-02-07 11:42:39 +0000 |
commit | 87f1114d21b1b1583bbef9e96f0e5d9d97f9712e (patch) | |
tree | 8695d3190af18e92845c750cc9da3330d87e788d | |
parent | a6eb6dd9093390a3bc041a87e24659a1b7858b44 (diff) |
Mercurial: Use more direct access to the client singleton
Change-Id: I32711a893bc5d5d655cf92637defaaf149f3f108
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
-rw-r--r-- | src/plugins/mercurial/mercurialclient.cpp | 6 | ||||
-rw-r--r-- | src/plugins/mercurial/mercurialclient.h | 2 | ||||
-rw-r--r-- | src/plugins/mercurial/mercurialeditor.cpp | 9 | ||||
-rw-r--r-- | src/plugins/mercurial/mercurialeditor.h | 6 | ||||
-rw-r--r-- | src/plugins/mercurial/mercurialplugin.cpp | 93 |
5 files changed, 60 insertions, 56 deletions
diff --git a/src/plugins/mercurial/mercurialclient.cpp b/src/plugins/mercurial/mercurialclient.cpp index c4e6fc6db7f..81228964229 100644 --- a/src/plugins/mercurial/mercurialclient.cpp +++ b/src/plugins/mercurial/mercurialclient.cpp @@ -446,4 +446,10 @@ void MercurialClient::parsePullOutput(const QString &output) emit needMerge(); } +MercurialClient &mercurialClient() +{ + static MercurialClient theMercurialClient; + return theMercurialClient; +} + } // Mercurial::Internal diff --git a/src/plugins/mercurial/mercurialclient.h b/src/plugins/mercurial/mercurialclient.h index 75e096f6180..a00ea74e475 100644 --- a/src/plugins/mercurial/mercurialclient.h +++ b/src/plugins/mercurial/mercurialclient.h @@ -73,4 +73,6 @@ private: void parsePullOutput(const QString &output); }; +MercurialClient &mercurialClient(); + } // Mercurial::Internal diff --git a/src/plugins/mercurial/mercurialeditor.cpp b/src/plugins/mercurial/mercurialeditor.cpp index 1f95a4d1f7f..581e657d51f 100644 --- a/src/plugins/mercurial/mercurialeditor.cpp +++ b/src/plugins/mercurial/mercurialeditor.cpp @@ -21,11 +21,10 @@ using namespace Utils; namespace Mercurial::Internal { // use QRegularExpression::anchoredPattern() when minimum Qt is raised to 5.12+ -MercurialEditorWidget::MercurialEditorWidget(MercurialClient *client) : +MercurialEditorWidget::MercurialEditorWidget() : exactIdentifier12(QString("\\A(?:") + Constants::CHANGEIDEXACT12 + QString(")\\z")), exactIdentifier40(QString("\\A(?:") + Constants::CHANGEIDEXACT40 + QString(")\\z")), - changesetIdentifier40(Constants::CHANGESETID40), - m_client(client) + changesetIdentifier40(Constants::CHANGESETID40) { setDiffFilePattern(Constants::DIFFIDENTIFIER); setLogEntryPattern("^changeset:\\s+(\\S+)$"); @@ -57,7 +56,7 @@ QString MercurialEditorWidget::decorateVersion(const QString &revision) const { const FilePath workingDirectory = source().absolutePath(); // Format with short summary - return m_client->shortDescriptionSync(workingDirectory, revision); + return mercurialClient().shortDescriptionSync(workingDirectory, revision); } QStringList MercurialEditorWidget::annotationPreviousVersions(const QString &revision) const @@ -65,7 +64,7 @@ QStringList MercurialEditorWidget::annotationPreviousVersions(const QString &rev const FilePath filePath = source(); const FilePath workingDirectory = filePath.absolutePath(); // Retrieve parent revisions - return m_client->parentRevisionsSync(workingDirectory, filePath.fileName(), revision); + return mercurialClient().parentRevisionsSync(workingDirectory, filePath.fileName(), revision); } } // Mercurial::Internal diff --git a/src/plugins/mercurial/mercurialeditor.h b/src/plugins/mercurial/mercurialeditor.h index d5162697a27..da263b20d3d 100644 --- a/src/plugins/mercurial/mercurialeditor.h +++ b/src/plugins/mercurial/mercurialeditor.h @@ -9,12 +9,10 @@ namespace Mercurial::Internal { -class MercurialClient; - class MercurialEditorWidget : public VcsBase::VcsBaseEditorWidget { public: - explicit MercurialEditorWidget(MercurialClient *client); + MercurialEditorWidget(); private: QString changeUnderCursor(const QTextCursor &cursor) const override; @@ -25,8 +23,6 @@ private: const QRegularExpression exactIdentifier12; const QRegularExpression exactIdentifier40; const QRegularExpression changesetIdentifier40; - - MercurialClient *m_client; }; } // Mercurial::Internal diff --git a/src/plugins/mercurial/mercurialplugin.cpp b/src/plugins/mercurial/mercurialplugin.cpp index 9e5445a2391..081a7a5e41c 100644 --- a/src/plugins/mercurial/mercurialplugin.cpp +++ b/src/plugins/mercurial/mercurialplugin.cpp @@ -53,7 +53,7 @@ namespace Mercurial::Internal { class MercurialTopicCache : public Core::IVersionControl::TopicCache { public: - MercurialTopicCache(MercurialClient *client) : m_client(client) {} + MercurialTopicCache() = default; protected: FilePath trackFile(const FilePath &repository) override @@ -63,11 +63,8 @@ protected: QString refreshTopic(const FilePath &repository) override { - return m_client->branchQuerySync(repository.toString()); + return mercurialClient().branchQuerySync(repository.toString()); } - -private: - MercurialClient *m_client; }; const VcsBaseEditorParameters logEditorParameters { @@ -111,7 +108,10 @@ public: bool vcsMove(const FilePath &from, const FilePath &to) final; bool vcsCreateRepository(const FilePath &directory) final; void vcsAnnotate(const FilePath &filePath, int line) final; - void vcsDescribe(const FilePath &source, const QString &id) final { m_client.view(source, id); } + void vcsDescribe(const FilePath &source, const QString &id) final + { + mercurialClient().view(source, id); + } VcsCommand *createInitialCheckoutCommand(const QString &url, const Utils::FilePath &baseDirectory, @@ -160,8 +160,6 @@ private: void createRepositoryActions(const Core::Context &context); // Variables - MercurialClient m_client; - Core::CommandLocator *m_commandLocator = nullptr; Core::ActionContainer *m_mercurialContainer = nullptr; @@ -184,19 +182,19 @@ private: public: VcsEditorFactory logEditorFactory { &logEditorParameters, - [this] { return new MercurialEditorWidget(&m_client); }, + [this] { return new MercurialEditorWidget; }, std::bind(&MercurialPluginPrivate::vcsDescribe, this, _1, _2) }; VcsEditorFactory annotateEditorFactory { &annotateEditorParameters, - [this] { return new MercurialEditorWidget(&m_client); }, + [this] { return new MercurialEditorWidget; }, std::bind(&MercurialPluginPrivate::vcsDescribe, this, _1, _2) }; VcsEditorFactory diffEditorFactory { &diffEditorParameters, - [this] { return new MercurialEditorWidget(&m_client); }, + [this] { return new MercurialEditorWidget; }, std::bind(&MercurialPluginPrivate::vcsDescribe, this, _1, _2) }; }; @@ -216,12 +214,12 @@ MercurialPluginPrivate::MercurialPluginPrivate() [] { return new CommitEditor; } }); - setTopicCache(new MercurialTopicCache(&m_client)); + setTopicCache(new MercurialTopicCache); Core::Context context(Constants::MERCURIAL_CONTEXT); - connect(&m_client, &VcsBaseClient::changed, this, &MercurialPluginPrivate::changed); - connect(&m_client, &MercurialClient::needUpdate, this, &MercurialPluginPrivate::update); + connect(&mercurialClient(), &VcsBaseClient::changed, this, &MercurialPluginPrivate::changed); + connect(&mercurialClient(), &MercurialClient::needUpdate, this, &MercurialPluginPrivate::update); const QString prefix = QLatin1String("hg"); m_commandLocator = new Core::CommandLocator("Mercurial", prefix, prefix, this); @@ -315,7 +313,7 @@ void MercurialPluginPrivate::addCurrentFile() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); - m_client.synchronousAdd(state.currentFileTopLevel(), state.relativeCurrentFile()); + mercurialClient().synchronousAdd(state.currentFileTopLevel(), state.relativeCurrentFile()); } void MercurialPluginPrivate::annotateCurrentFile() @@ -325,21 +323,21 @@ void MercurialPluginPrivate::annotateCurrentFile() currentLine = editor->currentLine(); const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); - m_client.annotate(state.currentFileTopLevel(), state.relativeCurrentFile(), currentLine); + mercurialClient().annotate(state.currentFileTopLevel(), state.relativeCurrentFile(), currentLine); } void MercurialPluginPrivate::diffCurrentFile() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); - m_client.showDiffEditor(state.currentFileTopLevel(), {state.relativeCurrentFile()}); + mercurialClient().showDiffEditor(state.currentFileTopLevel(), {state.relativeCurrentFile()}); } void MercurialPluginPrivate::logCurrentFile() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); - m_client.log(state.currentFileTopLevel(), {state.relativeCurrentFile()}, {}, true); + mercurialClient().log(state.currentFileTopLevel(), {state.relativeCurrentFile()}, {}, true); } void MercurialPluginPrivate::revertCurrentFile() @@ -350,14 +348,14 @@ void MercurialPluginPrivate::revertCurrentFile() RevertDialog reverter(Core::ICore::dialogParent()); if (reverter.exec() != QDialog::Accepted) return; - m_client.revertFile(state.currentFileTopLevel(), state.relativeCurrentFile(), reverter.revision()); + mercurialClient().revertFile(state.currentFileTopLevel(), state.relativeCurrentFile(), reverter.revision()); } void MercurialPluginPrivate::statusCurrentFile() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); - m_client.status(state.currentFileTopLevel(), state.relativeCurrentFile()); + mercurialClient().status(state.currentFileTopLevel(), state.relativeCurrentFile()); } void MercurialPluginPrivate::createDirectoryActions(const Core::Context &context) @@ -395,14 +393,14 @@ void MercurialPluginPrivate::diffRepository() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); - m_client.showDiffEditor(state.topLevel()); + mercurialClient().showDiffEditor(state.topLevel()); } void MercurialPluginPrivate::logRepository() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); - m_client.log(state.topLevel()); + mercurialClient().log(state.topLevel()); } void MercurialPluginPrivate::revertMulti() @@ -413,7 +411,7 @@ void MercurialPluginPrivate::revertMulti() RevertDialog reverter(Core::ICore::dialogParent()); if (reverter.exec() != QDialog::Accepted) return; - m_client.revertAll(state.topLevel(), reverter.revision()); + mercurialClient().revertAll(state.topLevel(), reverter.revision()); } void MercurialPluginPrivate::statusMulti() @@ -421,7 +419,7 @@ void MercurialPluginPrivate::statusMulti() const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); - m_client.status(state.topLevel()); + mercurialClient().status(state.topLevel()); } void MercurialPluginPrivate::createRepositoryActions(const Core::Context &context) @@ -491,7 +489,7 @@ void MercurialPluginPrivate::pull() dialog.setWindowTitle(Tr::tr("Pull Source")); if (dialog.exec() != QDialog::Accepted) return; - m_client.synchronousPull(dialog.workingDir(), dialog.getRepositoryString()); + mercurialClient().synchronousPull(dialog.workingDir(), dialog.getRepositoryString()); } void MercurialPluginPrivate::push() @@ -503,7 +501,7 @@ void MercurialPluginPrivate::push() dialog.setWindowTitle(Tr::tr("Push Destination")); if (dialog.exec() != QDialog::Accepted) return; - m_client.synchronousPush(dialog.workingDir(), dialog.getRepositoryString()); + mercurialClient().synchronousPush(dialog.workingDir(), dialog.getRepositoryString()); } void MercurialPluginPrivate::update() @@ -515,7 +513,7 @@ void MercurialPluginPrivate::update() updateDialog.setWindowTitle(Tr::tr("Update")); if (updateDialog.exec() != QDialog::Accepted) return; - m_client.update(state.topLevel(), updateDialog.revision()); + mercurialClient().update(state.topLevel(), updateDialog.revision()); } void MercurialPluginPrivate::import() @@ -531,7 +529,7 @@ void MercurialPluginPrivate::import() return; const QStringList fileNames = importDialog.selectedFiles(); - m_client.import(state.topLevel(), fileNames); + mercurialClient().import(state.topLevel(), fileNames); } void MercurialPluginPrivate::incoming() @@ -543,14 +541,14 @@ void MercurialPluginPrivate::incoming() dialog.setWindowTitle(Tr::tr("Incoming Source")); if (dialog.exec() != QDialog::Accepted) return; - m_client.incoming(state.topLevel(), dialog.getRepositoryString()); + mercurialClient().incoming(state.topLevel(), dialog.getRepositoryString()); } void MercurialPluginPrivate::outgoing() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); - m_client.outgoing(state.topLevel()); + mercurialClient().outgoing(state.topLevel()); } void MercurialPluginPrivate::commit() @@ -566,14 +564,17 @@ void MercurialPluginPrivate::commit() m_submitRepository = state.topLevel(); - connect(&m_client, &MercurialClient::parsedStatus, this, &MercurialPluginPrivate::showCommitWidget); - m_client.emitParsedStatus(m_submitRepository); + connect(&mercurialClient(), &MercurialClient::parsedStatus, + this, &MercurialPluginPrivate::showCommitWidget); + + mercurialClient().emitParsedStatus(m_submitRepository); } void MercurialPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusItem> &status) { //Once we receive our data release the connection so it can be reused elsewhere - disconnect(&m_client, &MercurialClient::parsedStatus, this, &MercurialPluginPrivate::showCommitWidget); + disconnect(&mercurialClient(), &MercurialClient::parsedStatus, + this, &MercurialPluginPrivate::showCommitWidget); if (status.isEmpty()) { VcsOutputWindow::appendError(Tr::tr("There are no changes to commit.")); @@ -614,7 +615,7 @@ void MercurialPluginPrivate::showCommitWidget(const QList<VcsBaseClient::StatusI void MercurialPluginPrivate::diffFromEditorSelected(const QStringList &files) { - m_client.showDiffEditor(m_submitRepository, files); + mercurialClient().showDiffEditor(m_submitRepository, files); } bool MercurialPluginPrivate::activateCommit() @@ -633,8 +634,8 @@ bool MercurialPluginPrivate::activateCommit() QStringList extraOptions; if (!commitEditor->committerInfo().isEmpty()) extraOptions << QLatin1String("-u") << commitEditor->committerInfo(); - m_client.commit(m_submitRepository, files, editorFile->filePath().toString(), - extraOptions); + mercurialClient().commit(m_submitRepository, files, editorFile->filePath().toString(), + extraOptions); } return true; } @@ -673,12 +674,12 @@ Utils::Id MercurialPluginPrivate::id() const bool MercurialPluginPrivate::isVcsFileOrDirectory(const FilePath &filePath) const { - return m_client.isVcsDirectory(filePath); + return mercurialClient().isVcsDirectory(filePath); } bool MercurialPluginPrivate::managesDirectory(const FilePath &filePath, FilePath *topLevel) const { - const FilePath topLevelFound = m_client.findTopLevelForFile(filePath); + const FilePath topLevelFound = mercurialClient().findTopLevelForFile(filePath); if (topLevel) *topLevel = topLevelFound; return !topLevelFound.isEmpty(); @@ -686,7 +687,7 @@ bool MercurialPluginPrivate::managesDirectory(const FilePath &filePath, FilePath bool MercurialPluginPrivate::managesFile(const FilePath &workingDirectory, const QString &fileName) const { - return m_client.managesFile(workingDirectory, fileName); + return mercurialClient().managesFile(workingDirectory, fileName); } bool MercurialPluginPrivate::isConfigured() const @@ -724,31 +725,31 @@ bool MercurialPluginPrivate::vcsOpen(const FilePath &filePath) bool MercurialPluginPrivate::vcsAdd(const FilePath &filePath) { - return m_client.synchronousAdd(filePath.parentDir(), filePath.fileName()); + return mercurialClient().synchronousAdd(filePath.parentDir(), filePath.fileName()); } bool MercurialPluginPrivate::vcsDelete(const FilePath &filePath) { - return m_client.synchronousRemove(filePath.parentDir(), filePath.fileName()); + return mercurialClient().synchronousRemove(filePath.parentDir(), filePath.fileName()); } bool MercurialPluginPrivate::vcsMove(const FilePath &from, const FilePath &to) { const QFileInfo fromInfo = from.toFileInfo(); const QFileInfo toInfo = to.toFileInfo(); - return m_client.synchronousMove(from.parentDir(), + return mercurialClient().synchronousMove(from.parentDir(), fromInfo.absoluteFilePath(), toInfo.absoluteFilePath()); } bool MercurialPluginPrivate::vcsCreateRepository(const FilePath &directory) { - return m_client.synchronousCreateRepository(directory); + return mercurialClient().synchronousCreateRepository(directory); } void MercurialPluginPrivate::vcsAnnotate(const FilePath &filePath, int line) { - m_client.annotate(filePath.parentDir(), filePath.fileName(), line); + mercurialClient().annotate(filePath.parentDir(), filePath.fileName(), line); } VcsCommand *MercurialPluginPrivate::createInitialCheckoutCommand(const QString &url, @@ -758,7 +759,7 @@ VcsCommand *MercurialPluginPrivate::createInitialCheckoutCommand(const QString & { QStringList args; args << QLatin1String("clone") << extraArgs << url << localName; - auto command = VcsBaseClient::createVcsCommand(baseDirectory, m_client.processEnvironment()); + auto command = VcsBaseClient::createVcsCommand(baseDirectory, mercurialClient().processEnvironment()); command->addJob({settings().binaryPath(), args}, -1); return command; } @@ -771,7 +772,7 @@ bool MercurialPluginPrivate::sccManaged(const QString &filename) if (!managed || topLevel.isEmpty()) return false; const QDir topLevelDir(topLevel.toString()); - return m_client.manifestSync(topLevel, topLevelDir.relativeFilePath(filename)); + return mercurialClient().manifestSync(topLevel, topLevelDir.relativeFilePath(filename)); } void MercurialPluginPrivate::changed(const QVariant &v) |