2011-02-28 13:40:06 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
|
|
|
** Copyright (c) 2010 Hugues Delorme
|
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-02-28 13:40: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.
|
2011-02-28 13:40:06 +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
|
2011-02-28 13:40:06 +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.
|
|
|
|
**
|
2011-02-28 13:40:06 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-02-28 13:40:06 +01:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "bazaarclient.h"
|
|
|
|
#include "constants.h"
|
|
|
|
|
2011-03-15 15:47:45 +01:00
|
|
|
#include <vcsbase/vcsbaseclientsettings.h>
|
2011-02-28 13:40:06 +01:00
|
|
|
#include <vcsbase/vcsbaseplugin.h>
|
2011-03-28 11:59:26 +02:00
|
|
|
#include <vcsbase/vcsbaseeditor.h>
|
|
|
|
#include <vcsbase/vcsbaseeditorparameterwidget.h>
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
2011-02-28 13:40:06 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QtDebug>
|
2011-02-28 13:40:06 +01:00
|
|
|
|
|
|
|
namespace Bazaar {
|
|
|
|
namespace Internal {
|
|
|
|
|
2011-06-10 14:02:46 +00:00
|
|
|
BazaarClient::BazaarClient(BazaarSettings *settings) :
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBase::VcsBaseClient(settings)
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-06-10 14:02:46 +00:00
|
|
|
BazaarSettings *BazaarClient::settings() const
|
|
|
|
{
|
2012-01-07 12:31:48 +01:00
|
|
|
return dynamic_cast<BazaarSettings *>(VcsBase::VcsBaseClient::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")
|
2012-01-31 10:57:10 +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
|
|
|
|
{
|
|
|
|
QFile branchConfFile(repositoryRoot + QDir::separator() +
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
const QString revision, int lineNumber,
|
|
|
|
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() ?
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBase::VcsBasePlugin::findRepositoryForDirectory(file.absoluteFilePath(),
|
2011-02-28 13:40:06 +01:00
|
|
|
repositoryCheckFile) :
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBase::VcsBasePlugin::findRepositoryForDirectory(file.absolutePath(),
|
2011-02-28 13:40:06 +01:00
|
|
|
repositoryCheckFile);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
QString BazaarClient::vcsEditorKind(VcsCommand cmd) const
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
|
|
|
switch(cmd) {
|
2011-02-28 15:05:40 +01:00
|
|
|
case AnnotateCommand:
|
|
|
|
return QLatin1String(Constants::ANNOTATELOG);
|
|
|
|
case DiffCommand:
|
|
|
|
return QLatin1String(Constants::DIFFLOG);
|
|
|
|
case LogCommand:
|
|
|
|
return QLatin1String(Constants::FILELOG);
|
|
|
|
default:
|
|
|
|
return QString();
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 11:24:54 +01:00
|
|
|
QString BazaarClient::vcsCommandString(VcsCommand cmd) const
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case CloneCommand:
|
|
|
|
return QLatin1String("branch");
|
|
|
|
default:
|
|
|
|
return VcsBaseClient::vcsCommandString(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("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'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("Created");
|
2011-02-28 13:40:06 +01:00
|
|
|
else if (flagContents == QLatin1Char('D'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("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'))
|
2011-08-22 15:33:03 +00:00
|
|
|
item.flags = QLatin1String("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-06-10 15:27:57 +00:00
|
|
|
// Collect all parameters required for a diff or log to be able to associate
|
|
|
|
// them with an editor and re-run the command with parameters.
|
|
|
|
struct BazaarCommandParameters
|
2011-03-28 11:59:26 +02:00
|
|
|
{
|
2011-06-10 15:27:57 +00:00
|
|
|
BazaarCommandParameters(const QString &workDir,
|
|
|
|
const QStringList &inFiles,
|
|
|
|
const QStringList &options) :
|
|
|
|
workingDir(workDir), files(inFiles), extraOptions(options)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-28 11:59:26 +02:00
|
|
|
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
|
2012-01-07 12:31:48 +01:00
|
|
|
class BazaarDiffParameterWidget : public VcsBase::VcsBaseEditorParameterWidget
|
2011-03-28 11:59:26 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2011-06-10 15:27:57 +00:00
|
|
|
BazaarDiffParameterWidget(BazaarClient *client,
|
|
|
|
const BazaarCommandParameters &p, QWidget *parent = 0) :
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBase::VcsBaseEditorParameterWidget(parent), m_client(client), m_params(p)
|
2011-06-10 15:27:57 +00:00
|
|
|
{
|
|
|
|
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore whitespace")),
|
2011-09-14 09:13:44 +00:00
|
|
|
client->settings()->boolPointer(BazaarSettings::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(BazaarSettings::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
|
|
|
QStringList arguments() const
|
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
// Bazaar wants "--diff-options=-w -B.."
|
2012-01-07 12:31:48 +01:00
|
|
|
const QStringList formatArguments = VcsBaseEditorParameterWidget::arguments();
|
2011-06-10 15:27:57 +00:00
|
|
|
if (!formatArguments.isEmpty()) {
|
|
|
|
const QString a = QLatin1String("--diff-options=")
|
2011-11-10 16:06:19 +01:00
|
|
|
+ formatArguments.join(QString(QLatin1Char(' ')));
|
2011-06-10 15:27:57 +00:00
|
|
|
args.append(a);
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|
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
|
|
|
BazaarClient *m_client;
|
|
|
|
const BazaarCommandParameters m_params;
|
2011-03-28 11:59:26 +02:00
|
|
|
};
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBase::VcsBaseEditorParameterWidget *BazaarClient::createDiffEditor(
|
2011-11-10 16:06:19 +01:00
|
|
|
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
|
2011-03-28 11:59:26 +02:00
|
|
|
{
|
2011-06-10 15:27:57 +00:00
|
|
|
const BazaarCommandParameters parameters(workingDir, files, extraOptions);
|
|
|
|
return new BazaarDiffParameterWidget(this, parameters);
|
2011-03-28 11:59:26 +02:00
|
|
|
}
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
class BazaarLogParameterWidget : public VcsBase::VcsBaseEditorParameterWidget
|
2011-07-28 10:22:11 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
BazaarLogParameterWidget(BazaarClient *client,
|
|
|
|
const BazaarCommandParameters &p, QWidget *parent = 0) :
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBase::VcsBaseEditorParameterWidget(parent), m_client(client), m_params(p)
|
2011-07-28 10:22:11 +00:00
|
|
|
{
|
|
|
|
mapSetting(addToggleButton(QLatin1String("--verbose"), tr("Verbose"),
|
|
|
|
tr("Show files changed in each revision")),
|
2011-09-14 09:13:44 +00:00
|
|
|
m_client->settings()->boolPointer(BazaarSettings::logVerboseKey));
|
2011-07-28 10:22:11 +00:00
|
|
|
mapSetting(addToggleButton(QLatin1String("--forward"), tr("Forward"),
|
|
|
|
tr("Show from oldest to newest")),
|
2011-09-14 09:13:44 +00:00
|
|
|
m_client->settings()->boolPointer(BazaarSettings::logForwardKey));
|
2011-07-28 10:22:11 +00:00
|
|
|
mapSetting(addToggleButton(QLatin1String("--include-merges"), tr("Include merges"),
|
|
|
|
tr("Show merged revisions")),
|
2011-09-14 09:13:44 +00:00
|
|
|
m_client->settings()->boolPointer(BazaarSettings::logIncludeMergesKey));
|
2011-07-28 10:22:11 +00:00
|
|
|
|
|
|
|
QList<ComboBoxItem> logChoices;
|
|
|
|
logChoices << ComboBoxItem(tr("Detailed"), QLatin1String("long"))
|
|
|
|
<< ComboBoxItem(tr("Moderately short"), QLatin1String("short"))
|
|
|
|
<< ComboBoxItem(tr("One line"), QLatin1String("line"))
|
|
|
|
<< ComboBoxItem(tr("GNU ChangeLog"), QLatin1String("gnu-changelog"));
|
|
|
|
mapSetting(addComboBox(QLatin1String("--log-format"), logChoices),
|
2011-09-14 09:13:44 +00:00
|
|
|
m_client->settings()->stringPointer(BazaarSettings::logFormatKey));
|
2011-07-28 10:22:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void executeCommand()
|
|
|
|
{
|
|
|
|
m_client->log(m_params.workingDir, m_params.files, m_params.extraOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-09-21 11:43:58 +02:00
|
|
|
BazaarClient *m_client;
|
2011-07-28 10:22:11 +00:00
|
|
|
const BazaarCommandParameters m_params;
|
|
|
|
};
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBase::VcsBaseEditorParameterWidget *BazaarClient::createLogEditor(
|
2011-11-10 16:06:19 +01:00
|
|
|
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
|
2011-07-28 10:22:11 +00:00
|
|
|
{
|
|
|
|
const BazaarCommandParameters parameters(workingDir, files, extraOptions);
|
|
|
|
return new BazaarLogParameterWidget(this, parameters);
|
|
|
|
}
|
|
|
|
|
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"
|