2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Brian McGillion
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-11-02 18:50:06 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-11-02 18:50:06 +01:00
|
|
|
|
2009-09-15 13:03:13 +03:00
|
|
|
#include "mercurialclient.h"
|
2018-12-09 22:47:40 +01:00
|
|
|
#include "mercurialplugin.h"
|
2009-09-15 13:03:13 +03:00
|
|
|
#include "constants.h"
|
|
|
|
|
2018-12-09 22:47:40 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
|
|
|
|
2014-08-27 18:55:41 +02:00
|
|
|
#include <vcsbase/vcscommand.h>
|
2014-08-26 00:02:47 +02:00
|
|
|
#include <vcsbase/vcsoutputwindow.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>
|
2016-10-23 04:42:43 +03:00
|
|
|
#include <vcsbase/vcsbaseeditorconfig.h>
|
2018-12-09 22:47:40 +01:00
|
|
|
#include <vcsbase/vcsbasediffeditorcontroller.h>
|
2011-02-28 13:40:04 +01:00
|
|
|
#include <utils/synchronousprocess.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2016-10-20 13:06:11 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2011-03-28 11:59:26 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2014-02-18 20:50:41 +02:00
|
|
|
#include <QDateTime>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QVariant>
|
2010-08-19 16:26:47 +02:00
|
|
|
|
2018-12-09 22:47:40 +01:00
|
|
|
using namespace Core;
|
|
|
|
using namespace DiffEditor;
|
2014-08-27 18:55:41 +02:00
|
|
|
using namespace Utils;
|
2014-08-26 00:02:47 +02:00
|
|
|
using namespace VcsBase;
|
|
|
|
|
2009-12-04 12:58:01 +01:00
|
|
|
namespace Mercurial {
|
|
|
|
namespace Internal {
|
|
|
|
|
2018-12-09 22:47:40 +01:00
|
|
|
class MercurialDiffEditorController : public VcsBaseDiffEditorController
|
2015-01-20 17:42:16 +01:00
|
|
|
{
|
|
|
|
public:
|
2020-02-04 08:11:50 +01:00
|
|
|
MercurialDiffEditorController(IDocument *document)
|
|
|
|
: VcsBaseDiffEditorController(document)
|
|
|
|
{
|
|
|
|
setDisplayName("Hg Diff");
|
|
|
|
}
|
2018-12-09 22:47:40 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void runCommand(const QList<QStringList> &args, QTextCodec *codec = nullptr);
|
|
|
|
QStringList addConfigurationArguments(const QStringList &args) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
void MercurialDiffEditorController::runCommand(const QList<QStringList> &args, QTextCodec *codec)
|
|
|
|
{
|
|
|
|
// at this moment, don't ignore any errors
|
|
|
|
VcsBaseDiffEditorController::runCommand(args, 0u, codec);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList MercurialDiffEditorController::addConfigurationArguments(const QStringList &args) const
|
|
|
|
{
|
|
|
|
QStringList configArgs{ "-g", "-p" };
|
|
|
|
configArgs << "-U" << QString::number(contextLineCount());
|
|
|
|
if (ignoreWhitespace()) {
|
|
|
|
configArgs << "-w" << "-b" << "-B" << "-Z";
|
|
|
|
}
|
|
|
|
return args + configArgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
class FileDiffController : public MercurialDiffEditorController
|
|
|
|
{
|
|
|
|
public:
|
2020-02-04 08:11:50 +01:00
|
|
|
FileDiffController(IDocument *document, const QString &fileName) :
|
2020-02-06 11:52:59 +01:00
|
|
|
MercurialDiffEditorController(document)
|
2015-01-20 17:42:16 +01:00
|
|
|
{
|
2020-02-06 11:52:59 +01:00
|
|
|
setReloader([this, fileName] {
|
|
|
|
QStringList args = { "diff", fileName };
|
|
|
|
runCommand({ addConfigurationArguments(args) });
|
|
|
|
});
|
2015-01-20 17:42:16 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-09 22:47:40 +01:00
|
|
|
class FileListDiffController : public MercurialDiffEditorController
|
|
|
|
{
|
|
|
|
public:
|
2020-02-04 08:11:50 +01:00
|
|
|
FileListDiffController(IDocument *document, const QStringList &fileNames) :
|
2020-02-06 11:52:59 +01:00
|
|
|
MercurialDiffEditorController(document)
|
2018-12-09 22:47:40 +01:00
|
|
|
{
|
2020-02-06 11:52:59 +01:00
|
|
|
setReloader([this, fileNames] {
|
|
|
|
QStringList args { "diff" };
|
|
|
|
args << fileNames;
|
|
|
|
runCommand({addConfigurationArguments(args)});
|
|
|
|
});
|
2018-12-09 22:47:40 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RepositoryDiffController : public MercurialDiffEditorController
|
|
|
|
{
|
|
|
|
public:
|
2020-02-04 08:11:50 +01:00
|
|
|
RepositoryDiffController(IDocument *document) :
|
|
|
|
MercurialDiffEditorController(document)
|
2018-12-09 22:47:40 +01:00
|
|
|
{
|
2020-02-06 11:52:59 +01:00
|
|
|
setReloader([this] {
|
|
|
|
QStringList args = { "diff" };
|
|
|
|
runCommand({addConfigurationArguments(args)});
|
|
|
|
});
|
2018-12-09 22:47:40 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
|
2020-01-24 10:13:02 +01:00
|
|
|
MercurialClient::MercurialClient(MercurialSettings *settings) : VcsBaseClient(settings)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2011-06-10 15:27:57 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2016-07-05 10:34:41 +02:00
|
|
|
const SynchronousProcessResponse result = vcsFullySynchronousExec(repository, args);
|
|
|
|
|
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
|
|
|
|
2016-07-05 10:34:41 +02:00
|
|
|
const QStringList files = result.stdOut().split(QLatin1Char('\n'));
|
2009-11-03 16:38:39 +01:00
|
|
|
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
|
|
|
{
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(workingDir)
|
|
|
|
Q_UNUSED(extraOptions)
|
2011-02-28 13:40:04 +01:00
|
|
|
QDir workingDirectory(srcLocation);
|
2015-04-27 15:03:07 +02:00
|
|
|
const unsigned flags = VcsCommand::SshPasswordPrompt |
|
|
|
|
VcsCommand::ShowStdOut |
|
|
|
|
VcsCommand::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"));
|
2016-07-05 10:34:41 +02:00
|
|
|
const SynchronousProcessResponse resp = vcsFullySynchronousExec(
|
|
|
|
workingDirectory.path(), arguments);
|
|
|
|
if (resp.result != SynchronousProcessResponse::Finished)
|
2011-02-28 13:40:04 +01:00
|
|
|
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;
|
2016-07-05 10:34:41 +02:00
|
|
|
const SynchronousProcessResponse resp1 = vcsSynchronousExec(
|
|
|
|
workingDirectory.path(), arguments, flags);
|
2014-08-27 18:55:41 +02:00
|
|
|
if (resp1.result != SynchronousProcessResponse::Finished)
|
2011-02-28 13:40:04 +01:00
|
|
|
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
|
2014-08-27 18:55:41 +02:00
|
|
|
FileSaver saver(workingDirectory.path() + QLatin1String("/.hg/hgrc"));
|
2012-01-31 10:57:10 +01:00
|
|
|
const QString hgrc = QLatin1String("[paths]\ndefault = ") + dstLocation + QLatin1Char('\n');
|
|
|
|
saver.write(hgrc.toUtf8());
|
2011-03-30 15:15:15 +02:00
|
|
|
if (!saver.finalize()) {
|
2014-08-27 18:55:41 +02:00
|
|
|
VcsOutputWindow::appendError(saver.errorString());
|
2011-03-30 15:15:15 +02:00
|
|
|
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");
|
2016-07-05 10:34:41 +02:00
|
|
|
const SynchronousProcessResponse resp2 = vcsSynchronousExec(
|
|
|
|
workingDirectory.path(), arguments, flags);
|
2014-08-27 18:55:41 +02:00
|
|
|
return resp2.result == SynchronousProcessResponse::Finished;
|
2011-02-28 13:40:04 +01:00
|
|
|
} else {
|
|
|
|
QStringList arguments(QLatin1String("clone"));
|
|
|
|
arguments << dstLocation << workingDirectory.dirName();
|
|
|
|
workingDirectory.cdUp();
|
2016-07-05 10:34:41 +02:00
|
|
|
const SynchronousProcessResponse resp = vcsSynchronousExec(
|
|
|
|
workingDirectory.path(), arguments, flags);
|
2014-08-27 18:55:41 +02:00
|
|
|
return resp.result == SynchronousProcessResponse::Finished;
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 21:55:52 +03:00
|
|
|
bool MercurialClient::synchronousPull(const QString &workingDir, const QString &srcLocation, const QStringList &extraOptions)
|
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
args << vcsCommandString(PullCommand) << extraOptions << srcLocation;
|
|
|
|
// Disable UNIX terminals to suppress SSH prompting
|
|
|
|
const unsigned flags =
|
2015-04-27 15:03:07 +02:00
|
|
|
VcsCommand::SshPasswordPrompt
|
|
|
|
| VcsCommand::ShowStdOut
|
|
|
|
| VcsCommand::ShowSuccessMessage;
|
2013-07-10 21:55:52 +03:00
|
|
|
|
|
|
|
// cause mercurial doesn`t understand LANG
|
|
|
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
|
|
|
env.insert(QLatin1String("LANGUAGE"), QLatin1String("C"));
|
2020-01-22 13:29:46 +01:00
|
|
|
const SynchronousProcessResponse resp = VcsBase::runVcs(
|
2019-06-07 15:27:50 +02:00
|
|
|
workingDir, {vcsBinary(), args}, vcsTimeoutS(), flags, nullptr, env);
|
2014-08-27 18:55:41 +02:00
|
|
|
const bool ok = resp.result == SynchronousProcessResponse::Finished;
|
2013-07-10 21:55:52 +03:00
|
|
|
|
2016-07-05 12:00:59 +02:00
|
|
|
parsePullOutput(resp.stdOut().trimmed());
|
2013-07-10 21:55:52 +03:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2009-12-08 14:28:00 +01:00
|
|
|
QString MercurialClient::branchQuerySync(const QString &repositoryRoot)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2014-02-18 20:50:41 +02:00
|
|
|
QFile branchFile(repositoryRoot + QLatin1String("/.hg/branch"));
|
|
|
|
if (branchFile.open(QFile::ReadOnly)) {
|
|
|
|
const QByteArray branch = branchFile.readAll().trimmed();
|
|
|
|
if (!branch.isEmpty())
|
|
|
|
return QString::fromLocal8Bit(branch);
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2012-06-04 12:15:54 +03:00
|
|
|
QStringList MercurialClient::parentRevisionsSync(const QString &workingDirectory,
|
2010-01-08 09:44:07 +01:00
|
|
|
const QString &file /* = QString() */,
|
2012-06-04 12:15:54 +03:00
|
|
|
const QString &revision)
|
2010-01-08 09:44:07 +01:00
|
|
|
{
|
2012-06-04 12:15:54 +03:00
|
|
|
QStringList parents;
|
2010-01-08 09:44:07 +01:00
|
|
|
QStringList args;
|
|
|
|
args << QLatin1String("parents") << QLatin1String("-r") <<revision;
|
|
|
|
if (!file.isEmpty())
|
|
|
|
args << file;
|
2016-07-05 10:34:41 +02:00
|
|
|
const SynchronousProcessResponse resp = vcsFullySynchronousExec(workingDirectory, args);
|
|
|
|
if (resp.result != SynchronousProcessResponse::Finished)
|
2012-06-04 12:15:54 +03:00
|
|
|
return QStringList();
|
2010-01-08 09:44:07 +01:00
|
|
|
/* Looks like: \code
|
|
|
|
changeset: 0:031a48610fba
|
|
|
|
user: ...
|
|
|
|
\endcode */
|
|
|
|
// Obtain first line and split by blank-delimited tokens
|
2016-07-05 10:34:41 +02:00
|
|
|
const QStringList lines = resp.stdOut().split(QLatin1Char('\n'));
|
2010-01-08 09:44:07 +01:00
|
|
|
if (lines.size() < 1) {
|
2016-07-05 10:34:41 +02:00
|
|
|
VcsOutputWindow::appendSilently(msgParentRevisionFailed(workingDirectory, revision, msgParseParentsOutputFailed(resp.stdOut())));
|
2012-06-04 12:15:54 +03:00
|
|
|
return QStringList();
|
2010-01-08 09:44:07 +01:00
|
|
|
}
|
|
|
|
QStringList changeSets = lines.front().simplified().split(QLatin1Char(' '));
|
|
|
|
if (changeSets.size() < 2) {
|
2016-07-05 10:34:41 +02:00
|
|
|
VcsOutputWindow::appendSilently(msgParentRevisionFailed(workingDirectory, revision, msgParseParentsOutputFailed(resp.stdOut())));
|
2012-06-04 12:15:54 +03:00
|
|
|
return QStringList();
|
2010-01-08 09:44:07 +01:00
|
|
|
}
|
|
|
|
// 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)
|
2012-06-04 12:15:54 +03:00
|
|
|
parents.push_back(it->mid(colonIndex + 1));
|
2010-01-08 09:44:07 +01:00
|
|
|
}
|
2012-06-04 12:15:54 +03:00
|
|
|
return parents;
|
2010-01-08 09:44:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Describe a change using an optional format
|
2012-06-04 12:15:54 +03:00
|
|
|
QString MercurialClient::shortDescriptionSync(const QString &workingDirectory,
|
2010-01-08 09:44:07 +01:00
|
|
|
const QString &revision,
|
2012-06-04 12:15:54 +03:00
|
|
|
const QString &format)
|
2010-01-08 09:44:07 +01:00
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
args << QLatin1String("log") << QLatin1String("-r") <<revision;
|
|
|
|
if (!format.isEmpty())
|
|
|
|
args << QLatin1String("--template") << format;
|
2016-07-05 10:34:41 +02:00
|
|
|
|
|
|
|
const SynchronousProcessResponse resp = vcsFullySynchronousExec(workingDirectory, args);
|
|
|
|
if (resp.result != SynchronousProcessResponse::Finished)
|
2012-06-04 22:06:15 +03:00
|
|
|
return revision;
|
2016-07-05 10:34:41 +02:00
|
|
|
return stripLastNewline(resp.stdOut());
|
2010-01-08 09:44:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default format: "SHA1 (author summmary)"
|
|
|
|
static const char defaultFormatC[] = "{node} ({author|person} {desc|firstline})";
|
|
|
|
|
2012-06-04 12:15:54 +03:00
|
|
|
QString MercurialClient::shortDescriptionSync(const QString &workingDirectory,
|
|
|
|
const QString &revision)
|
2010-01-08 09:44:07 +01:00
|
|
|
{
|
2012-06-04 12:15:54 +03:00
|
|
|
return shortDescriptionSync(workingDirectory, revision, QLatin1String(defaultFormatC));
|
2010-01-08 09:44:07 +01:00
|
|
|
}
|
|
|
|
|
2013-10-02 00:18:39 +03:00
|
|
|
bool MercurialClient::managesFile(const QString &workingDirectory, const QString &fileName) const
|
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
args << QLatin1String("status") << QLatin1String("--unknown") << fileName;
|
2016-07-05 10:34:41 +02:00
|
|
|
return vcsFullySynchronousExec(workingDirectory, args).stdOut().isEmpty();
|
2013-10-02 00:18:39 +03:00
|
|
|
}
|
|
|
|
|
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;
|
2015-01-31 22:11:11 +02:00
|
|
|
if (!repository.isEmpty())
|
|
|
|
id += QLatin1Char('/') + repository;
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
const QString title = tr("Hg incoming %1").arg(id);
|
|
|
|
|
2014-09-02 12:25:20 +02:00
|
|
|
VcsBaseEditorWidget *editor = createVcsEditor(Constants::DIFFLOG_ID, title, repositoryRoot,
|
2015-03-27 16:08:52 +01:00
|
|
|
VcsBaseEditor::getCodec(repositoryRoot),
|
|
|
|
"incoming", id);
|
2014-08-27 18:55:41 +02:00
|
|
|
VcsCommand *cmd = createCommand(repository, editor);
|
2011-10-05 15:32:16 +00:00
|
|
|
enqueueJob(cmd, args);
|
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
|
|
|
|
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
|
|
|
|
2015-03-27 16:08:52 +01:00
|
|
|
VcsBaseEditorWidget *editor = createVcsEditor(Constants::DIFFLOG_ID, title, repositoryRoot,
|
|
|
|
VcsBaseEditor::getCodec(repositoryRoot),
|
2014-08-27 18:55:41 +02:00
|
|
|
"outgoing", repositoryRoot);
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2014-08-27 18:55:41 +02:00
|
|
|
VcsCommand *cmd = createCommand(repositoryRoot, editor);
|
2011-10-05 15:32:16 +00:00
|
|
|
enqueueJob(cmd, args);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
2016-06-13 19:57:45 +03:00
|
|
|
VcsBaseEditorWidget *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");
|
2016-06-13 19:57:45 +03:00
|
|
|
return 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");
|
2012-01-07 12:31:48 +01: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
|
|
|
{
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(extraOptions)
|
2018-12-09 22:47:40 +01:00
|
|
|
|
|
|
|
QString fileName;
|
|
|
|
|
|
|
|
if (files.empty()) {
|
|
|
|
const QString title = tr("Mercurial Diff");
|
|
|
|
const QString sourceFile = VcsBaseEditor::getSource(workingDir, fileName);
|
|
|
|
const QString documentId = QString(Constants::MERCURIAL_PLUGIN)
|
|
|
|
+ ".DiffRepo." + sourceFile;
|
2020-02-04 08:11:50 +01:00
|
|
|
requestReload(documentId, sourceFile, title, workingDir,
|
|
|
|
[](IDocument *doc) { return new RepositoryDiffController(doc); });
|
2018-12-09 22:47:40 +01:00
|
|
|
} else if (files.size() == 1) {
|
|
|
|
fileName = files.at(0);
|
|
|
|
const QString title = tr("Mercurial Diff \"%1\"").arg(fileName);
|
|
|
|
const QString sourceFile = VcsBaseEditor::getSource(workingDir, fileName);
|
|
|
|
const QString documentId = QString(Constants::MERCURIAL_PLUGIN)
|
|
|
|
+ ".DiffFile." + sourceFile;
|
2020-02-04 08:11:50 +01:00
|
|
|
requestReload(documentId, sourceFile, title, workingDir,
|
|
|
|
[fileName](IDocument *doc) { return new FileDiffController(doc, fileName); });
|
2018-12-09 22:47:40 +01:00
|
|
|
} else {
|
|
|
|
const QString title = tr("Mercurial Diff \"%1\"").arg(workingDir);
|
|
|
|
const QString sourceFile = VcsBaseEditor::getSource(workingDir, fileName);
|
|
|
|
const QString documentId = QString(Constants::MERCURIAL_PLUGIN)
|
|
|
|
+ ".DiffFile." + workingDir;
|
2020-02-04 08:11:50 +01:00
|
|
|
requestReload(documentId, sourceFile, title, workingDir,
|
|
|
|
[files](IDocument *doc) { return new FileListDiffController(doc, files); });
|
2018-12-09 22:47:40 +01:00
|
|
|
}
|
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
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseClient::import(repositoryRoot, files,
|
2011-08-23 10:38:44 +00:00
|
|
|
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
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseClient::revertAll(workingDir, revision,
|
2011-08-23 10:38:44 +00:00
|
|
|
QStringList(extraOptions) << QLatin1String("--all"));
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
bool MercurialClient::isVcsDirectory(const FilePath &fileName) const
|
2016-10-20 13:06:11 +02:00
|
|
|
{
|
2019-05-28 16:55:43 +02:00
|
|
|
return fileName.isDir()
|
2016-10-22 21:10:00 +03:00
|
|
|
&& !fileName.fileName().compare(Constants::MERCURIALREPO, HostOsInfo::fileNameCaseSensitivity());
|
2016-10-20 13:06:11 +02: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;
|
2014-11-04 23:50:17 +02:00
|
|
|
args << QLatin1String("-v") << QLatin1String("log")
|
|
|
|
<< QLatin1String("-p") << QLatin1String("-g");
|
2012-01-07 12:31:48 +01:00
|
|
|
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
|
|
|
{
|
2013-06-10 01:12:59 +03:00
|
|
|
const QString repositoryCheckFile = QLatin1String(Constants::MERCURIALREPO) + QLatin1String("/requires");
|
2011-08-23 10:38:44 +00:00
|
|
|
return file.isDir() ?
|
2020-01-22 13:29:46 +01:00
|
|
|
VcsBase::findRepositoryForDirectory(file.absoluteFilePath(), repositoryCheckFile) :
|
|
|
|
VcsBase::findRepositoryForDirectory(file.absolutePath(), repositoryCheckFile);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
2014-08-27 18:55:41 +02:00
|
|
|
Core::Id MercurialClient::vcsEditorKind(VcsCommandTag cmd) const
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2013-03-19 15:23:04 +01:00
|
|
|
switch (cmd) {
|
|
|
|
case AnnotateCommand:
|
2014-09-02 12:25:20 +02:00
|
|
|
return Constants::ANNOTATELOG_ID;
|
2013-03-19 15:23:04 +01:00
|
|
|
case DiffCommand:
|
2014-09-02 12:25:20 +02:00
|
|
|
return Constants::DIFFLOG_ID;
|
2013-03-19 15:23:04 +01:00
|
|
|
case LogCommand:
|
2014-09-02 12:25:20 +02:00
|
|
|
return Constants::FILELOG_ID;
|
2013-03-19 15:23:04 +01:00
|
|
|
default:
|
|
|
|
return Core::Id();
|
2011-08-23 10:38:44 +00:00
|
|
|
}
|
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
|
2015-03-01 08:16:18 +02:00
|
|
|
item.file = QDir::fromNativeSeparators(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
|
|
|
|
2018-12-09 22:47:40 +01:00
|
|
|
void MercurialClient::requestReload(const QString &documentId, const QString &source, const QString &title,
|
2020-02-04 08:11:50 +01:00
|
|
|
const QString &workingDirectory,
|
|
|
|
std::function<VcsBaseDiffEditorController *(Core::IDocument *)> factory)
|
2018-12-09 22:47:40 +01:00
|
|
|
{
|
|
|
|
// Creating document might change the referenced source. Store a copy and use it.
|
|
|
|
const QString sourceCopy = source;
|
|
|
|
|
|
|
|
IDocument *document = DiffEditorController::findOrCreateDocument(documentId, title);
|
|
|
|
QTC_ASSERT(document, return);
|
2020-02-04 08:11:50 +01:00
|
|
|
VcsBaseDiffEditorController *controller = factory(document);
|
2018-12-09 22:47:40 +01:00
|
|
|
QTC_ASSERT(controller, return);
|
2020-02-04 08:11:50 +01:00
|
|
|
controller->setVcsBinary(settings().binaryPath());
|
|
|
|
controller->setVcsTimeoutS(settings().vcsTimeoutS());
|
|
|
|
controller->setProcessEnvironment(processEnvironment());
|
|
|
|
controller->setWorkingDirectory(workingDirectory);
|
2018-12-09 22:47:40 +01:00
|
|
|
|
2020-01-22 13:29:46 +01:00
|
|
|
VcsBase::setSource(document, sourceCopy);
|
2018-12-09 22:47:40 +01:00
|
|
|
EditorManager::activateEditorForDocument(document);
|
|
|
|
controller->requestReload();
|
|
|
|
}
|
|
|
|
|
2013-07-10 21:55:52 +03:00
|
|
|
void MercurialClient::parsePullOutput(const QString &output)
|
|
|
|
{
|
|
|
|
if (output.endsWith(QLatin1String("no changes found")))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (output.endsWith(QLatin1String("(run 'hg update' to get a working copy)"))) {
|
|
|
|
emit needUpdate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output.endsWith(QLatin1String("'hg merge' to merge)")))
|
|
|
|
emit needMerge();
|
|
|
|
}
|
|
|
|
|
2009-12-04 12:58:01 +01:00
|
|
|
} // namespace Internal
|
|
|
|
} // namespace Mercurial
|