forked from qt-creator/qt-creator
VcsManager: Register IVersionControls with VcsManager
Get some more objects out of the pool. Change-Id: Id93021b712307c4777dc39b9d15aa18a46318885 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -154,8 +154,7 @@ bool BazaarPlugin::initialize(const QStringList &arguments, QString *errorMessag
|
||||
Context context(Constants::BAZAAR_CONTEXT);
|
||||
|
||||
m_client = new BazaarClient;
|
||||
auto vcsCtrl = new BazaarControl(m_client);
|
||||
initializeVcs(vcsCtrl, context);
|
||||
auto vcsCtrl = initializeVcs<BazaarControl>(context, m_client);
|
||||
connect(m_client, &VcsBaseClient::changed, vcsCtrl, &BazaarControl::changed);
|
||||
|
||||
addAutoReleasedObject(new OptionsPage(vcsCtrl));
|
||||
|
@@ -410,7 +410,7 @@ bool ClearCasePlugin::initialize(const QStringList & /*arguments */, QString *er
|
||||
|
||||
Context context(CLEARCASE_CONTEXT);
|
||||
|
||||
initializeVcs(new ClearCaseControl(this), context);
|
||||
initializeVcs<ClearCaseControl>(context, this);
|
||||
|
||||
m_clearcasePluginInstance = this;
|
||||
connect(ICore::instance(), &ICore::coreAboutToClose, this, &ClearCasePlugin::closing);
|
||||
|
@@ -50,8 +50,6 @@
|
||||
|
||||
namespace Core {
|
||||
|
||||
typedef QList<IVersionControl *> VersionControlList;
|
||||
|
||||
#if defined(WITH_TESTS)
|
||||
const char TEST_PREFIX[] = "/8E3A9BA0-0B97-40DF-AEC1-2BDF9FC9EDBE/";
|
||||
#endif
|
||||
@@ -158,6 +156,12 @@ VcsManager::~VcsManager()
|
||||
delete d;
|
||||
}
|
||||
|
||||
void VcsManager::addVersionControl(IVersionControl *vc)
|
||||
{
|
||||
QTC_ASSERT(!d->m_versionControlList.contains(vc), return);
|
||||
d->m_versionControlList.append(vc);
|
||||
}
|
||||
|
||||
VcsManager *VcsManager::instance()
|
||||
{
|
||||
return m_instance;
|
||||
@@ -176,9 +180,9 @@ void VcsManager::extensionsInitialized()
|
||||
}
|
||||
}
|
||||
|
||||
QList<IVersionControl *> VcsManager::versionControls()
|
||||
const QList<IVersionControl *> VcsManager::versionControls()
|
||||
{
|
||||
return ExtensionSystem::PluginManager::getObjects<IVersionControl>();
|
||||
return d->m_versionControlList;
|
||||
}
|
||||
|
||||
IVersionControl *VcsManager::versionControl(Id id)
|
||||
@@ -460,31 +464,6 @@ const char ID_VCS_B[] = "B";
|
||||
|
||||
typedef QHash<QString, QString> FileHash;
|
||||
|
||||
template<class T>
|
||||
class ObjectPoolGuard
|
||||
{
|
||||
public:
|
||||
ObjectPoolGuard(T *watch) : m_watched(watch)
|
||||
{
|
||||
ExtensionSystem::PluginManager::addObject(watch);
|
||||
}
|
||||
|
||||
explicit operator bool() { return m_watched; }
|
||||
bool operator !() { return !m_watched; }
|
||||
T &operator*() { return *m_watched; }
|
||||
T *operator->() { return m_watched; }
|
||||
T *value() { return m_watched; }
|
||||
|
||||
~ObjectPoolGuard()
|
||||
{
|
||||
ExtensionSystem::PluginManager::removeObject(m_watched);
|
||||
delete m_watched;
|
||||
}
|
||||
|
||||
private:
|
||||
T *m_watched;
|
||||
};
|
||||
|
||||
static FileHash makeHash(const QStringList &list)
|
||||
{
|
||||
FileHash result;
|
||||
@@ -559,8 +538,11 @@ void CorePlugin::testVcsManager_data()
|
||||
void CorePlugin::testVcsManager()
|
||||
{
|
||||
// setup:
|
||||
ObjectPoolGuard<TestVersionControl> vcsA(new TestVersionControl(ID_VCS_A, QLatin1String("A")));
|
||||
ObjectPoolGuard<TestVersionControl> vcsB(new TestVersionControl(ID_VCS_B, QLatin1String("B")));
|
||||
QList<IVersionControl *> orig = Core::d->m_versionControlList;
|
||||
TestVersionControl *vcsA(new TestVersionControl(ID_VCS_A, QLatin1String("A")));
|
||||
TestVersionControl *vcsB(new TestVersionControl(ID_VCS_B, QLatin1String("B")));
|
||||
|
||||
Core::d->m_versionControlList = {vcsA, vcsB};
|
||||
|
||||
// test:
|
||||
QFETCH(QStringList, dirsVcsA);
|
||||
@@ -604,7 +586,8 @@ void CorePlugin::testVcsManager()
|
||||
}
|
||||
|
||||
// teardown:
|
||||
// handled by guards
|
||||
qDeleteAll(Core::d->m_versionControlList);
|
||||
Core::d->m_versionControlList = orig;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -56,9 +56,17 @@ class CORE_EXPORT VcsManager : public QObject
|
||||
public:
|
||||
static VcsManager *instance();
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static T *registerVersionControl(Args&&... args)
|
||||
{
|
||||
T *vc = new T(std::forward<Args>(args)...);
|
||||
addVersionControl(vc);
|
||||
return vc;
|
||||
}
|
||||
|
||||
static void extensionsInitialized();
|
||||
|
||||
static QList<IVersionControl *> versionControls();
|
||||
static const QList<IVersionControl *> versionControls();
|
||||
static IVersionControl *versionControl(Id id);
|
||||
|
||||
static void resetVersionControlForDirectory(const QString &inputDirectory);
|
||||
@@ -102,6 +110,8 @@ private:
|
||||
explicit VcsManager(QObject *parent = 0);
|
||||
~VcsManager();
|
||||
|
||||
static void addVersionControl(IVersionControl *vc);
|
||||
|
||||
void handleConfigurationChanges();
|
||||
|
||||
friend class Core::Internal::MainWindow;
|
||||
|
@@ -198,7 +198,7 @@ bool CvsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
|
||||
Context context(CVS_CONTEXT);
|
||||
|
||||
initializeVcs(new CvsControl(this), context);
|
||||
initializeVcs<CvsControl>(context, this);
|
||||
|
||||
m_cvsPluginInstance = this;
|
||||
|
||||
|
@@ -296,10 +296,10 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
|
||||
m_gitClient = new GitClient;
|
||||
|
||||
initializeVcs(new GitVersionControl(m_gitClient), context);
|
||||
auto vc = initializeVcs<GitVersionControl>(context, m_gitClient);
|
||||
|
||||
// Create the settings Page
|
||||
auto settingsPage = new SettingsPage(versionControl());
|
||||
auto settingsPage = new SettingsPage(vc);
|
||||
addAutoReleasedObject(settingsPage);
|
||||
connect(settingsPage, &SettingsPage::settingsChanged,
|
||||
this, &GitPlugin::updateRepositoryBrowserAction);
|
||||
|
@@ -122,12 +122,11 @@ bool MercurialPlugin::initialize(const QStringList & /* arguments */, QString *
|
||||
Core::Context context(Constants::MERCURIAL_CONTEXT);
|
||||
|
||||
m_client = new MercurialClient;
|
||||
initializeVcs(new MercurialControl(m_client), context);
|
||||
auto vc = initializeVcs<MercurialControl>(context, m_client);
|
||||
|
||||
addAutoReleasedObject(new OptionsPage(versionControl()));
|
||||
addAutoReleasedObject(new OptionsPage(vc));
|
||||
|
||||
connect(m_client, &VcsBaseClient::changed,
|
||||
static_cast<MercurialControl *>(versionControl()), &MercurialControl::changed);
|
||||
connect(m_client, &VcsBaseClient::changed, vc, &MercurialControl::changed);
|
||||
connect(m_client, &MercurialClient::needUpdate, this, &MercurialPlugin::update);
|
||||
|
||||
const auto describeFunc = [this](const QString &source, const QString &id) {
|
||||
|
@@ -183,7 +183,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er
|
||||
Q_UNUSED(errorMessage)
|
||||
Context context(PERFORCE_CONTEXT);
|
||||
|
||||
initializeVcs(new PerforceVersionControl(this), context);
|
||||
initializeVcs<PerforceVersionControl>(context, this);
|
||||
|
||||
m_instance = this;
|
||||
|
||||
|
@@ -210,7 +210,7 @@ bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *e
|
||||
|
||||
Context context(SUBVERSION_CONTEXT);
|
||||
|
||||
initializeVcs(new SubversionControl(this), context);
|
||||
initializeVcs<SubversionControl>(context, this);
|
||||
|
||||
m_subversionPluginInstance = this;
|
||||
|
||||
|
@@ -34,9 +34,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/id.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <coreplugin/iversioncontrol.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/vcsmanager.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/session.h>
|
||||
@@ -552,9 +550,10 @@ VcsBasePlugin::~VcsBasePlugin()
|
||||
|
||||
void VcsBasePlugin::initializeVcs(IVersionControl *vc, const Context &context)
|
||||
{
|
||||
QTC_ASSERT(vc, return);
|
||||
|
||||
d->m_versionControl = vc;
|
||||
d->m_context = context;
|
||||
addAutoReleasedObject(vc);
|
||||
|
||||
Internal::VcsPlugin *plugin = Internal::VcsPlugin::instance();
|
||||
connect(plugin, &Internal::VcsPlugin::submitEditorAboutToClose,
|
||||
|
@@ -27,6 +27,8 @@
|
||||
|
||||
#include "vcsbase_global.h"
|
||||
|
||||
#include <coreplugin/iversioncontrol.h>
|
||||
#include <coreplugin/vcsmanager.h>
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <QList>
|
||||
@@ -128,7 +130,14 @@ class VCSBASE_EXPORT VcsBasePlugin : public ExtensionSystem::IPlugin
|
||||
protected:
|
||||
explicit VcsBasePlugin();
|
||||
|
||||
void initializeVcs(Core::IVersionControl *vc, const Core::Context &context);
|
||||
template<class T, typename... Args>
|
||||
T *initializeVcs(const Core::Context &context, Args&&... args)
|
||||
{
|
||||
T *vc = Core::VcsManager::registerVersionControl<T>(std::forward<Args>(args)...);
|
||||
initializeVcs(vc, context);
|
||||
return vc;
|
||||
}
|
||||
|
||||
void extensionsInitialized() override;
|
||||
|
||||
public:
|
||||
@@ -204,6 +213,8 @@ private:
|
||||
void slotSubmitEditorAboutToClose(VcsBaseSubmitEditor *submitEditor, bool *result);
|
||||
void slotStateChanged(const VcsBase::Internal::State &s, Core::IVersionControl *vc);
|
||||
|
||||
void initializeVcs(Core::IVersionControl *vc, const Core::Context &context);
|
||||
|
||||
VcsBasePluginPrivate *d;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user