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 <orgads@gmail.com>
This commit is contained in:
hjk
2020-01-30 12:31:47 +01:00
parent a35a2d6bf3
commit b8fe25db25
58 changed files with 1091 additions and 1902 deletions

View File

@@ -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 <vcsbase/vcsbaseeditor.h>
#include <vcsbase/vcsbaseconstants.h>
#include <vcsbase/vcsoutputwindow.h>
#include <vcsbase/vcscommand.h>
#include <QtPlugin>
#include <QAction>
@@ -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;
setTopicCache(new MercurialTopicCache(&m_client));
Core::Context context(Constants::MERCURIAL_CONTEXT);
initializeVcs(&m_control, context);
connect(&m_client, &VcsBaseClient::changed, &m_control, &MercurialControl::changed);
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 QList<VcsBaseClient::StatusI
arg(QDir::toNativeSeparators(m_submitRepository));
commitEditor->document()->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()