2009-11-02 18:50:06 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
|
|
|
** Copyright (c) 2009 Brian McGillion
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
2009-09-15 13:03:13 +03:00
|
|
|
#include "mercurialclient.h"
|
|
|
|
#include "constants.h"
|
|
|
|
|
2009-11-05 12:45:02 +01:00
|
|
|
#include <vcsbase/vcsbaseoutputwindow.h>
|
2011-02-28 13:40:04 +01:00
|
|
|
#include <vcsbase/vcsbaseplugin.h>
|
2011-03-28 11:59:26 +02:00
|
|
|
#include <vcsbase/vcsbaseeditor.h>
|
|
|
|
#include <vcsbase/vcsbaseeditorparameterwidget.h>
|
2011-02-28 13:40:04 +01:00
|
|
|
#include <vcsbase/vcsjobrunner.h>
|
|
|
|
#include <utils/synchronousprocess.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2011-03-28 11:59:26 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-03-28 11:59:26 +02:00
|
|
|
#include <QtCore/QDir>
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
#include <QtCore/QTextCodec>
|
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
#include <QtCore/QVariant>
|
2010-08-19 16:26:47 +02:00
|
|
|
|
2009-12-04 12:58:01 +01:00
|
|
|
namespace Mercurial {
|
|
|
|
namespace Internal {
|
|
|
|
|
2011-06-10 15:27:57 +00:00
|
|
|
MercurialClient::MercurialClient(MercurialSettings *settings) :
|
2011-02-28 13:40:04 +01:00
|
|
|
VCSBase::VCSBaseClient(settings)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2010-05-11 14:13:38 +02:00
|
|
|
}
|
|
|
|
|
2011-06-10 15:27:57 +00:00
|
|
|
MercurialSettings *MercurialClient::settings() const
|
|
|
|
{
|
|
|
|
return dynamic_cast<MercurialSettings *>(VCSBase::VCSBaseClient::settings());
|
|
|
|
}
|
|
|
|
|
2009-12-08 14:28:00 +01:00
|
|
|
bool MercurialClient::manifestSync(const QString &repository, const QString &relativeFilename)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2009-12-08 14:28:00 +01:00
|
|
|
// This only works when called from the repo and outputs paths relative to it.
|
|
|
|
const QStringList args(QLatin1String("manifest"));
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
QByteArray output;
|
2011-02-28 13:40:04 +01:00
|
|
|
vcsFullySynchronousExec(repository, args, &output);
|
2009-12-08 14:28:00 +01:00
|
|
|
const QDir repositoryDir(repository);
|
|
|
|
const QFileInfo needle = QFileInfo(repositoryDir, relativeFilename);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2009-11-03 16:38:39 +01:00
|
|
|
const QStringList files = QString::fromLocal8Bit(output).split(QLatin1Char('\n'));
|
|
|
|
foreach (const QString &fileName, files) {
|
2009-12-08 14:28:00 +01:00
|
|
|
const QFileInfo managedFile(repositoryDir, fileName);
|
|
|
|
if (needle == managedFile)
|
2009-09-15 13:03:13 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-28 13:40:04 +01:00
|
|
|
//bool MercurialClient::clone(const QString &directory, const QString &url)
|
|
|
|
bool MercurialClient::synchronousClone(const QString &workingDir,
|
|
|
|
const QString &srcLocation,
|
|
|
|
const QString &dstLocation,
|
2011-05-12 14:48:10 +02:00
|
|
|
const QStringList &extraOptions)
|
2010-05-25 12:24:18 +02:00
|
|
|
{
|
2011-02-28 13:40:04 +01:00
|
|
|
Q_UNUSED(workingDir);
|
|
|
|
Q_UNUSED(extraOptions);
|
|
|
|
QDir workingDirectory(srcLocation);
|
|
|
|
QByteArray output;
|
|
|
|
const unsigned flags = VCSBase::VCSBasePlugin::SshPasswordPrompt |
|
|
|
|
VCSBase::VCSBasePlugin::ShowStdOutInLogWindow |
|
|
|
|
VCSBase::VCSBasePlugin::ShowSuccessMessage;
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-02-28 13:40:04 +01:00
|
|
|
if (workingDirectory.exists()) {
|
|
|
|
// Let's make first init
|
|
|
|
QStringList arguments(QLatin1String("init"));
|
|
|
|
if (!vcsFullySynchronousExec(workingDirectory.path(), arguments, &output)) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-05 12:45:02 +01:00
|
|
|
|
2011-02-28 13:40:04 +01:00
|
|
|
// Then pull remote repository
|
|
|
|
arguments.clear();
|
|
|
|
arguments << QLatin1String("pull") << dstLocation;
|
|
|
|
const Utils::SynchronousProcessResponse resp1 =
|
|
|
|
vcsSynchronousExec(workingDirectory.path(), arguments, flags);
|
|
|
|
if (resp1.result != Utils::SynchronousProcessResponse::Finished) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-02-28 13:40:04 +01:00
|
|
|
// By now, there is no hgrc file -> create it
|
2011-03-30 15:15:15 +02:00
|
|
|
Utils::FileSaver saver(workingDirectory.path()+"/.hg/hgrc");
|
|
|
|
saver.write(QString("[paths]\ndefault = %1\n").arg(dstLocation).toUtf8());
|
|
|
|
if (!saver.finalize()) {
|
|
|
|
VCSBase::VCSBaseOutputWindow::instance()->appendError(saver.errorString());
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-02-28 13:40:04 +01:00
|
|
|
// And last update repository
|
|
|
|
arguments.clear();
|
|
|
|
arguments << QLatin1String("update");
|
|
|
|
const Utils::SynchronousProcessResponse resp2 =
|
|
|
|
vcsSynchronousExec(workingDirectory.path(), arguments, flags);
|
|
|
|
return resp2.result == Utils::SynchronousProcessResponse::Finished;
|
|
|
|
} else {
|
|
|
|
QStringList arguments(QLatin1String("clone"));
|
|
|
|
arguments << dstLocation << workingDirectory.dirName();
|
|
|
|
workingDirectory.cdUp();
|
|
|
|
const Utils::SynchronousProcessResponse resp =
|
|
|
|
vcsSynchronousExec(workingDirectory.path(), arguments, flags);
|
|
|
|
return resp.result == Utils::SynchronousProcessResponse::Finished;
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-08 14:28:00 +01:00
|
|
|
QString MercurialClient::branchQuerySync(const QString &repositoryRoot)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
QByteArray output;
|
2011-02-28 13:40:04 +01:00
|
|
|
if (vcsFullySynchronousExec(repositoryRoot, QStringList(QLatin1String("branch")), &output))
|
2009-09-15 13:03:13 +03:00
|
|
|
return QTextCodec::codecForLocale()->toUnicode(output).trimmed();
|
|
|
|
|
2009-11-03 16:38:39 +01:00
|
|
|
return QLatin1String("Unknown Branch");
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
2010-01-08 09:44:07 +01:00
|
|
|
static inline QString msgParentRevisionFailed(const QString &workingDirectory,
|
|
|
|
const QString &revision,
|
|
|
|
const QString &why)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2010-07-05 09:52:32 +02:00
|
|
|
return MercurialClient::tr("Unable to find parent revisions of %1 in %2: %3").
|
|
|
|
arg(revision, QDir::toNativeSeparators(workingDirectory), why);
|
2010-01-08 09:44:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline QString msgParseParentsOutputFailed(const QString &output)
|
|
|
|
{
|
|
|
|
return MercurialClient::tr("Cannot parse output: %1").arg(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MercurialClient::parentRevisionsSync(const QString &workingDirectory,
|
|
|
|
const QString &file /* = QString() */,
|
|
|
|
const QString &revision,
|
|
|
|
QStringList *parents)
|
|
|
|
{
|
|
|
|
parents->clear();
|
|
|
|
QStringList args;
|
|
|
|
args << QLatin1String("parents") << QLatin1String("-r") <<revision;
|
|
|
|
if (!file.isEmpty())
|
|
|
|
args << file;
|
|
|
|
QByteArray outputData;
|
2011-02-28 13:40:04 +01:00
|
|
|
if (!vcsFullySynchronousExec(workingDirectory, args, &outputData))
|
2010-01-08 09:44:07 +01:00
|
|
|
return false;
|
|
|
|
QString output = QString::fromLocal8Bit(outputData);
|
|
|
|
output.remove(QLatin1Char('\r'));
|
|
|
|
/* Looks like: \code
|
|
|
|
changeset: 0:031a48610fba
|
|
|
|
user: ...
|
|
|
|
\endcode */
|
|
|
|
// Obtain first line and split by blank-delimited tokens
|
|
|
|
VCSBase::VCSBaseOutputWindow *outputWindow = VCSBase::VCSBaseOutputWindow::instance();
|
|
|
|
const QStringList lines = output.split(QLatin1Char('\n'));
|
|
|
|
if (lines.size() < 1) {
|
|
|
|
outputWindow->appendSilently(msgParentRevisionFailed(workingDirectory, revision, msgParseParentsOutputFailed(output)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QStringList changeSets = lines.front().simplified().split(QLatin1Char(' '));
|
|
|
|
if (changeSets.size() < 2) {
|
|
|
|
outputWindow->appendSilently(msgParentRevisionFailed(workingDirectory, revision, msgParseParentsOutputFailed(output)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Remove revision numbers
|
|
|
|
const QChar colon = QLatin1Char(':');
|
|
|
|
const QStringList::iterator end = changeSets.end();
|
|
|
|
QStringList::iterator it = changeSets.begin();
|
|
|
|
for (++it; it != end; ++it) {
|
|
|
|
const int colonIndex = it->indexOf(colon);
|
|
|
|
if (colonIndex != -1)
|
|
|
|
parents->push_back(it->mid(colonIndex + 1));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Describe a change using an optional format
|
|
|
|
bool MercurialClient::shortDescriptionSync(const QString &workingDirectory,
|
|
|
|
const QString &revision,
|
|
|
|
const QString &format,
|
|
|
|
QString *description)
|
|
|
|
{
|
|
|
|
description->clear();
|
|
|
|
QStringList args;
|
|
|
|
args << QLatin1String("log") << QLatin1String("-r") <<revision;
|
|
|
|
if (!format.isEmpty())
|
|
|
|
args << QLatin1String("--template") << format;
|
|
|
|
QByteArray outputData;
|
2011-02-28 13:40:04 +01:00
|
|
|
if (!vcsFullySynchronousExec(workingDirectory, args, &outputData))
|
2010-01-08 09:44:07 +01:00
|
|
|
return false;
|
|
|
|
*description = QString::fromLocal8Bit(outputData);
|
|
|
|
description->remove(QLatin1Char('\r'));
|
|
|
|
if (description->endsWith(QLatin1Char('\n')))
|
|
|
|
description->truncate(description->size() - 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default format: "SHA1 (author summmary)"
|
|
|
|
static const char defaultFormatC[] = "{node} ({author|person} {desc|firstline})";
|
|
|
|
|
|
|
|
bool MercurialClient::shortDescriptionSync(const QString &workingDirectory,
|
|
|
|
const QString &revision,
|
|
|
|
QString *description)
|
|
|
|
{
|
|
|
|
if (!shortDescriptionSync(workingDirectory, revision, QLatin1String(defaultFormatC), description))
|
|
|
|
return false;
|
|
|
|
description->remove(QLatin1Char('\n'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience to format a list of changes
|
|
|
|
bool MercurialClient::shortDescriptionsSync(const QString &workingDirectory, const QStringList &revisions,
|
|
|
|
QStringList *descriptions)
|
|
|
|
{
|
|
|
|
descriptions->clear();
|
|
|
|
foreach(const QString &revision, revisions) {
|
|
|
|
QString description;
|
|
|
|
if (!shortDescriptionSync(workingDirectory, revision, &description))
|
|
|
|
return false;
|
|
|
|
descriptions->push_back(description);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-29 12:16:35 +02:00
|
|
|
QString MercurialClient::vcsGetRepositoryURL(const QString &directory)
|
|
|
|
{
|
|
|
|
QByteArray output;
|
|
|
|
|
|
|
|
QStringList arguments(QLatin1String("showconfig"));
|
|
|
|
arguments << QLatin1String("paths.default");
|
|
|
|
|
2011-02-28 13:40:04 +01:00
|
|
|
if (vcsFullySynchronousExec(directory, arguments, &output))
|
|
|
|
return QString::fromLocal8Bit(output);
|
2010-09-29 12:16:35 +02:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2009-12-08 14:28:00 +01:00
|
|
|
void MercurialClient::incoming(const QString &repositoryRoot, const QString &repository)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
QStringList args;
|
2009-11-03 16:38:39 +01:00
|
|
|
args << QLatin1String("incoming") << QLatin1String("-g") << QLatin1String("-p");
|
2009-09-15 13:03:13 +03:00
|
|
|
if (!repository.isEmpty())
|
|
|
|
args.append(repository);
|
|
|
|
|
2009-12-08 14:28:00 +01:00
|
|
|
QString id = repositoryRoot;
|
|
|
|
if (!repository.isEmpty()) {
|
|
|
|
id += QDir::separator();
|
|
|
|
id += repository;
|
|
|
|
}
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2009-11-03 16:38:39 +01:00
|
|
|
const QString kind = QLatin1String(Constants::DIFFLOG);
|
2009-09-15 13:03:13 +03:00
|
|
|
const QString title = tr("Hg incoming %1").arg(id);
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
VCSBase::VCSBaseEditorWidget *editor = createVCSEditor(kind, title, repositoryRoot,
|
2009-09-15 13:03:13 +03:00
|
|
|
true, "incoming", id);
|
|
|
|
|
2011-02-28 13:40:04 +01:00
|
|
|
QSharedPointer<VCSBase::VCSJob> job(new VCSBase::VCSJob(repositoryRoot, args, editor));
|
2010-05-21 17:46:00 +02:00
|
|
|
// Suppress SSH prompting.
|
|
|
|
if (!repository.isEmpty() && VCSBase::VCSBasePlugin::isSshPromptConfigured())
|
2011-02-28 13:40:04 +01:00
|
|
|
job->setUnixTerminalDisabled(true);
|
2009-11-06 12:32:38 +01:00
|
|
|
enqueueJob(job);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
2009-12-08 14:28:00 +01:00
|
|
|
void MercurialClient::outgoing(const QString &repositoryRoot)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
QStringList args;
|
2009-11-03 16:38:39 +01:00
|
|
|
args << QLatin1String("outgoing") << QLatin1String("-g") << QLatin1String("-p");
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2009-11-03 16:38:39 +01:00
|
|
|
const QString kind = QLatin1String(Constants::DIFFLOG);
|
2010-07-05 09:52:32 +02:00
|
|
|
const QString title = tr("Hg outgoing %1").
|
2011-02-28 13:40:04 +01:00
|
|
|
arg(QDir::toNativeSeparators(repositoryRoot));
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
VCSBase::VCSBaseEditorWidget *editor = createVCSEditor(kind, title, repositoryRoot, true,
|
2009-12-08 14:28:00 +01:00
|
|
|
"outgoing", repositoryRoot);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-02-28 13:40:04 +01:00
|
|
|
QSharedPointer<VCSBase::VCSJob> job(new VCSBase::VCSJob(repositoryRoot, args, editor));
|
2010-05-21 17:46:00 +02:00
|
|
|
// Suppress SSH prompting
|
|
|
|
job->setUnixTerminalDisabled(VCSBase::VCSBasePlugin::isSshPromptConfigured());
|
2009-11-06 12:32:38 +01:00
|
|
|
enqueueJob(job);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
void MercurialClient::annotate(const QString &workingDir, const QString &file,
|
|
|
|
const QString revision, int lineNumber,
|
|
|
|
const QStringList &extraOptions)
|
2011-02-28 13:40:04 +01:00
|
|
|
{
|
2011-08-23 10:38:44 +00:00
|
|
|
QStringList args(extraOptions);
|
|
|
|
args << QLatin1String("-u") << QLatin1String("-c") << QLatin1String("-d");
|
|
|
|
VCSBaseClient::annotate(workingDir, file, revision, lineNumber, args);
|
2011-02-28 13:40:04 +01:00
|
|
|
}
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
void MercurialClient::commit(const QString &repositoryRoot, const QStringList &files,
|
|
|
|
const QString &commitMessageFile,
|
|
|
|
const QStringList &extraOptions)
|
2011-02-28 13:40:04 +01:00
|
|
|
{
|
2011-08-23 10:38:44 +00:00
|
|
|
QStringList args(extraOptions);
|
2011-09-14 11:50:37 +00:00
|
|
|
args << QLatin1String("--noninteractive") << QLatin1String("-l") << commitMessageFile << QLatin1String("-A");
|
2011-08-23 10:38:44 +00:00
|
|
|
VCSBaseClient::commit(repositoryRoot, files, commitMessageFile, args);
|
2011-02-28 13:40:04 +01:00
|
|
|
}
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
void MercurialClient::diff(const QString &workingDir, const QStringList &files,
|
|
|
|
const QStringList &extraOptions)
|
2011-02-28 13:40:04 +01:00
|
|
|
{
|
2011-08-23 10:38:44 +00:00
|
|
|
QStringList args(extraOptions);
|
|
|
|
args << QLatin1String("-g") << QLatin1String("-p") << QLatin1String("-U 8");
|
|
|
|
VCSBaseClient::diff(workingDir, files, args);
|
2011-02-28 13:40:04 +01:00
|
|
|
}
|
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
void MercurialClient::import(const QString &repositoryRoot, const QStringList &files,
|
|
|
|
const QStringList &extraOptions)
|
2011-02-28 13:40:04 +01:00
|
|
|
{
|
2011-08-23 10:38:44 +00:00
|
|
|
VCSBaseClient::import(repositoryRoot, files,
|
|
|
|
QStringList(extraOptions) << QLatin1String("--no-commit"));
|
2011-02-28 13:40:04 +01:00
|
|
|
}
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
void MercurialClient::revertAll(const QString &workingDir, const QString &revision,
|
|
|
|
const QStringList &extraOptions)
|
2011-02-28 13:40:04 +01:00
|
|
|
{
|
2011-08-23 10:38:44 +00:00
|
|
|
VCSBaseClient::revertAll(workingDir, revision,
|
|
|
|
QStringList(extraOptions) << QLatin1String("--all"));
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
void MercurialClient::view(const QString &source, const QString &id,
|
|
|
|
const QStringList &extraOptions)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2011-02-28 13:40:04 +01:00
|
|
|
QStringList args;
|
2011-08-23 10:38:44 +00:00
|
|
|
args << QLatin1String("log") << QLatin1String("-p") << QLatin1String("-g");
|
|
|
|
VCSBaseClient::view(source, id, args << extraOptions);
|
2011-02-28 13:40:04 +01:00
|
|
|
}
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
QString MercurialClient::findTopLevelForFile(const QFileInfo &file) const
|
2011-02-28 13:40:04 +01:00
|
|
|
{
|
2011-08-23 10:38:44 +00:00
|
|
|
const QString repositoryCheckFile = QLatin1String(Constants::MECURIALREPO) + QLatin1String("/requires");
|
|
|
|
return file.isDir() ?
|
|
|
|
VCSBase::VCSBasePlugin::findRepositoryForDirectory(file.absoluteFilePath(), repositoryCheckFile) :
|
|
|
|
VCSBase::VCSBasePlugin::findRepositoryForDirectory(file.absolutePath(), repositoryCheckFile);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
QString MercurialClient::vcsEditorKind(VCSCommand cmd) const
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2011-08-23 10:38:44 +00:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case AnnotateCommand : return QLatin1String(Constants::ANNOTATELOG);
|
|
|
|
case DiffCommand : return QLatin1String(Constants::DIFFLOG);
|
|
|
|
case LogCommand : return QLatin1String(Constants::FILELOG);
|
|
|
|
default : return QLatin1String("");
|
|
|
|
}
|
|
|
|
return QLatin1String("");
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
QStringList MercurialClient::revisionSpec(const QString &revision) const
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2011-02-28 13:40:04 +01:00
|
|
|
QStringList args;
|
|
|
|
if (!revision.isEmpty())
|
|
|
|
args << QLatin1String("-r") << revision;
|
|
|
|
return args;
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
2009-11-06 12:32:38 +01:00
|
|
|
|
2011-08-22 15:33:03 +00:00
|
|
|
MercurialClient::StatusItem MercurialClient::parseStatusLine(const QString &line) const
|
2009-11-06 12:32:38 +01:00
|
|
|
{
|
2011-08-22 15:33:03 +00:00
|
|
|
StatusItem item;
|
2011-02-28 13:40:04 +01:00
|
|
|
if (!line.isEmpty())
|
|
|
|
{
|
|
|
|
if (line.startsWith(QLatin1Char('M')))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Modified");
|
2011-02-28 13:40:04 +01:00
|
|
|
else if (line.startsWith(QLatin1Char('A')))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Added");
|
2011-02-28 13:40:04 +01:00
|
|
|
else if (line.startsWith(QLatin1Char('R')))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Removed");
|
2011-02-28 13:40:04 +01:00
|
|
|
else if (line.startsWith(QLatin1Char('!')))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Deleted");
|
2011-02-28 13:40:04 +01:00
|
|
|
else if (line.startsWith(QLatin1Char('?')))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Untracked");
|
2011-02-28 13:40:04 +01:00
|
|
|
else
|
2011-08-22 15:33:03 +00:00
|
|
|
return item;
|
2011-02-28 13:40:04 +01:00
|
|
|
|
|
|
|
//the status line should be similar to "M file_with_changes"
|
|
|
|
//so just should take the file name part and store it
|
2011-08-22 15:33:03 +00:00
|
|
|
item.file = line.mid(2);
|
2009-11-06 12:32:38 +01:00
|
|
|
}
|
2011-08-22 15:33:03 +00:00
|
|
|
return item;
|
2009-11-06 12:32:38 +01:00
|
|
|
}
|
2009-12-04 12:58:01 +01:00
|
|
|
|
2011-03-28 11:59:26 +02:00
|
|
|
// Collect all parameters required for a diff to be able to associate them
|
|
|
|
// with a diff editor and re-run the diff with parameters.
|
|
|
|
struct MercurialDiffParameters
|
|
|
|
{
|
|
|
|
QString workingDir;
|
|
|
|
QStringList files;
|
2011-05-12 14:48:10 +02:00
|
|
|
QStringList extraOptions;
|
2011-03-28 11:59:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Parameter widget controlling whitespace diff mode, associated with a parameter
|
|
|
|
class MercurialDiffParameterWidget : public VCSBase::VCSBaseEditorParameterWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2011-06-10 15:27:57 +00:00
|
|
|
MercurialDiffParameterWidget(MercurialClient *client,
|
|
|
|
const MercurialDiffParameters &p, QWidget *parent = 0) :
|
|
|
|
VCSBase::VCSBaseEditorParameterWidget(parent), m_client(client), m_params(p)
|
|
|
|
{
|
|
|
|
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore whitespace")),
|
2011-09-14 09:13:44 +00:00
|
|
|
client->settings()->boolPointer(MercurialSettings::diffIgnoreWhiteSpaceKey));
|
2011-06-10 15:27:57 +00:00
|
|
|
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore blank lines")),
|
2011-09-14 09:13:44 +00:00
|
|
|
client->settings()->boolPointer(MercurialSettings::diffIgnoreBlankLinesKey));
|
2011-06-10 15:27:57 +00:00
|
|
|
}
|
2011-03-28 11:59:26 +02:00
|
|
|
|
2011-06-10 15:27:57 +00:00
|
|
|
void executeCommand()
|
|
|
|
{
|
|
|
|
m_client->diff(m_params.workingDir, m_params.files, m_params.extraOptions);
|
|
|
|
}
|
2011-03-28 11:59:26 +02:00
|
|
|
|
|
|
|
private:
|
2011-06-10 15:27:57 +00:00
|
|
|
MercurialClient *m_client;
|
|
|
|
const MercurialDiffParameters m_params;
|
2011-03-28 11:59:26 +02:00
|
|
|
};
|
|
|
|
|
2011-06-10 15:27:57 +00:00
|
|
|
VCSBase::VCSBaseEditorParameterWidget *MercurialClient::createDiffEditor(
|
|
|
|
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
|
2011-03-28 11:59:26 +02:00
|
|
|
{
|
|
|
|
MercurialDiffParameters parameters;
|
|
|
|
parameters.workingDir = workingDir;
|
|
|
|
parameters.files = files;
|
2011-05-12 14:48:10 +02:00
|
|
|
parameters.extraOptions = extraOptions;
|
2011-06-10 15:27:57 +00:00
|
|
|
return new MercurialDiffParameterWidget(this, parameters);
|
2011-03-28 11:59:26 +02:00
|
|
|
}
|
|
|
|
|
2009-12-04 12:58:01 +01:00
|
|
|
} // namespace Internal
|
|
|
|
} // namespace Mercurial
|
2011-03-28 11:59:26 +02:00
|
|
|
|
|
|
|
#include "mercurialclient.moc"
|