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"
|
|
|
|
#include "constants.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>
|
|
|
|
#include <vcsbase/vcsbaseeditorparameterwidget.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>
|
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
|
|
|
|
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 {
|
|
|
|
|
2015-01-20 17:42:16 +01:00
|
|
|
// Parameter widget controlling whitespace diff mode, associated with a parameter
|
|
|
|
class MercurialDiffParameterWidget : public VcsBaseEditorParameterWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-03-26 12:22:29 +01:00
|
|
|
MercurialDiffParameterWidget(VcsBaseClientSettings &settings, QWidget *parent = 0) :
|
2015-01-20 17:42:16 +01:00
|
|
|
VcsBaseEditorParameterWidget(parent)
|
|
|
|
{
|
|
|
|
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
|
2015-03-26 12:22:29 +01:00
|
|
|
settings.boolPointer(MercurialSettings::diffIgnoreWhiteSpaceKey));
|
2015-01-20 17:42:16 +01:00
|
|
|
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
|
2015-03-26 12:22:29 +01:00
|
|
|
settings.boolPointer(MercurialSettings::diffIgnoreBlankLinesKey));
|
2015-01-20 17:42:16 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-27 15:24:45 +01:00
|
|
|
MercurialClient::MercurialClient() : VcsBaseClient(new MercurialSettings)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2015-03-26 12:22:29 +01:00
|
|
|
setDiffParameterWidgetCreator([this] { return new MercurialDiffParameterWidget(settings()); });
|
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
|
|
|
|
|
|
|
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;
|
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"));
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!vcsFullySynchronousExec(workingDirectory.path(), arguments, &output))
|
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;
|
2014-08-27 18:55:41 +02:00
|
|
|
const SynchronousProcessResponse resp1 =
|
2011-02-28 13:40:04 +01:00
|
|
|
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");
|
2014-08-27 18:55:41 +02:00
|
|
|
const SynchronousProcessResponse resp2 =
|
2011-02-28 13:40:04 +01:00
|
|
|
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();
|
2014-08-27 18:55:41 +02:00
|
|
|
const SynchronousProcessResponse resp =
|
2011-02-28 13:40:04 +01:00
|
|
|
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"));
|
2014-08-27 18:55:41 +02:00
|
|
|
const SynchronousProcessResponse resp = VcsBasePlugin::runVcs(
|
2015-04-10 14:44:17 +02:00
|
|
|
workingDir, vcsBinary(), args, vcsTimeoutS(), flags, 0, env);
|
2014-08-27 18:55:41 +02:00
|
|
|
const bool ok = resp.result == SynchronousProcessResponse::Finished;
|
2013-07-10 21:55:52 +03:00
|
|
|
|
|
|
|
parsePullOutput(resp.stdOut.trimmed());
|
|
|
|
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;
|
|
|
|
QByteArray outputData;
|
2011-02-28 13:40:04 +01:00
|
|
|
if (!vcsFullySynchronousExec(workingDirectory, args, &outputData))
|
2012-06-04 12:15:54 +03:00
|
|
|
return QStringList();
|
2014-08-27 18:55:41 +02:00
|
|
|
const QString output = SynchronousProcess::normalizeNewlines(
|
2013-08-02 12:15:04 +03:00
|
|
|
QString::fromLocal8Bit(outputData));
|
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
|
|
|
|
const QStringList lines = output.split(QLatin1Char('\n'));
|
|
|
|
if (lines.size() < 1) {
|
2014-08-26 00:02:47 +02:00
|
|
|
VcsOutputWindow::appendSilently(msgParentRevisionFailed(workingDirectory, revision, msgParseParentsOutputFailed(output)));
|
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) {
|
2014-08-26 00:02:47 +02:00
|
|
|
VcsOutputWindow::appendSilently(msgParentRevisionFailed(workingDirectory, revision, msgParseParentsOutputFailed(output)));
|
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
|
|
|
{
|
2012-06-04 12:15:54 +03:00
|
|
|
QString description;
|
2010-01-08 09:44:07 +01:00
|
|
|
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))
|
2012-06-04 22:06:15 +03:00
|
|
|
return revision;
|
2015-04-10 15:23:20 +02:00
|
|
|
description = commandOutputFromLocal8Bit(outputData);
|
2012-06-04 12:15:54 +03:00
|
|
|
if (description.endsWith(QLatin1Char('\n')))
|
|
|
|
description.truncate(description.size() - 1);
|
|
|
|
return description;
|
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;
|
|
|
|
QByteArray output;
|
|
|
|
vcsFullySynchronousExec(workingDirectory, args, &output);
|
|
|
|
return output.isEmpty();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
void MercurialClient::annotate(const QString &workingDir, const QString &file,
|
2014-05-05 16:59:56 +03:00
|
|
|
const QString &revision, int lineNumber,
|
2011-08-23 10:38:44 +00:00
|
|
|
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");
|
2012-01-07 12:31:48 +01:00
|
|
|
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
|
|
|
{
|
2011-08-23 10:38:44 +00:00
|
|
|
QStringList args(extraOptions);
|
|
|
|
args << QLatin1String("-g") << QLatin1String("-p") << QLatin1String("-U 8");
|
2012-01-07 12:31:48 +01:00
|
|
|
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
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
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() ?
|
2014-08-27 18:55:41 +02:00
|
|
|
VcsBasePlugin::findRepositoryForDirectory(file.absoluteFilePath(), repositoryCheckFile) :
|
|
|
|
VcsBasePlugin::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
|
|
|
|
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
|
2011-03-28 11:59:26 +02:00
|
|
|
|
|
|
|
#include "mercurialclient.moc"
|