Commit de490678 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Mercurial: Adapt to 8097879d

Make use of VCS base class.
parent 8097879d
......@@ -78,48 +78,46 @@ MercurialClient::~MercurialClient()
}
}
bool MercurialClient::add(const QString &filename)
bool MercurialClient::add(const QString &workingDir, const QString &filename)
{
QFileInfo file(filename);
QStringList args;
args << QLatin1String("add") << file.absoluteFilePath();
return executeHgSynchronously(file, args);
args << QLatin1String("add") << filename;
return executeHgSynchronously(workingDir, args);
}
bool MercurialClient::remove(const QString &filename)
bool MercurialClient::remove(const QString &workingDir, const QString &filename)
{
QFileInfo file(filename);
QStringList args;
args << QLatin1String("remove") << file.absoluteFilePath();
return executeHgSynchronously(file, args);
args << QLatin1String("remove") << filename;
return executeHgSynchronously(workingDir, args);
}
bool MercurialClient::manifestSync(const QString &filename)
bool MercurialClient::manifestSync(const QString &repository, const QString &relativeFilename)
{
QFileInfo file(filename);
QStringList args(QLatin1String("manifest"));
// This only works when called from the repo and outputs paths relative to it.
const QStringList args(QLatin1String("manifest"));
QByteArray output;
executeHgSynchronously(file, args, &output);
executeHgSynchronously(repository, args, &output);
const QDir repositoryDir(repository);
const QFileInfo needle = QFileInfo(repositoryDir, relativeFilename);
const QStringList files = QString::fromLocal8Bit(output).split(QLatin1Char('\n'));
foreach (const QString &fileName, files) {
const QFileInfo managedFile(fileName);
if (file == managedFile)
const QFileInfo managedFile(repositoryDir, fileName);
if (needle == managedFile)
return true;
}
return false;
}
bool MercurialClient::executeHgSynchronously(const QFileInfo &file, const QStringList &args,
bool MercurialClient::executeHgSynchronously(const QString &workingDir,
const QStringList &args,
QByteArray *output) const
{
QProcess hgProcess;
hgProcess.setWorkingDirectory(file.isDir() ? file.absoluteFilePath() : file.absolutePath());
if (!workingDir.isEmpty())
hgProcess.setWorkingDirectory(workingDir);
const MercurialSettings &settings = MercurialPlugin::instance()->settings();
const QString binary = settings.binary();
......@@ -152,7 +150,7 @@ bool MercurialClient::executeHgSynchronously(const QFileInfo &file, const QStrin
return false;
}
QString MercurialClient::branchQuerySync(const QFileInfo &repositoryRoot)
QString MercurialClient::branchQuerySync(const QString &repositoryRoot)
{
QByteArray output;
if (executeHgSynchronously(repositoryRoot, QStringList(QLatin1String("branch")), &output))
......@@ -161,66 +159,53 @@ QString MercurialClient::branchQuerySync(const QFileInfo &repositoryRoot)
return QLatin1String("Unknown Branch");
}
void MercurialClient::annotate(const QFileInfo &file)
void MercurialClient::annotate(const QString &workingDir, const QString &file)
{
QStringList args;
args << QLatin1String("annotate") << QLatin1String("-u") << QLatin1String("-c") << QLatin1String("-d") << file.absoluteFilePath();
args << QLatin1String("annotate") << QLatin1String("-u") << QLatin1String("-c") << QLatin1String("-d") << file;
const QString kind = QLatin1String(Constants::ANNOTATELOG);
const QString title = tr("Hg Annotate %1").arg(file.fileName());
const QString id = VCSBase::VCSBaseEditor::getSource(workingDir, QStringList(file));
const QString title = tr("Hg Annotate %1").arg(id);
const QString source = VCSBase::VCSBaseEditor::getSource(workingDir, file);
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, file.absolutePath(), true,
"annotate", file.absoluteFilePath());
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, source, true,
"annotate", id);
QSharedPointer<HgTask> job(new HgTask(file.absolutePath(), args, editor));
QSharedPointer<HgTask> job(new HgTask(workingDir, args, editor));
enqueueJob(job);
}
void MercurialClient::diff(const QFileInfo &fileOrDir)
void MercurialClient::diff(const QString &workingDir, const QStringList &files)
{
QStringList args;
QString id;
QString workingPath;
args << QLatin1String("diff") << QLatin1String("-g") << QLatin1String("-p")
<< QLatin1String("-U 8");
if (!fileOrDir.isDir()) {
args.append(fileOrDir.absoluteFilePath());
id = fileOrDir.absoluteFilePath();
workingPath = fileOrDir.absolutePath();
} else {
id = MercurialPlugin::instance()->currentProjectName();
workingPath = fileOrDir.absoluteFilePath();
}
if (!files.isEmpty())
args.append(files);
const QString kind = QLatin1String(Constants::DIFFLOG);
const QString title = tr("Hg diff %1").arg(fileOrDir.isDir() ? id : fileOrDir.fileName());
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, workingPath, true,
const QString id = VCSBase::VCSBaseEditor::getTitleId(workingDir,files);
const QString title = tr("Hg diff %1").arg(id);
const QString source = VCSBase::VCSBaseEditor::getSource(workingDir, files);
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, source, true,
"diff", id);
QSharedPointer<HgTask> job(new HgTask(workingPath, args, editor));
QSharedPointer<HgTask> job(new HgTask(workingDir, args, editor));
enqueueJob(job);
}
void MercurialClient::log(const QFileInfo &fileOrDir)
void MercurialClient::log(const QString &workingDir, const QStringList &files)
{
QStringList args(QLatin1String("log"));
QString id;
QString workingDir;
if (!fileOrDir.isDir()) {
args.append(fileOrDir.absoluteFilePath());
id = fileOrDir.absoluteFilePath();
workingDir = fileOrDir.absolutePath();
} else {
id = MercurialPlugin::instance()->currentProjectName();
workingDir = fileOrDir.absoluteFilePath();
}
if (!files.empty())
args.append(files);
const QString kind = QLatin1String(Constants::FILELOG);
const QString title = tr("Hg log %1").arg(fileOrDir.isDir() ? id : fileOrDir.fileName());
const QString id = VCSBase::VCSBaseEditor::getTitleId(workingDir,files);
const QString title = tr("Hg log %1").arg(id);
const QString source = VCSBase::VCSBaseEditor::getSource(workingDir, files);
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, workingDir, true,
"log", id);
......@@ -229,42 +214,51 @@ void MercurialClient::log(const QFileInfo &fileOrDir)
enqueueJob(job);
}
void MercurialClient::revert(const QFileInfo &fileOrDir, const QString &revision)
void MercurialClient::revertFile(const QString &workingDir,
const QString &file,
const QString &revision)
{
const QString filePath = fileOrDir.absoluteFilePath();
const QString workingDir = fileOrDir.isDir() ? filePath : fileOrDir.absolutePath();
const QStringList cookieList(workingDir + QLatin1Char('/') + file);
revert(workingDir, file, revision, QVariant(cookieList));
}
void MercurialClient::revertRepository(const QString &workingDir,
const QString &revision)
{
revert(workingDir, QLatin1String("--all"), revision, QVariant(workingDir));
}
void MercurialClient::revert(const QString &workingDir,
const QString &argument,
const QString &revision,
const QVariant &cookie)
{
QStringList args(QLatin1String("revert"));
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
args.append(fileOrDir.isDir() ? QString(QLatin1String("--all")) : filePath);
args.append(argument);
// Indicate repository change or file list
const QVariant cookie = fileOrDir.isDir() ? QVariant(filePath) : QVariant(QStringList(filePath));
QSharedPointer<HgTask> job(new HgTask(workingDir, args, false, cookie));
connect(job.data(), SIGNAL(succeeded(QVariant)), this, SIGNAL(changed(QVariant)), Qt::QueuedConnection);
enqueueJob(job);
}
void MercurialClient::status(const QFileInfo &fileOrDir)
void MercurialClient::status(const QString &workingDir, const QString &file)
{
QStringList args(QLatin1String("status"));
if (!fileOrDir.isDir())
args.append(fileOrDir.absoluteFilePath());
QSharedPointer<HgTask> job(new HgTask(fileOrDir.isDir() ? fileOrDir.absoluteFilePath() :
fileOrDir.absolutePath(), args, false));
if (!file.isEmpty())
args.append(file);
QSharedPointer<HgTask> job(new HgTask(workingDir, args, false));
enqueueJob(job);
}
void MercurialClient::statusWithSignal(const QFileInfo &repositoryRoot)
void MercurialClient::statusWithSignal(const QString &repositoryRoot)
{
const QStringList args(QLatin1String("status"));
QSharedPointer<HgTask> job(new HgTask(repositoryRoot.absoluteFilePath(), args, true));
QSharedPointer<HgTask> job(new HgTask(repositoryRoot, args, true));
connect(job.data(), SIGNAL(rawData(QByteArray)),
this, SLOT(statusParser(QByteArray)));
enqueueJob(job);
}
......@@ -299,72 +293,71 @@ void MercurialClient::statusParser(const QByteArray &data)
emit parsedStatus(statusList);
}
void MercurialClient::import(const QFileInfo &repositoryRoot, const QStringList &files)
void MercurialClient::import(const QString &repositoryRoot, const QStringList &files)
{
QStringList args;
args << QLatin1String("import") << QLatin1String("--no-commit");
args += files;
QSharedPointer<HgTask> job(new HgTask(repositoryRoot.absoluteFilePath(), args, false));
QSharedPointer<HgTask> job(new HgTask(repositoryRoot, args, false));
enqueueJob(job);
}
void MercurialClient::pull(const QFileInfo &repositoryRoot, const QString &repository)
void MercurialClient::pull(const QString &repositoryRoot, const QString &repository)
{
QStringList args(QLatin1String("pull"));
if (!repository.isEmpty())
args.append(repository);
const QString path = repositoryRoot.absoluteFilePath();
QSharedPointer<HgTask> job(new HgTask(path, args, false, QVariant(path)));
QSharedPointer<HgTask> job(new HgTask(repositoryRoot, args, false, QVariant(repositoryRoot)));
connect(job.data(), SIGNAL(succeeded(QVariant)), this, SIGNAL(changed(QVariant)), Qt::QueuedConnection);
enqueueJob(job);
}
void MercurialClient::push(const QFileInfo &repositoryRoot, const QString &repository)
void MercurialClient::push(const QString &repositoryRoot, const QString &repository)
{
QStringList args(QLatin1String("push"));
if (!repository.isEmpty())
args.append(repository);
QSharedPointer<HgTask> job(new HgTask(repositoryRoot.absoluteFilePath(), args, false));
QSharedPointer<HgTask> job(new HgTask(repositoryRoot, args, false));
enqueueJob(job);
}
void MercurialClient::incoming(const QFileInfo &repositoryRoot, const QString &repository)
void MercurialClient::incoming(const QString &repositoryRoot, const QString &repository)
{
QStringList args;
args << QLatin1String("incoming") << QLatin1String("-g") << QLatin1String("-p");
if (!repository.isEmpty())
args.append(repository);
QString id = MercurialPlugin::instance()->currentProjectName();
QString id = repositoryRoot;
if (!repository.isEmpty()) {
id += QDir::separator();
id += repository;
}
const QString kind = QLatin1String(Constants::DIFFLOG);
const QString title = tr("Hg incoming %1").arg(id);
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, repositoryRoot.absoluteFilePath(),
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, repositoryRoot,
true, "incoming", id);
QSharedPointer<HgTask> job(new HgTask(repositoryRoot.absoluteFilePath(), args, editor));
QSharedPointer<HgTask> job(new HgTask(repositoryRoot, args, editor));
enqueueJob(job);
}
void MercurialClient::outgoing(const QFileInfo &repositoryRoot)
void MercurialClient::outgoing(const QString &repositoryRoot)
{
QStringList args;
args << QLatin1String("outgoing") << QLatin1String("-g") << QLatin1String("-p");
QString id = MercurialPlugin::instance()->currentProjectName();
const QString kind = QLatin1String(Constants::DIFFLOG);
const QString title = tr("Hg outgoing %1").arg(id);
const QString title = tr("Hg outgoing %1").arg(repositoryRoot);
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, repositoryRoot.absoluteFilePath(), true,
"outgoing", id);
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, repositoryRoot, true,
"outgoing", repositoryRoot);
QSharedPointer<HgTask> job(new HgTask(repositoryRoot.absoluteFilePath(), args, editor));
QSharedPointer<HgTask> job(new HgTask(repositoryRoot, args, editor));
enqueueJob(job);
}
......@@ -384,26 +377,25 @@ void MercurialClient::view(const QString &source, const QString &id)
enqueueJob(job);
}
void MercurialClient::update(const QFileInfo &repositoryRoot, const QString &revision)
void MercurialClient::update(const QString &repositoryRoot, const QString &revision)
{
QStringList args(QLatin1String("update"));
if (!revision.isEmpty())
args << revision;
const QString path = repositoryRoot.absoluteFilePath();
QSharedPointer<HgTask> job(new HgTask(path, args, false, QVariant(path)));
QSharedPointer<HgTask> job(new HgTask(repositoryRoot, args, false, QVariant(repositoryRoot)));
connect(job.data(), SIGNAL(succeeded(QVariant)), this, SIGNAL(changed(QVariant)), Qt::QueuedConnection);
enqueueJob(job);
}
void MercurialClient::commit(const QFileInfo &repositoryRoot, const QStringList &files,
void MercurialClient::commit(const QString &repositoryRoot, const QStringList &files,
const QString &committerInfo, const QString &commitMessageFile)
{
QStringList args(QLatin1String("commit"));
if (!committerInfo.isEmpty())
args << QLatin1String("-u") << committerInfo;
args << QLatin1String("-l") << commitMessageFile << files;
QSharedPointer<HgTask> job(new HgTask(repositoryRoot.absoluteFilePath(), args, false));
QSharedPointer<HgTask> job(new HgTask(repositoryRoot, args, false));
enqueueJob(job);
}
......
......@@ -31,6 +31,7 @@
#define MERCURIALCLIENT_H
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QPair>
#include <QtCore/QSharedPointer>
......@@ -59,23 +60,24 @@ class MercurialClient : public QObject
public:
MercurialClient();
~MercurialClient();
bool add(const QString &fileName);
bool remove(const QString &fileName);
bool manifestSync(const QString &filename);
QString branchQuerySync(const QFileInfo &repositoryRoot);
void annotate(const QFileInfo &file);
void diff(const QFileInfo &fileOrDir);
void log(const QFileInfo &fileOrDir);
void import(const QFileInfo &repositoryRoot, const QStringList &files);
void pull(const QFileInfo &repositoryRoot, const QString &repository);
void push(const QFileInfo &repositoryRoot, const QString &repository);
void incoming(const QFileInfo &repositoryRoot, const QString &repository);
void outgoing(const QFileInfo &repositoryRoot);
void status(const QFileInfo &fileOrDir);
void statusWithSignal(const QFileInfo &fileOrDir);
void revert(const QFileInfo &fileOrDir, const QString &revision);
void update(const QFileInfo &repositoryRoot, const QString &revision);
void commit(const QFileInfo &repositoryRoot, const QStringList &files,
bool add(const QString &workingDir, const QString &fileName);
bool remove(const QString &workingDir, const QString &fileName);
bool manifestSync(const QString &repository, const QString &filename);
QString branchQuerySync(const QString &repositoryRoot);
void annotate(const QString &workingDir, const QString &files);
void diff(const QString &workingDir, const QStringList &files = QStringList());
void log(const QString &workingDir, const QStringList &files = QStringList());
void import(const QString &repositoryRoot, const QStringList &files);
void pull(const QString &repositoryRoot, const QString &repository = QString());
void push(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());
void update(const QString &repositoryRoot, const QString &revision = QString());
void commit(const QString &repositoryRoot, const QStringList &files,
const QString &commiterInfo, const QString &commitMessageFile);
static QString findTopLevelForFile(const QFileInfo &file);
......@@ -93,9 +95,12 @@ private slots:
void statusParser(const QByteArray &data);
private:
bool executeHgSynchronously(const QFileInfo &file, const QStringList &args,
bool executeHgSynchronously(const QString &workingDir,
const QStringList &args,
QByteArray *output=0) const;
void enqueueJob(const QSharedPointer<HgTask> &);
void revert(const QString &workingDir, const QString &argument,
const QString &revision, const QVariant &cookie);
MercurialJobRunner *jobManager;
Core::ICore *core;
......
......@@ -33,6 +33,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QVariant>
#include <QtCore/QStringList>
#include <QtCore/QDir>
using namespace Mercurial::Internal;
......@@ -47,19 +48,6 @@ QString MercurialControl::name() const
return tr("Mercurial");
}
bool MercurialControl::isEnabled() const
{
return mercurialEnabled;
}
void MercurialControl::setEnabled(bool enabled)
{
if (mercurialEnabled != enabled) {
mercurialEnabled = enabled;
emit enabledChanged(mercurialEnabled);
}
}
bool MercurialControl::managesDirectory(const QString &directory) const
{
QFileInfo dir(directory);
......@@ -97,17 +85,24 @@ bool MercurialControl::vcsOpen(const QString &filename)
bool MercurialControl::vcsAdd(const QString &filename)
{
return mercurialClient->add(filename);
const QFileInfo fi(filename);
return mercurialClient->add(fi.absolutePath(), fi.fileName());
}
bool MercurialControl::vcsDelete(const QString &filename)
{
return mercurialClient->remove(filename);
const QFileInfo fi(filename);
return mercurialClient->remove(fi.absolutePath(), fi.fileName());
}
bool MercurialControl::sccManaged(const QString &filename)
{
return mercurialClient->manifestSync(filename);
const QFileInfo fi(filename);
const QString topLevel = findTopLevelForDirectory(fi.absolutePath());
if (topLevel.isEmpty())
return false;
const QDir topLevelDir(topLevel);
return mercurialClient->manifestSync(topLevel, topLevelDir.relativeFilePath(filename));
}
void MercurialControl::changed(const QVariant &v)
......
......@@ -50,8 +50,6 @@ public:
explicit MercurialControl(MercurialClient *mercurialClient);
QString name() const;
bool isEnabled() const;
void setEnabled(bool enabled);
bool managesDirectory(const QString &filename) const;
QString findTopLevelForDirectory(const QString &directory) const;
bool supportsOperation(Operation operation) const;
......@@ -66,9 +64,6 @@ public slots:
// String -> repository, StringList -> files
void changed(const QVariant&);
signals:
void enabledChanged(bool);
private:
MercurialClient *mercurialClient;
bool mercurialEnabled;
......
......@@ -48,10 +48,8 @@
#include <coreplugin/filemanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
#include <utils/parameteraction.h>
#include <utils/qtcassert.h>
#include <vcsbase/basevcseditorfactory.h>
#include <vcsbase/basevcssubmiteditorfactory.h>
......@@ -73,11 +71,6 @@
using namespace Mercurial::Internal;
using namespace Mercurial;
bool ListenForClose::editorAboutToClose(Core::IEditor *editor)
{
return MercurialPlugin::instance()->closeEditor(editor);
}
static const VCSBase::VCSBaseEditorParameters editorParameters[] = {
{
VCSBase::RegularCommandOutput, //type
......@@ -122,11 +115,11 @@ static inline const VCSBase::VCSBaseEditorParameters *findType(int ie)
MercurialPlugin *MercurialPlugin::m_instance = 0;
MercurialPlugin::MercurialPlugin() :
VCSBase::VCSBasePlugin(QLatin1String(Constants::COMMITKIND)),
optionsPage(0),
client(0),
mercurialVC(0),
projectExplorer(0),
changeLog(0)
changeLog(0),
m_menuAction(0)
{
m_instance = this;
}
......@@ -143,13 +136,12 @@ MercurialPlugin::~MercurialPlugin()
m_instance = 0;
}
bool MercurialPlugin::initialize(const QStringList &arguments, QString *error_message)
bool MercurialPlugin::initialize(const QStringList & /* arguments */, QString * /*error_message */)
{
Q_UNUSED(arguments)
Q_UNUSED(error_message)
typedef VCSBase::VCSEditorFactory<MercurialEditor> MercurialEditorFactory;
VCSBase::VCSBasePlugin::initialize(new MercurialControl(client));
core = Core::ICore::instance();
actionManager = core->actionManager();
......@@ -160,9 +152,7 @@ bool MercurialPlugin::initialize(const QStringList &arguments, QString *error_me
client = new MercurialClient();
connect(optionsPage, SIGNAL(settingsChanged()), client, SLOT(settingsChanged()));
mercurialVC = new MercurialControl(client);
addAutoReleasedObject(mercurialVC);
connect(client, SIGNAL(changed(QVariant)), mercurialVC, SLOT(changed(QVariant)));
connect(client, SIGNAL(changed(QVariant)), versionControl(), SLOT(changed(QVariant)));
static const char *describeSlot = SLOT(view(QString,QString));
const int editorCount = sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters);
......@@ -173,8 +163,6 @@ bool MercurialPlugin::initialize(const QStringList &arguments, QString *error_me
addAutoReleasedObject(new CloneWizard);
addAutoReleasedObject(new ListenForClose);
createMenu();
createSubmitEditorActions();
......@@ -184,10 +172,6 @@ bool MercurialPlugin::initialize(const QStringList &arguments, QString *error_me
void MercurialPlugin::extensionsInitialized()
{
projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
if (projectExplorer)
connect(projectExplorer, SIGNAL(currentProjectChanged(ProjectExplorer::Project *)),
this, SLOT(currentProjectChanged(ProjectExplorer::Project *)));
}
const MercurialSettings &MercurialPlugin::settings() const
......@@ -216,11 +200,6 @@ void MercurialPlugin::createMenu()
QMenu *menu = mercurialContainer->menu();
menu->setTitle(tr("Mercurial"));
if (QAction *visibleAction = menu->menuAction()) {
visibleAction->setEnabled(mercurialVC->isEnabled());
connect(mercurialVC, SIGNAL(enabledChanged(bool)), visibleAction, SLOT(setVisible(bool)));