Commit 6c1dd96f authored by cerf's avatar cerf Committed by Tobias Hunger
Browse files

Refactored the Mercurial plugin



Refactored the mercurial plugin which led to new vcsbase common
tools (VCSBaseClient, VCSBaseClientSettings and VCSJobRunner)

Merge-request: 229
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent be81d25b
......@@ -6,7 +6,6 @@ SOURCES += mercurialplugin.cpp \
optionspage.cpp \
mercurialcontrol.cpp \
mercurialclient.cpp \
mercurialjobrunner.cpp \
annotationhighlighter.cpp \
mercurialeditor.cpp \
revertdialog.cpp \
......@@ -21,7 +20,6 @@ HEADERS += mercurialplugin.h \
optionspage.h \
mercurialcontrol.h \
mercurialclient.h \
mercurialjobrunner.h \
annotationhighlighter.h \
mercurialeditor.h \
revertdialog.h \
......
This diff is collapsed.
......@@ -34,43 +34,27 @@
#ifndef MERCURIALCLIENT_H
#define MERCURIALCLIENT_H
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QPair>
#include <QtCore/QSharedPointer>
QT_BEGIN_NAMESPACE
class QFileInfo;
class QVariant;
QT_END_NAMESPACE
namespace Core {
class ICore;
}
namespace VCSBase{
class VCSBaseEditorWidget;
}
namespace Utils {
struct SynchronousProcessResponse;
}
#include <vcsbase/vcsbaseclient.h>
namespace Mercurial {
namespace Internal {
class MercurialJobRunner;
class HgTask;
class MercurialClient : public QObject
class MercurialClient : public VCSBase::VCSBaseClient
{
Q_OBJECT
public:
MercurialClient();
~MercurialClient();
bool add(const QString &workingDir, const QString &fileName);
bool remove(const QString &workingDir, const QString &fileName);
bool move(const QString &workingDir, const QString &from, const QString &to);
enum ExtraOptionId
{
// Commit
AuthorCommitOptionId,
AutoAddRemoveCommitOptionId
};
MercurialClient(const VCSBase::VCSBaseClientSettings &settings);
virtual bool synchronousClone(const QString &workingDir,
const QString &srcLocation,
const QString &dstLocation,
const ExtraCommandOptions &extraOptions = ExtraCommandOptions());
bool manifestSync(const QString &repository, const QString &filename);
QString branchQuerySync(const QString &repositoryRoot);
bool parentRevisionsSync(const QString &workingDirectory,
......@@ -83,67 +67,38 @@ public:
QString *description);
bool shortDescriptionsSync(const QString &workingDirectory, const QStringList &revisions,
QStringList *descriptions);
void annotate(const QString &workingDir, const QString &files,
const QString revision = QString(), int lineNumber = -1);
void diff(const QString &workingDir, const QStringList &files = QStringList());
void log(const QString &workingDir, const QStringList &files = QStringList(),
bool enableAnnotationContextMenu = false);
void import(const QString &repositoryRoot, const QStringList &files);
bool pullSync(const QString &repositoryRoot, const QString &repository = QString());
bool pushSync(const QString &repositoryRoot, const QString &repository = QString());
void incoming(const QString &repositoryRoot, const QString &repository = QString());
void outgoing(const QString &repositoryRoot);
void status(const QString &workingDir, const QString &file = QString());
void statusWithSignal(const QString &repository);
void revertFile(const QString &workingDir, const QString &file, const QString &revision = QString());
void revertRepository(const QString &workingDir, const QString &revision = QString());
bool createRepositorySync(const QString &workingDir);
void update(const QString &repositoryRoot, const QString &revision = QString());
void commit(const QString &repositoryRoot,
const QStringList &files,
const QString &commiterInfo,
const QString &commitMessageFile,
bool autoAddRemove = false);
bool clone(const QString &directory, const QString &url);
QString vcsGetRepositoryURL(const QString &directory);
static QString findTopLevelForFile(const QFileInfo &file);
signals:
void parsedStatus(const QList<QPair<QString, QString> > &statusList);
// Passes on changed signals from HgTask to Control.
void changed(const QVariant &v);
public slots:
void view(const QString &source, const QString &id);
void settingsChanged();
private slots:
void statusParser(const QByteArray &data);
void slotAnnotateRevisionRequested(const QString &source, QString change, int lineNumber);
private:
// Fully synchronous git execution (QProcess-based).
bool executeHgFullySynchronously(const QString &workingDir,
const QStringList &args,
QByteArray *output) const;
// Synchronous hg execution using Utils::SynchronousProcess, with
// log windows updating (using VCSBasePlugin::runVCS with flags).
inline Utils::SynchronousProcessResponse
executeHgSynchronously(const QString &workingDir, const QStringList &args,
unsigned flags = 0, QTextCodec *outputCodec = 0);
void enqueueJob(const QSharedPointer<HgTask> &);
void revert(const QString &workingDir, const QString &argument,
const QString &revision, const QVariant &cookie);
MercurialJobRunner *jobManager;
Core::ICore *core;
VCSBase::VCSBaseEditorWidget *createVCSEditor(const QString &kind, QString title,
const QString &source, bool setSourceCodec,
const char *registerDynamicProperty,
const QString &dynamicPropertyValue) const;
public:
virtual QString findTopLevelForFile(const QFileInfo &file) const;
protected:
virtual QString vcsEditorKind(VCSCommand cmd) const;
virtual QStringList cloneArguments(const QString &srcLocation,
const QString &dstLocation,
const ExtraCommandOptions &extraOptions) const;
virtual QStringList pullArguments(const QString &srcLocation,
const ExtraCommandOptions &extraOptions) const;
virtual QStringList pushArguments(const QString &dstLocation,
const ExtraCommandOptions &extraOptions) const;
virtual QStringList commitArguments(const QStringList &files,
const QString &commitMessageFile,
const ExtraCommandOptions &extraOptions) const;
virtual QStringList importArguments(const QStringList &files) const;
virtual QStringList updateArguments(const QString &revision) const;
virtual QStringList revertArguments(const QString &file, const QString &revision) const;
virtual QStringList revertAllArguments(const QString &revision) const;
virtual QStringList annotateArguments(const QString &file,
const QString &revision, int lineNumber) const;
virtual QStringList diffArguments(const QStringList &files) const;
virtual QStringList logArguments(const QStringList &files) const;
virtual QStringList statusArguments(const QString &file) const;
virtual QStringList viewArguments(const QString &revision) const;
virtual QPair<QString, QString> parseStatusLine(const QString &line) const;
};
} //namespace Internal
......
......@@ -89,25 +89,27 @@ bool MercurialControl::vcsOpen(const QString &filename)
bool MercurialControl::vcsAdd(const QString &filename)
{
const QFileInfo fi(filename);
return mercurialClient->add(fi.absolutePath(), fi.fileName());
return mercurialClient->synchronousAdd(fi.absolutePath(), fi.fileName());
}
bool MercurialControl::vcsDelete(const QString &filename)
{
const QFileInfo fi(filename);
return mercurialClient->remove(fi.absolutePath(), 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->move(fromInfo.absolutePath(), fromInfo.absoluteFilePath(), toInfo.absoluteFilePath());
return mercurialClient->synchronousMove(fromInfo.absolutePath(),
fromInfo.absoluteFilePath(),
toInfo.absoluteFilePath());
}
bool MercurialControl::vcsCreateRepository(const QString &directory)
{
return mercurialClient->createRepositorySync(directory);
return mercurialClient->synchronousCreateRepository(directory);
}
QString MercurialControl::vcsCreateSnapshot(const QString &)
......@@ -150,7 +152,7 @@ bool MercurialControl::sccManaged(const QString &filename)
bool MercurialControl::vcsCheckout(const QString &directory, const QByteArray &url)
{
return mercurialClient->clone(directory,url);
return mercurialClient->synchronousClone(QString(), directory, url);
}
QString MercurialControl::vcsGetRepositoryURL(const QString &directory)
......
......@@ -157,7 +157,7 @@ bool MercurialPlugin::initialize(const QStringList & /* arguments */, QString *
{
typedef VCSBase::VCSEditorFactory<MercurialEditor> MercurialEditorFactory;
m_client = new MercurialClient();
m_client = new MercurialClient(mercurialSettings);
VCSBase::VCSBasePlugin::initialize(new MercurialControl(m_client));
core = Core::ICore::instance();
......@@ -165,7 +165,7 @@ bool MercurialPlugin::initialize(const QStringList & /* arguments */, QString *
optionsPage = new OptionsPage();
addAutoReleasedObject(optionsPage);
mercurialSettings.readSettings(core->settings());
mercurialSettings.readSettings(core->settings(), QLatin1String("Mercurial"));
connect(optionsPage, SIGNAL(settingsChanged()), m_client, SLOT(settingsChanged()));
......@@ -296,7 +296,7 @@ void MercurialPlugin::addCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
m_client->add(state.currentFileTopLevel(), state.relativeCurrentFile());
m_client->synchronousAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
}
void MercurialPlugin::annotateCurrentFile()
......@@ -395,7 +395,7 @@ void MercurialPlugin::revertMulti()
RevertDialog reverter;
if (reverter.exec() != QDialog::Accepted)
return;
m_client->revertRepository(state.topLevel(), reverter.revision());
m_client->revertAll(state.topLevel(), reverter.revision());
}
void MercurialPlugin::statusMulti()
......@@ -473,7 +473,7 @@ void MercurialPlugin::pull()
dialog.setWindowTitle(tr("Pull Source"));
if (dialog.exec() != QDialog::Accepted)
return;
m_client->pullSync(state.topLevel(), dialog.getRepositoryString());
m_client->synchronousPull(state.topLevel(), dialog.getRepositoryString());
}
void MercurialPlugin::push()
......@@ -485,7 +485,7 @@ void MercurialPlugin::push()
dialog.setWindowTitle(tr("Push Destination"));
if (dialog.exec() != QDialog::Accepted)
return;
m_client->pushSync(state.topLevel(), dialog.getRepositoryString());
m_client->synchronousPush(state.topLevel(), dialog.getRepositoryString());
}
void MercurialPlugin::update()
......@@ -672,11 +672,14 @@ bool MercurialPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *sub
editorFile->save();
core->fileManager()->unblockFileChange(editorFile);
m_client->commit(commitEditor->repoRoot(), files, commitEditor->committerInfo(),
editorFile->fileName(), true);
QHash<int, QVariant> extraOptions;
extraOptions[MercurialClient::AuthorCommitOptionId] = commitEditor->committerInfo();
m_client->commit(m_submitRepository, files, editorFile->fileName(),
extraOptions);
}
return true;
}
void MercurialPlugin::deleteCommitLog()
{
if (changeLog) {
......
......@@ -34,120 +34,15 @@
#include "mercurialsettings.h"
#include "constants.h"
#include <QtCore/QSettings>
using namespace Mercurial::Internal;
enum { timeOutDefaultSeconds = 30 };
MercurialSettings::MercurialSettings() :
m_binary(QLatin1String(Constants::MERCURIALDEFAULT)),
m_logCount(0),
m_timeoutSeconds(timeOutDefaultSeconds),
m_prompt(true)
{
}
QString MercurialSettings::binary() const
{
return m_binary;
}
void MercurialSettings::setBinary(const QString &b)
{
m_binary = b;
}
QStringList MercurialSettings::standardArguments() const
{
return m_standardArguments;
}
QString MercurialSettings::userName() const
{
return m_user;
}
void MercurialSettings::setUserName(const QString &u)
{
m_user = u;
}
QString MercurialSettings::email() const
{
return m_mail;
}
void MercurialSettings::setEmail(const QString &m)
{
m_mail = m;
}
int MercurialSettings::logCount() const
{
return m_logCount;
}
void MercurialSettings::setLogCount(int l)
{
m_logCount = l;
}
int MercurialSettings::timeoutMilliSeconds() const
{
//return timeout is in Ms
return m_timeoutSeconds * 1000;
}
int MercurialSettings::timeoutSeconds() const
{
//return timeout in seconds (as the user specifies on the options page
return m_timeoutSeconds;
}
void MercurialSettings::setTimeoutSeconds(int s)
{
m_timeoutSeconds = s;
}
bool MercurialSettings::prompt() const
{
return m_prompt;
}
void MercurialSettings::setPrompt(bool b)
{
m_prompt = b;
}
void MercurialSettings::writeSettings(QSettings *settings) const
{
settings->beginGroup(QLatin1String("Mercurial"));
settings->setValue(QLatin1String(Constants::MERCURIALPATH), m_binary);
settings->setValue(QLatin1String(Constants::MERCURIALUSERNAME), m_user);
settings->setValue(QLatin1String(Constants::MERCURIALEMAIL), m_mail);
settings->setValue(QLatin1String(Constants::MERCURIALLOGCOUNT), m_logCount);
settings->setValue(QLatin1String(Constants::MERCURIALTIMEOUT), m_timeoutSeconds);
settings->setValue(QLatin1String(Constants::MERCURIALPROMPTSUBMIT), m_prompt);
settings->endGroup();
}
void MercurialSettings::readSettings(const QSettings *settings)
MercurialSettings::MercurialSettings()
{
const QString keyRoot = QLatin1String("Mercurial/");
m_binary = settings->value(keyRoot + QLatin1String(Constants::MERCURIALPATH),
QLatin1String(Constants::MERCURIALDEFAULT)).toString();
m_user = settings->value(keyRoot + QLatin1String(Constants::MERCURIALUSERNAME), QString()).toString();
m_mail = settings->value(keyRoot + QLatin1String(Constants::MERCURIALEMAIL), QString()).toString();
m_logCount = settings->value(keyRoot + QLatin1String(Constants::MERCURIALLOGCOUNT), 0).toInt();
m_timeoutSeconds = settings->value(keyRoot + QLatin1String(Constants::MERCURIALTIMEOUT), timeOutDefaultSeconds).toInt();
m_prompt = settings->value(keyRoot + QLatin1String(Constants::MERCURIALPROMPTSUBMIT), true).toBool();
setBinary(QLatin1String(Constants::MERCURIALDEFAULT));
}
bool MercurialSettings::equals(const MercurialSettings &rhs) const
MercurialSettings& MercurialSettings::operator=(const MercurialSettings& other)
{
return m_binary == rhs.m_binary && m_standardArguments == rhs.m_standardArguments
&& m_user == rhs.m_user && m_mail == rhs.m_mail
&& m_logCount == rhs.m_logCount && m_timeoutSeconds == rhs.m_timeoutSeconds
&& m_prompt == rhs.m_prompt;
VCSBase::VCSBaseClientSettings::operator=(other);
return *this;
}
......@@ -34,65 +34,18 @@
#ifndef MERCURIALSETTINGS_H
#define MERCURIALSETTINGS_H
#include <QtCore/QString>
#include <QtCore/QStringList>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
#include <vcsbase/vcsbaseclientsettings.h>
namespace Mercurial {
namespace Internal {
class MercurialSettings
class MercurialSettings : public VCSBase::VCSBaseClientSettings
{
public:
MercurialSettings();
QString binary() const;
void setBinary(const QString &);
// Calculated.
QStringList standardArguments() const;
QString userName() const;
void setUserName(const QString &);
QString email() const;
void setEmail(const QString &);
int logCount() const;
void setLogCount(int l);
int timeoutMilliSeconds() const;
int timeoutSeconds() const;
void setTimeoutSeconds(int s);
bool prompt() const;
void setPrompt(bool b);
void writeSettings(QSettings *settings) const;
void readSettings(const QSettings *settings);
bool equals(const MercurialSettings &rhs) const;
private:
void readSettings();
QString m_binary;
QStringList m_standardArguments;
QString m_user;
QString m_mail;
int m_logCount;
int m_timeoutSeconds;
bool m_prompt;
MercurialSettings& operator=(const MercurialSettings& other);
};
inline bool operator==(const MercurialSettings &s1, const MercurialSettings &s2)
{ return s1.equals(s2); }
inline bool operator!=(const MercurialSettings &s1, const MercurialSettings &s2)
{ return !s1.equals(s2); }
} // namespace Internal
} // namespace Mercurial
......
......@@ -126,7 +126,8 @@ void OptionsPage::apply()
if (newSettings != plugin->settings()) {
//assume success and emit signal that settings are changed;
plugin->setSettings(newSettings);
newSettings.writeSettings(Core::ICore::instance()->settings());
newSettings.writeSettings(Core::ICore::instance()->settings(),
QLatin1String("Mercurial"));
emit settingsChanged();
}
}
......
......@@ -27,7 +27,10 @@ HEADERS += vcsbase_global.h \
basecheckoutwizardpage.h \
vcsbaseoutputwindow.h \
cleandialog.h \
vcsbaseoptionspage.h
vcsbaseoptionspage.h \
vcsjobrunner.h \
vcsbaseclient.h \
vcsbaseclientsettings.h
SOURCES += vcsplugin.cpp \
vcsbaseplugin.cpp \
......@@ -51,7 +54,10 @@ SOURCES += vcsplugin.cpp \
basecheckoutwizardpage.cpp \
vcsbaseoutputwindow.cpp \
cleandialog.cpp \
vcsbaseoptionspage.cpp
vcsbaseoptionspage.cpp \
vcsjobrunner.cpp \
vcsbaseclient.cpp \
vcsbaseclientsettings.cpp
RESOURCES += vcsbase.qrc
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Brian McGillion & Hugues Delorme
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "vcsbaseclient.h"
#include "vcsjobrunner.h"
#include "vcsbaseclientsettings.h"
#include <QtDebug>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <utils/qtcassert.h>
#include <utils/synchronousprocess.h>
#include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/vcsbaseoutputwindow.h>
#include <vcsbase/vcsbaseplugin.h>
#include <QtCore/QStringList>
#include <QtCore/QSharedPointer>
#include <QtCore/QDir>
#include <QtCore/QProcess>
#include <QtCore/QTextCodec>
#include <QtCore/QtDebug>
#include <QtCore/QFileInfo>
#include <QtCore/QByteArray>
#include <QtCore/QMetaType>
Q_DECLARE_METATYPE(QVariant)
inline Core::IEditor *locateEditor(const Core::ICore *core, const char *property, const QString &entry)
{
foreach (Core::IEditor *ed, core->editorManager()->openedEditors())
if (ed->file()->property(property).toString() == entry)
return ed;
return 0;
}
namespace VCSBase {
VCSBaseClient::VCSBaseClient(const VCSBaseClientSettings &settings) :
m_jobManager(0),
m_core(Core::ICore::instance()),
m_clientSettings(settings)
{
qRegisterMetaType<QVariant>();
}
VCSBaseClient::~VCSBaseClient()
{
if (m_jobManager) {
delete m_jobManager;