2011-02-28 13:40:06 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 Hugues Delorme
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2011-02-28 13:40:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-28 13:40: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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2011-02-28 13:40:06 +01:00
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-02-28 13:40:06 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-02-28 13:40:06 +01:00
|
|
|
#include "bazaarclient.h"
|
|
|
|
#include "constants.h"
|
|
|
|
|
2015-02-26 09:33:24 +01:00
|
|
|
#include <coreplugin/id.h>
|
|
|
|
|
2011-02-28 13:40:06 +01:00
|
|
|
#include <vcsbase/vcsbaseplugin.h>
|
2014-08-26 00:02:47 +02:00
|
|
|
#include <vcsbase/vcsoutputwindow.h>
|
2011-03-28 11:59:26 +02:00
|
|
|
#include <vcsbase/vcsbaseeditorparameterwidget.h>
|
2013-09-24 16:40:10 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
2011-03-28 11:59:26 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QTextStream>
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2011-02-28 13:40:06 +01:00
|
|
|
|
2014-08-27 18:55:41 +02:00
|
|
|
using namespace Utils;
|
2014-08-26 00:02:47 +02:00
|
|
|
using namespace VcsBase;
|
|
|
|
|
2011-02-28 13:40:06 +01:00
|
|
|
namespace Bazaar {
|
|
|
|
namespace Internal {
|
|
|
|
|
2014-08-27 18:55:41 +02:00
|
|
|
class BazaarDiffExitCodeInterpreter : public ExitCodeInterpreter
|
2013-09-24 16:40:10 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-08-27 18:55:41 +02:00
|
|
|
BazaarDiffExitCodeInterpreter(QObject *parent) : ExitCodeInterpreter(parent) {}
|
|
|
|
SynchronousProcessResponse::Result interpretExitCode(int code) const;
|
2013-09-24 16:40:10 +02:00
|
|
|
};
|
|
|
|
|
2014-08-27 18:55:41 +02:00
|
|
|
SynchronousProcessResponse::Result BazaarDiffExitCodeInterpreter::interpretExitCode(int code) const
|
2013-09-24 16:40:10 +02:00
|
|
|
{
|
|
|
|
if (code < 0 || code > 2)
|
2014-08-27 18:55:41 +02:00
|
|
|
return SynchronousProcessResponse::FinishedError;
|
|
|
|
return SynchronousProcessResponse::Finished;
|
2013-09-24 16:40:10 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 17:42:16 +01:00
|
|
|
// Parameter widget controlling whitespace diff mode, associated with a parameter
|
|
|
|
class BazaarDiffParameterWidget : public VcsBaseEditorParameterWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-03-26 12:22:29 +01:00
|
|
|
BazaarDiffParameterWidget(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(BazaarSettings::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(BazaarSettings::diffIgnoreBlankLinesKey));
|
2015-01-20 17:42:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList arguments() const
|
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
// Bazaar wants "--diff-options=-w -B.."
|
|
|
|
const QStringList formatArguments = VcsBaseEditorParameterWidget::arguments();
|
|
|
|
if (!formatArguments.isEmpty()) {
|
|
|
|
const QString a = QLatin1String("--diff-options=")
|
|
|
|
+ formatArguments.join(QString(QLatin1Char(' ')));
|
|
|
|
args.append(a);
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BazaarLogParameterWidget : public VcsBaseEditorParameterWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-03-26 12:22:29 +01:00
|
|
|
BazaarLogParameterWidget(VcsBaseClientSettings &settings, QWidget *parent = 0) :
|
2015-01-20 17:42:16 +01:00
|
|
|
VcsBaseEditorParameterWidget(parent)
|
|
|
|
{
|
|
|
|
mapSetting(addToggleButton(QLatin1String("--verbose"), tr("Verbose"),
|
2015-03-27 10:36:10 +01:00
|
|
|
tr("Show files changed in each revision.")),
|
2015-03-26 12:22:29 +01:00
|
|
|
settings.boolPointer(BazaarSettings::logVerboseKey));
|
2015-01-20 17:42:16 +01:00
|
|
|
mapSetting(addToggleButton(QLatin1String("--forward"), tr("Forward"),
|
2015-03-27 10:36:10 +01:00
|
|
|
tr("Show from oldest to newest.")),
|
2015-03-26 12:22:29 +01:00
|
|
|
settings.boolPointer(BazaarSettings::logForwardKey));
|
2015-03-27 10:36:10 +01:00
|
|
|
mapSetting(addToggleButton(QLatin1String("--include-merges"), tr("Include Merges"),
|
|
|
|
tr("Show merged revisions.")),
|
2015-03-26 12:22:29 +01:00
|
|
|
settings.boolPointer(BazaarSettings::logIncludeMergesKey));
|
2015-01-20 17:42:16 +01:00
|
|
|
|
|
|
|
QList<ComboBoxItem> logChoices;
|
|
|
|
logChoices << ComboBoxItem(tr("Detailed"), QLatin1String("long"))
|
2015-03-27 10:36:10 +01:00
|
|
|
<< ComboBoxItem(tr("Moderately Short"), QLatin1String("short"))
|
|
|
|
<< ComboBoxItem(tr("One Line"), QLatin1String("line"))
|
|
|
|
<< ComboBoxItem(tr("GNU Change Log"), QLatin1String("gnu-changelog"));
|
2015-01-20 17:42:16 +01:00
|
|
|
mapSetting(addComboBox(QStringList(QLatin1String("--log-format=%1")), logChoices),
|
2015-03-26 12:22:29 +01:00
|
|
|
settings.stringPointer(BazaarSettings::logFormatKey));
|
2015-01-20 17:42:16 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-26 12:22:29 +01:00
|
|
|
BazaarClient::BazaarClient() :
|
|
|
|
VcsBaseClient(new BazaarSettings)
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
2015-03-26 12:22:29 +01:00
|
|
|
setDiffParameterWidgetCreator([this] { return new BazaarDiffParameterWidget(settings()); });
|
|
|
|
setLogParameterWidgetCreator([this] { return new BazaarLogParameterWidget(settings()); });
|
2011-06-10 14:02:46 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 15:47:45 +01:00
|
|
|
bool BazaarClient::synchronousSetUserId()
|
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
args << QLatin1String("whoami")
|
2015-03-26 12:22:29 +01:00
|
|
|
<< (settings().stringValue(BazaarSettings::userNameKey) + QLatin1String(" <")
|
|
|
|
+ settings().stringValue(BazaarSettings::userEmailKey) + QLatin1Char('>'));
|
2011-03-15 15:47:45 +01:00
|
|
|
QByteArray stdOut;
|
|
|
|
return vcsFullySynchronousExec(QDir::currentPath(), args, &stdOut);
|
|
|
|
}
|
|
|
|
|
2011-02-28 13:40:06 +01:00
|
|
|
BranchInfo BazaarClient::synchronousBranchQuery(const QString &repositoryRoot) const
|
|
|
|
{
|
2015-01-31 22:11:11 +02:00
|
|
|
QFile branchConfFile(repositoryRoot + QLatin1Char('/') +
|
2011-02-28 13:40:06 +01:00
|
|
|
QLatin1String(Constants::BAZAARREPO) +
|
|
|
|
QLatin1String("/branch/branch.conf"));
|
|
|
|
if (!branchConfFile.open(QIODevice::ReadOnly))
|
|
|
|
return BranchInfo(QString(), false);
|
|
|
|
|
|
|
|
QTextStream ts(&branchConfFile);
|
|
|
|
QString branchLocation;
|
|
|
|
QString isBranchBound;
|
2012-04-30 12:01:15 +02:00
|
|
|
QRegExp branchLocationRx(QLatin1String("bound_location\\s*=\\s*(.+)$"));
|
|
|
|
QRegExp isBranchBoundRx(QLatin1String("bound\\s*=\\s*(.+)$"));
|
2011-02-28 13:40:06 +01:00
|
|
|
while (!ts.atEnd() && (branchLocation.isEmpty() || isBranchBound.isEmpty())) {
|
|
|
|
const QString line = ts.readLine();
|
|
|
|
if (branchLocationRx.indexIn(line) != -1)
|
|
|
|
branchLocation = branchLocationRx.cap(1);
|
|
|
|
else if (isBranchBoundRx.indexIn(line) != -1)
|
|
|
|
isBranchBound = isBranchBoundRx.cap(1);
|
|
|
|
}
|
|
|
|
if (isBranchBound.simplified().toLower() == QLatin1String("true"))
|
|
|
|
return BranchInfo(branchLocation, true);
|
|
|
|
return BranchInfo(repositoryRoot, false);
|
|
|
|
}
|
|
|
|
|
2013-12-06 14:56:24 +01:00
|
|
|
//! Removes the last committed revision(s)
|
|
|
|
bool BazaarClient::synchronousUncommit(const QString &workingDir,
|
|
|
|
const QString &revision,
|
|
|
|
const QStringList &extraOptions)
|
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
args << QLatin1String("uncommit")
|
|
|
|
<< QLatin1String("--force") // Say yes to all questions
|
|
|
|
<< QLatin1String("--verbose") // Will print out what is being removed
|
|
|
|
<< revisionSpec(revision)
|
|
|
|
<< extraOptions;
|
|
|
|
QByteArray stdOut;
|
|
|
|
const bool success = vcsFullySynchronousExec(workingDir, args, &stdOut);
|
|
|
|
if (!stdOut.isEmpty())
|
2014-08-26 00:02:47 +02:00
|
|
|
VcsOutputWindow::append(QString::fromUtf8(stdOut));
|
2013-12-06 14:56:24 +01:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
void BazaarClient::commit(const QString &repositoryRoot, const QStringList &files,
|
|
|
|
const QString &commitMessageFile, const QStringList &extraOptions)
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseClient::commit(repositoryRoot, files, commitMessageFile,
|
2011-08-23 10:38:44 +00:00
|
|
|
QStringList(extraOptions) << QLatin1String("-F") << commitMessageFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BazaarClient::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)
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseClient::annotate(workingDir, file, revision, lineNumber,
|
2011-08-23 10:38:44 +00:00
|
|
|
QStringList(extraOptions) << QLatin1String("--long"));
|
|
|
|
}
|
|
|
|
|
2011-02-28 13:40:06 +01:00
|
|
|
QString BazaarClient::findTopLevelForFile(const QFileInfo &file) const
|
|
|
|
{
|
|
|
|
const QString repositoryCheckFile =
|
|
|
|
QLatin1String(Constants::BAZAARREPO) + QLatin1String("/branch-format");
|
|
|
|
return file.isDir() ?
|
2014-08-27 18:55:41 +02:00
|
|
|
VcsBasePlugin::findRepositoryForDirectory(file.absoluteFilePath(),
|
|
|
|
repositoryCheckFile) :
|
|
|
|
VcsBasePlugin::findRepositoryForDirectory(file.absolutePath(),
|
|
|
|
repositoryCheckFile);
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
2013-10-02 00:18:39 +03:00
|
|
|
bool BazaarClient::managesFile(const QString &workingDirectory, const QString &fileName) const
|
|
|
|
{
|
|
|
|
QStringList args(QLatin1String("status"));
|
|
|
|
args << fileName;
|
|
|
|
QByteArray stdOut;
|
|
|
|
if (!vcsFullySynchronousExec(workingDirectory, args, &stdOut))
|
|
|
|
return false;
|
|
|
|
return !stdOut.startsWith("unknown");
|
|
|
|
}
|
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
void BazaarClient::view(const QString &source, const QString &id, const QStringList &extraOptions)
|
|
|
|
{
|
|
|
|
QStringList args(QLatin1String("log"));
|
|
|
|
args << QLatin1String("-p") << QLatin1String("-v") << extraOptions;
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBaseClient::view(source, id, args);
|
2011-08-23 10:38:44 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 18:55:41 +02:00
|
|
|
Core::Id BazaarClient::vcsEditorKind(VcsCommandTag cmd) const
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
2012-11-28 20:44:03 +02:00
|
|
|
switch (cmd) {
|
2011-02-28 15:05:40 +01:00
|
|
|
case AnnotateCommand:
|
2014-09-02 12:25:20 +02:00
|
|
|
return Constants::ANNOTATELOG_ID;
|
2011-02-28 15:05:40 +01:00
|
|
|
case DiffCommand:
|
2014-09-02 12:25:20 +02:00
|
|
|
return Constants::DIFFLOG_ID;
|
2011-02-28 15:05:40 +01:00
|
|
|
case LogCommand:
|
2014-09-02 12:25:20 +02:00
|
|
|
return Constants::FILELOG_ID;
|
2011-02-28 15:05:40 +01:00
|
|
|
default:
|
2013-03-19 15:23:04 +01:00
|
|
|
return Core::Id();
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 18:55:41 +02:00
|
|
|
QString BazaarClient::vcsCommandString(VcsCommandTag cmd) const
|
2012-02-01 11:24:54 +01:00
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case CloneCommand:
|
|
|
|
return QLatin1String("branch");
|
|
|
|
default:
|
|
|
|
return VcsBaseClient::vcsCommandString(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 18:55:41 +02:00
|
|
|
ExitCodeInterpreter *BazaarClient::exitCodeInterpreter(VcsCommandTag cmd, QObject *parent) const
|
2013-09-24 16:40:10 +02:00
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case DiffCommand:
|
|
|
|
return new BazaarDiffExitCodeInterpreter(parent);
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-23 10:38:44 +00:00
|
|
|
QStringList BazaarClient::revisionSpec(const QString &revision) const
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
if (!revision.isEmpty())
|
|
|
|
args << QLatin1String("-r") << revision;
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2011-08-22 15:33:03 +00:00
|
|
|
BazaarClient::StatusItem BazaarClient::parseStatusLine(const QString &line) const
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
2011-08-22 15:33:03 +00:00
|
|
|
StatusItem item;
|
2011-02-28 13:40:06 +01:00
|
|
|
if (!line.isEmpty()) {
|
|
|
|
const QChar flagVersion = line[0];
|
|
|
|
if (flagVersion == QLatin1Char('+'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Versioned");
|
2011-02-28 13:40:06 +01:00
|
|
|
else if (flagVersion == QLatin1Char('-'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Unversioned");
|
2011-02-28 13:40:06 +01:00
|
|
|
else if (flagVersion == QLatin1Char('R'))
|
2015-03-11 17:52:26 +01:00
|
|
|
item.flags = QLatin1String(Constants::FSTATUS_RENAMED);
|
2011-02-28 13:40:06 +01:00
|
|
|
else if (flagVersion == QLatin1Char('?'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Unknown");
|
2011-02-28 13:40:06 +01:00
|
|
|
else if (flagVersion == QLatin1Char('X'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Nonexistent");
|
2011-02-28 13:40:06 +01:00
|
|
|
else if (flagVersion == QLatin1Char('C'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Conflict");
|
2011-02-28 13:40:06 +01:00
|
|
|
else if (flagVersion == QLatin1Char('P'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("PendingMerge");
|
2011-02-28 13:40:06 +01:00
|
|
|
|
|
|
|
const int lineLength = line.length();
|
|
|
|
if (lineLength >= 2) {
|
|
|
|
const QChar flagContents = line[1];
|
|
|
|
if (flagContents == QLatin1Char('N'))
|
2015-03-11 17:52:26 +01:00
|
|
|
item.flags = QLatin1String(Constants::FSTATUS_CREATED);
|
2011-02-28 13:40:06 +01:00
|
|
|
else if (flagContents == QLatin1Char('D'))
|
2015-03-11 17:52:26 +01:00
|
|
|
item.flags = QLatin1String(Constants::FSTATUS_DELETED);
|
2011-02-28 13:40:06 +01:00
|
|
|
else if (flagContents == QLatin1Char('K'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("KindChanged");
|
2011-02-28 13:40:06 +01:00
|
|
|
else if (flagContents == QLatin1Char('M'))
|
2015-03-11 17:52:26 +01:00
|
|
|
item.flags = QLatin1String(Constants::FSTATUS_MODIFIED);
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
if (lineLength >= 3) {
|
|
|
|
const QChar flagExec = line[2];
|
|
|
|
if (flagExec == QLatin1Char('*'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("ExecuteBitChanged");
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
// The status string should be similar to "xxx 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(4);
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
2011-08-22 15:33:03 +00:00
|
|
|
return item;
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
2011-11-10 16:06:19 +01:00
|
|
|
} // namespace Internal
|
2011-02-28 13:40:06 +01:00
|
|
|
} // namespace Bazaar
|
2011-03-28 11:59:26 +02:00
|
|
|
|
|
|
|
#include "bazaarclient.moc"
|