From b8fe25db258da13a2f7a4e44fcf8845a512af6bf Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 30 Jan 2020 12:31:47 +0100 Subject: Vcs: Merge IVersionControl and VcsBasePlugin hierarchies They were 1:1 in parallel, with quite a bit of function call ping-pong inbetween, for code-sharing-by-inheritance. Merge them by making VcsBasePlugin inherit IVersionControl and merge the derived classes below. Size of this patch is hard to avoid as all seven systems have to move simultaneously. Non-necessary potential follow-up cleanup have been left out on purpose. Change-Id: Icb71e4182af3db21069cc637e7ae87ffa3829791 Reviewed-by: Orgad Shaneh --- src/plugins/mercurial/CMakeLists.txt | 1 - src/plugins/mercurial/mercurial.pro | 2 - src/plugins/mercurial/mercurial.qbs | 2 - src/plugins/mercurial/mercurialcontrol.cpp | 206 ----------------------------- src/plugins/mercurial/mercurialcontrol.h | 80 ----------- src/plugins/mercurial/mercurialplugin.cpp | 196 ++++++++++++++++++++++++++- 6 files changed, 189 insertions(+), 298 deletions(-) delete mode 100644 src/plugins/mercurial/mercurialcontrol.cpp delete mode 100644 src/plugins/mercurial/mercurialcontrol.h (limited to 'src/plugins/mercurial') diff --git a/src/plugins/mercurial/CMakeLists.txt b/src/plugins/mercurial/CMakeLists.txt index c0ea4343f2d..e81b3e3eaf2 100644 --- a/src/plugins/mercurial/CMakeLists.txt +++ b/src/plugins/mercurial/CMakeLists.txt @@ -8,7 +8,6 @@ add_qtc_plugin(Mercurial mercurialclient.cpp mercurialclient.h mercurialcommitpanel.ui mercurialcommitwidget.cpp mercurialcommitwidget.h - mercurialcontrol.cpp mercurialcontrol.h mercurialeditor.cpp mercurialeditor.h mercurialplugin.cpp mercurialplugin.h mercurialsettings.cpp mercurialsettings.h diff --git a/src/plugins/mercurial/mercurial.pro b/src/plugins/mercurial/mercurial.pro index 69f250bd2db..9057e0fcc03 100644 --- a/src/plugins/mercurial/mercurial.pro +++ b/src/plugins/mercurial/mercurial.pro @@ -1,7 +1,6 @@ include(../../qtcreatorplugin.pri) SOURCES += mercurialplugin.cpp \ optionspage.cpp \ - mercurialcontrol.cpp \ mercurialclient.cpp \ annotationhighlighter.cpp \ mercurialeditor.cpp \ @@ -14,7 +13,6 @@ SOURCES += mercurialplugin.cpp \ HEADERS += mercurialplugin.h \ constants.h \ optionspage.h \ - mercurialcontrol.h \ mercurialclient.h \ annotationhighlighter.h \ mercurialeditor.h \ diff --git a/src/plugins/mercurial/mercurial.qbs b/src/plugins/mercurial/mercurial.qbs index 22f006eb3fd..43a3c68598e 100644 --- a/src/plugins/mercurial/mercurial.qbs +++ b/src/plugins/mercurial/mercurial.qbs @@ -25,8 +25,6 @@ QtcPlugin { "mercurialcommitpanel.ui", "mercurialcommitwidget.cpp", "mercurialcommitwidget.h", - "mercurialcontrol.cpp", - "mercurialcontrol.h", "mercurialeditor.cpp", "mercurialeditor.h", "mercurialplugin.cpp", diff --git a/src/plugins/mercurial/mercurialcontrol.cpp b/src/plugins/mercurial/mercurialcontrol.cpp deleted file mode 100644 index 7935813abe7..00000000000 --- a/src/plugins/mercurial/mercurialcontrol.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Brian McGillion -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "mercurialcontrol.h" -#include "mercurialclient.h" - -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include - -namespace Mercurial { -namespace Internal { - -class MercurialTopicCache : public Core::IVersionControl::TopicCache -{ -public: - MercurialTopicCache(MercurialClient *client) : m_client(client) {} - -protected: - QString trackFile(const QString &repository) override - { - return repository + QLatin1String("/.hg/branch"); - } - - QString refreshTopic(const QString &repository) override - { - return m_client->branchQuerySync(repository); - } - -private: - MercurialClient *m_client; -}; - -MercurialControl::MercurialControl(MercurialClient *client) : - mercurialClient(client) -{ - setTopicCache(new MercurialTopicCache(client)); -} - -QString MercurialControl::displayName() const -{ - return tr("Mercurial"); -} - -Core::Id MercurialControl::id() const -{ - return {VcsBase::Constants::VCS_ID_MERCURIAL}; -} - -bool MercurialControl::isVcsFileOrDirectory(const Utils::FilePath &fileName) const -{ - return mercurialClient->isVcsDirectory(fileName); -} - -bool MercurialControl::managesDirectory(const QString &directory, QString *topLevel) const -{ - QFileInfo dir(directory); - const QString topLevelFound = mercurialClient->findTopLevelForFile(dir); - if (topLevel) - *topLevel = topLevelFound; - return !topLevelFound.isEmpty(); -} - -bool MercurialControl::managesFile(const QString &workingDirectory, const QString &fileName) const -{ - return mercurialClient->managesFile(workingDirectory, fileName); -} - -bool MercurialControl::isConfigured() const -{ - const Utils::FilePath binary = mercurialClient->vcsBinary(); - if (binary.isEmpty()) - return false; - QFileInfo fi = binary.toFileInfo(); - return fi.exists() && fi.isFile() && fi.isExecutable(); -} - -bool MercurialControl::supportsOperation(Operation operation) const -{ - bool supported = isConfigured(); - switch (operation) { - case Core::IVersionControl::AddOperation: - case Core::IVersionControl::DeleteOperation: - case Core::IVersionControl::MoveOperation: - case Core::IVersionControl::CreateRepositoryOperation: - case Core::IVersionControl::AnnotateOperation: - case Core::IVersionControl::InitialCheckoutOperation: - break; - case Core::IVersionControl::SnapshotOperations: - supported = false; - break; - } - return supported; -} - -bool MercurialControl::vcsOpen(const QString &filename) -{ - Q_UNUSED(filename) - return true; -} - -bool MercurialControl::vcsAdd(const QString &filename) -{ - const QFileInfo fi(filename); - return mercurialClient->synchronousAdd(fi.absolutePath(), fi.fileName()); -} - -bool MercurialControl::vcsDelete(const QString &filename) -{ - const QFileInfo fi(filename); - return mercurialClient->synchronousRemove(fi.absolutePath(), fi.fileName()); -} - -bool MercurialControl::vcsMove(const QString &from, const QString &to) -{ - const QFileInfo fromInfo(from); - const QFileInfo toInfo(to); - return mercurialClient->synchronousMove(fromInfo.absolutePath(), - fromInfo.absoluteFilePath(), - toInfo.absoluteFilePath()); -} - -bool MercurialControl::vcsCreateRepository(const QString &directory) -{ - return mercurialClient->synchronousCreateRepository(directory); -} - -bool MercurialControl::vcsAnnotate(const QString &file, int line) -{ - const QFileInfo fi(file); - mercurialClient->annotate(fi.absolutePath(), fi.fileName(), QString(), line); - return true; -} - -Core::ShellCommand *MercurialControl::createInitialCheckoutCommand(const QString &url, - const Utils::FilePath &baseDirectory, - const QString &localName, - const QStringList &extraArgs) -{ - QStringList args; - args << QLatin1String("clone") << extraArgs << url << localName; - auto command = new VcsBase::VcsCommand(baseDirectory.toString(), - mercurialClient->processEnvironment()); - command->addJob({mercurialClient->vcsBinary(), args}, -1); - return command; -} - -bool MercurialControl::sccManaged(const QString &filename) -{ - const QFileInfo fi(filename); - QString topLevel; - const bool managed = managesDirectory(fi.absolutePath(), &topLevel); - if (!managed || topLevel.isEmpty()) - return false; - const QDir topLevelDir(topLevel); - return mercurialClient->manifestSync(topLevel, topLevelDir.relativeFilePath(filename)); -} - -void MercurialControl::changed(const QVariant &v) -{ - switch (v.type()) { - case QVariant::String: - emit repositoryChanged(v.toString()); - break; - case QVariant::StringList: - emit filesChanged(v.toStringList()); - break; - default: - break; - } -} - -} // namespace Internal -} // namespace Mercurial diff --git a/src/plugins/mercurial/mercurialcontrol.h b/src/plugins/mercurial/mercurialcontrol.h deleted file mode 100644 index 4d96a32a9ad..00000000000 --- a/src/plugins/mercurial/mercurialcontrol.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Brian McGillion -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include - -QT_BEGIN_NAMESPACE -class QVariant; -QT_END_NAMESPACE - -namespace Mercurial { -namespace Internal { - -class MercurialClient; - -// Implements just the basics of the Version Control Interface -// MercurialClient handles all the work. -class MercurialControl : public Core::IVersionControl -{ - Q_OBJECT - -public: - explicit MercurialControl(MercurialClient *mercurialClient); - - QString displayName() const final; - Core::Id id() const final; - bool isVcsFileOrDirectory(const Utils::FilePath &fileName) const final; - - bool managesDirectory(const QString &filename, QString *topLevel = nullptr) const final; - bool managesFile(const QString &workingDirectory, const QString &fileName) const final; - bool isConfigured() const final; - bool supportsOperation(Operation operation) const final; - bool vcsOpen(const QString &fileName) final; - bool vcsAdd(const QString &filename) final; - bool vcsDelete(const QString &filename) final; - bool vcsMove(const QString &from, const QString &to) final; - bool vcsCreateRepository(const QString &directory) final; - bool vcsAnnotate(const QString &file, int line) final; - - Core::ShellCommand *createInitialCheckoutCommand(const QString &url, - const Utils::FilePath &baseDirectory, - const QString &localName, - const QStringList &extraArgs) final; - - bool sccManaged(const QString &filename); - - // To be connected to the HgTask's success signal to emit the repository/ - // files changed signals according to the variant's type: - // String -> repository, StringList -> files - void changed(const QVariant&); - -private: - MercurialClient *const mercurialClient; -}; - -} // namespace Internal -} // namespace Mercurial diff --git a/src/plugins/mercurial/mercurialplugin.cpp b/src/plugins/mercurial/mercurialplugin.cpp index ca7bd78a0be..693cedc8210 100644 --- a/src/plugins/mercurial/mercurialplugin.cpp +++ b/src/plugins/mercurial/mercurialplugin.cpp @@ -27,7 +27,6 @@ #include "optionspage.h" #include "constants.h" #include "mercurialclient.h" -#include "mercurialcontrol.h" #include "mercurialeditor.h" #include "revertdialog.h" #include "srcdestdialog.h" @@ -55,6 +54,7 @@ #include #include #include +#include #include #include @@ -75,6 +75,26 @@ using namespace Utils; namespace Mercurial { namespace Internal { +class MercurialTopicCache : public Core::IVersionControl::TopicCache +{ +public: + MercurialTopicCache(MercurialClient *client) : m_client(client) {} + +protected: + QString trackFile(const QString &repository) override + { + return repository + QLatin1String("/.hg/branch"); + } + + QString refreshTopic(const QString &repository) override + { + return m_client->branchQuerySync(repository); + } + +private: + MercurialClient *m_client; +}; + static const VcsBaseEditorParameters editorParameters[] = { { LogOutput, @@ -107,6 +127,34 @@ class MercurialPluginPrivate final : public VcsBase::VcsBasePluginPrivate public: MercurialPluginPrivate(); + // IVersionControl + QString displayName() const final; + Core::Id id() const final; + bool isVcsFileOrDirectory(const Utils::FilePath &fileName) const final; + + bool managesDirectory(const QString &filename, QString *topLevel = nullptr) const final; + bool managesFile(const QString &workingDirectory, const QString &fileName) const final; + bool isConfigured() const final; + bool supportsOperation(Operation operation) const final; + bool vcsOpen(const QString &fileName) final; + bool vcsAdd(const QString &filename) final; + bool vcsDelete(const QString &filename) final; + bool vcsMove(const QString &from, const QString &to) final; + bool vcsCreateRepository(const QString &directory) final; + bool vcsAnnotate(const QString &file, int line) final; + + Core::ShellCommand *createInitialCheckoutCommand(const QString &url, + const Utils::FilePath &baseDirectory, + const QString &localName, + const QStringList &extraArgs) final; + + bool sccManaged(const QString &filename); + + // To be connected to the HgTask's success signal to emit the repository/ + // files changed signals according to the variant's type: + // String -> repository, StringList -> files + void changed(const QVariant&); + private: void updateActions(VcsBase::VcsBasePluginPrivate::ActionState) final; bool submitEditorAboutToClose() final; @@ -145,9 +193,8 @@ private: // Variables MercurialSettings m_settings; MercurialClient m_client{&m_settings}; - MercurialControl m_control{&m_client}; - OptionsPage m_optionsPage{[this] { m_control.configurationChanged(); }, &m_settings}; + OptionsPage m_optionsPage{[this] { configurationChanged(); }, &m_settings}; Core::CommandLocator *m_commandLocator = nullptr; Core::ActionContainer *m_mercurialContainer = nullptr; @@ -191,13 +238,15 @@ void MercurialPlugin::extensionsInitialized() } MercurialPluginPrivate::MercurialPluginPrivate() + : VcsBase::VcsBasePluginPrivate(Core::Context(Constants::MERCURIAL_CONTEXT)) { dd = this; - Core::Context context(Constants::MERCURIAL_CONTEXT); - initializeVcs(&m_control, context); + setTopicCache(new MercurialTopicCache(&m_client)); - connect(&m_client, &VcsBaseClient::changed, &m_control, &MercurialControl::changed); + Core::Context context(Constants::MERCURIAL_CONTEXT); + + connect(&m_client, &VcsBaseClient::changed, this, &MercurialPluginPrivate::changed); connect(&m_client, &MercurialClient::needUpdate, this, &MercurialPluginPrivate::update); const auto describeFunc = [this](const QString &source, const QString &id) { @@ -593,7 +642,7 @@ void MercurialPluginPrivate::showCommitWidget(const QListdocument()->setPreferredDisplayName(msg); - QString branch = m_control.vcsTopic(m_submitRepository); + const QString branch = vcsTopic(m_submitRepository); commitEditor->setFields(m_submitRepository, branch, m_settings.stringValue(MercurialSettings::userNameKey), m_settings.stringValue(MercurialSettings::userEmailKey), status); @@ -669,6 +718,139 @@ void MercurialPluginPrivate::updateActions(VcsBasePluginPrivate::ActionState as) repoAction->setEnabled(repoEnabled); } +QString MercurialPluginPrivate::displayName() const +{ + return tr("Mercurial"); +} + +Core::Id MercurialPluginPrivate::id() const +{ + return {VcsBase::Constants::VCS_ID_MERCURIAL}; +} + +bool MercurialPluginPrivate::isVcsFileOrDirectory(const Utils::FilePath &fileName) const +{ + return m_client.isVcsDirectory(fileName); +} + +bool MercurialPluginPrivate::managesDirectory(const QString &directory, QString *topLevel) const +{ + QFileInfo dir(directory); + const QString topLevelFound = m_client.findTopLevelForFile(dir); + if (topLevel) + *topLevel = topLevelFound; + return !topLevelFound.isEmpty(); +} + +bool MercurialPluginPrivate::managesFile(const QString &workingDirectory, const QString &fileName) const +{ + return m_client.managesFile(workingDirectory, fileName); +} + +bool MercurialPluginPrivate::isConfigured() const +{ + const Utils::FilePath binary = m_client.vcsBinary(); + if (binary.isEmpty()) + return false; + QFileInfo fi = binary.toFileInfo(); + return fi.exists() && fi.isFile() && fi.isExecutable(); +} + +bool MercurialPluginPrivate::supportsOperation(Operation operation) const +{ + bool supported = isConfigured(); + switch (operation) { + case Core::IVersionControl::AddOperation: + case Core::IVersionControl::DeleteOperation: + case Core::IVersionControl::MoveOperation: + case Core::IVersionControl::CreateRepositoryOperation: + case Core::IVersionControl::AnnotateOperation: + case Core::IVersionControl::InitialCheckoutOperation: + break; + case Core::IVersionControl::SnapshotOperations: + supported = false; + break; + } + return supported; +} + +bool MercurialPluginPrivate::vcsOpen(const QString &filename) +{ + Q_UNUSED(filename) + return true; +} + +bool MercurialPluginPrivate::vcsAdd(const QString &filename) +{ + const QFileInfo fi(filename); + return m_client.synchronousAdd(fi.absolutePath(), fi.fileName()); +} + +bool MercurialPluginPrivate::vcsDelete(const QString &filename) +{ + const QFileInfo fi(filename); + return m_client.synchronousRemove(fi.absolutePath(), fi.fileName()); +} + +bool MercurialPluginPrivate::vcsMove(const QString &from, const QString &to) +{ + const QFileInfo fromInfo(from); + const QFileInfo toInfo(to); + return m_client.synchronousMove(fromInfo.absolutePath(), + fromInfo.absoluteFilePath(), + toInfo.absoluteFilePath()); +} + +bool MercurialPluginPrivate::vcsCreateRepository(const QString &directory) +{ + return m_client.synchronousCreateRepository(directory); +} + +bool MercurialPluginPrivate::vcsAnnotate(const QString &file, int line) +{ + const QFileInfo fi(file); + m_client.annotate(fi.absolutePath(), fi.fileName(), QString(), line); + return true; +} + +Core::ShellCommand *MercurialPluginPrivate::createInitialCheckoutCommand(const QString &url, + const Utils::FilePath &baseDirectory, + const QString &localName, + const QStringList &extraArgs) +{ + QStringList args; + args << QLatin1String("clone") << extraArgs << url << localName; + auto command = new VcsBase::VcsCommand(baseDirectory.toString(), + m_client.processEnvironment()); + command->addJob({m_client.vcsBinary(), args}, -1); + return command; +} + +bool MercurialPluginPrivate::sccManaged(const QString &filename) +{ + const QFileInfo fi(filename); + QString topLevel; + const bool managed = managesDirectory(fi.absolutePath(), &topLevel); + if (!managed || topLevel.isEmpty()) + return false; + const QDir topLevelDir(topLevel); + return m_client.manifestSync(topLevel, topLevelDir.relativeFilePath(filename)); +} + +void MercurialPluginPrivate::changed(const QVariant &v) +{ + switch (v.type()) { + case QVariant::String: + emit repositoryChanged(v.toString()); + break; + case QVariant::StringList: + emit filesChanged(v.toStringList()); + break; + default: + break; + } +} + #ifdef WITH_TESTS void MercurialPlugin::testDiffFileResolving_data() -- cgit v1.2.3