Commit 72da839b authored by Jarek Kobus's avatar Jarek Kobus Committed by Jarek Kobus

Use VcsBaseClient::diff instead of cvs's one

The second step in cleaning a mess in VCS

Change-Id: I3eb360825480c74242110b0da9f90b39fc4c767f
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@digia.com>
parent 0f4808a6
......@@ -68,7 +68,7 @@ VcsBase::Command *CheckoutWizard::createCommand(const QList<QWizardPage*> &param
const CheckoutWizardPage *cwp = qobject_cast<const CheckoutWizardPage *>(parameterPages.front());
QTC_ASSERT(cwp, return 0);
const CvsSettings settings = CvsPlugin::instance()->settings();
const QString binary = settings.cvsBinaryPath;
const QString binary = settings.binaryPath();
QStringList args;
const QString repository = cwp->repository();
args << QLatin1String("checkout") << repository;
......
......@@ -2,6 +2,7 @@ include(../../qtcreatorplugin.pri)
HEADERS += annotationhighlighter.h \
cvsplugin.h \
cvsclient.h \
cvscontrol.h \
settingspage.h \
cvseditor.h \
......@@ -14,6 +15,7 @@ HEADERS += annotationhighlighter.h \
SOURCES += annotationhighlighter.cpp \
cvsplugin.cpp \
cvsclient.cpp \
cvscontrol.cpp \
settingspage.cpp \
cvseditor.cpp \
......
......@@ -20,6 +20,8 @@ QtcPlugin {
"checkoutwizardpage.cpp",
"checkoutwizardpage.h",
"cvs.qrc",
"cvsclient.cpp",
"cvsclient.h",
"cvsconstants.h",
"cvscontrol.cpp",
"cvscontrol.h",
......
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "cvsclient.h"
#include "cvssettings.h"
#include "cvsconstants.h"
#include <vcsbase/vcsbaseplugin.h>
#include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/vcsbaseconstants.h>
#include <vcsbase/vcsbaseeditorparameterwidget.h>
#include <utils/synchronousprocess.h>
#include <QDir>
#include <QFileInfo>
#include <QTextStream>
#include <QDebug>
namespace Cvs {
namespace Internal {
class CvsDiffExitCodeInterpreter : public Utils::ExitCodeInterpreter
{
Q_OBJECT
public:
CvsDiffExitCodeInterpreter(QObject *parent) : Utils::ExitCodeInterpreter(parent) {}
Utils::SynchronousProcessResponse::Result interpretExitCode(int code) const;
};
Utils::SynchronousProcessResponse::Result CvsDiffExitCodeInterpreter::interpretExitCode(int code) const
{
if (code < 0 || code > 2)
return Utils::SynchronousProcessResponse::FinishedError;
return Utils::SynchronousProcessResponse::Finished;
}
// 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 CvsDiffParameters
{
QString workingDir;
QStringList extraOptions;
QStringList files;
};
// Parameter widget controlling whitespace diff mode, associated with a parameter
class CvsDiffParameterWidget : public VcsBase::VcsBaseEditorParameterWidget
{
Q_OBJECT
public:
explicit CvsDiffParameterWidget(CvsClient *client,
const CvsDiffParameters &p,
QWidget *parent = 0);
QStringList arguments() const;
void executeCommand();
private:
CvsClient *m_client;
const CvsDiffParameters m_params;
};
CvsDiffParameterWidget::CvsDiffParameterWidget(CvsClient *client,
const CvsDiffParameters &p,
QWidget *parent)
: VcsBase::VcsBaseEditorParameterWidget(parent), m_client(client), m_params(p)
{
mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")),
client->settings()->boolPointer(CvsSettings::diffIgnoreWhiteSpaceKey));
mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")),
client->settings()->boolPointer(CvsSettings::diffIgnoreBlankLinesKey));
}
QStringList CvsDiffParameterWidget::arguments() const
{
QStringList args;
args = m_client->settings()->stringValue(CvsSettings::diffOptionsKey).split(QLatin1Char(' '), QString::SkipEmptyParts);
args += VcsBaseEditorParameterWidget::arguments();
return args;
}
void CvsDiffParameterWidget::executeCommand()
{
m_client->diff(m_params.workingDir, m_params.files, m_params.extraOptions);
}
CvsClient::CvsClient(CvsSettings *settings) :
VcsBase::VcsBaseClient(settings)
{
}
CvsSettings *CvsClient::settings() const
{
return dynamic_cast<CvsSettings *>(VcsBase::VcsBaseClient::settings());
}
Core::Id CvsClient::vcsEditorKind(VcsCommand cmd) const
{
switch (cmd) {
case DiffCommand:
return "CVS Diff Editor"; // TODO: replace by string from cvsconstants.h
default:
return Core::Id();
}
}
Utils::ExitCodeInterpreter *CvsClient::exitCodeInterpreter(VcsCommand cmd, QObject *parent) const
{
switch (cmd) {
case DiffCommand:
return new CvsDiffExitCodeInterpreter(parent);
default:
return 0;
}
}
void CvsClient::diff(const QString &workingDir, const QStringList &files,
const QStringList &extraOptions)
{
VcsBaseClient::diff(workingDir, files, extraOptions);
}
QString CvsClient::findTopLevelForFile(const QFileInfo &file) const
{
Q_UNUSED(file)
return QString();
}
QStringList CvsClient::revisionSpec(const QString &revision) const
{
Q_UNUSED(revision)
return QStringList();
}
VcsBase::VcsBaseClient::StatusItem CvsClient::parseStatusLine(const QString &line) const
{
Q_UNUSED(line)
return VcsBase::VcsBaseClient::StatusItem();
}
VcsBase::VcsBaseEditorParameterWidget *CvsClient::createDiffEditor(
const QString &workingDir, const QStringList &files, const QStringList &extraOptions)
{
Q_UNUSED(extraOptions)
CvsDiffParameters p;
p.workingDir = workingDir;
p.files = files;
p.extraOptions = extraOptions;
return new CvsDiffParameterWidget(this, p);
}
} // namespace Internal
} // namespace Cvs
#include "cvsclient.moc"
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CVSCLIENT_H
#define CVSCLIENT_H
#include "cvssettings.h"
#include <vcsbase/vcsbaseclient.h>
namespace Cvs {
namespace Internal {
class CvsSettings;
class CvsClient : public VcsBase::VcsBaseClient
{
Q_OBJECT
public:
CvsClient(CvsSettings *settings);
CvsSettings *settings() const;
void diff(const QString &workingDir, const QStringList &files,
const QStringList &extraOptions = QStringList());
QString findTopLevelForFile(const QFileInfo &file) const;
QStringList revisionSpec(const QString &revision) const;
StatusItem parseStatusLine(const QString &line) const;
protected:
Utils::ExitCodeInterpreter *exitCodeInterpreter(VcsCommand cmd, QObject *parent) const;
Core::Id vcsEditorKind(VcsCommand cmd) const;
VcsBase::VcsBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
const QStringList &files,
const QStringList &extraOptions);
private:
};
} // namespace Internal
} // namespace Cvs
#endif // CVSCLIENT_H
......@@ -55,7 +55,7 @@ Core::Id CvsControl::id() const
bool CvsControl::isConfigured() const
{
const QString binary = m_plugin->settings().cvsBinaryPath;
const QString binary = m_plugin->settings().binaryPath();
if (binary.isEmpty())
return false;
QFileInfo fi(binary);
......
This diff is collapsed.
......@@ -56,6 +56,7 @@ namespace Internal {
struct CvsDiffParameters;
class CvsSubmitEditor;
class CvsControl;
class CvsClient;
struct CvsResponse
{
......@@ -79,8 +80,6 @@ public:
bool initialize(const QStringList &arguments, QString *errorMessage);
void cvsDiff(const QString &workingDir, const QStringList &files);
CvsSubmitEditor *openCVSSubmitEditor(const QString &fileName);
CvsSettings settings() const;
......@@ -124,7 +123,6 @@ private slots:
void editCurrentFile();
void uneditCurrentFile();
void uneditCurrentRepository();
void cvsDiff(const Cvs::Internal::CvsDiffParameters &p);
#ifdef WITH_TESTS
void testDiffFileResolving_data();
void testDiffFileResolving();
......@@ -168,6 +166,8 @@ private:
inline CvsControl *cvsVersionControl() const;
CvsSettings m_settings;
CvsClient *m_client;
QString m_commitMessageFileName;
QString m_commitRepository;
......
......@@ -35,71 +35,34 @@
#include <QSettings>
#include <QTextStream>
static const char groupC[] = "CVS";
static const char commandKeyC[] = "Command";
static const char rootC[] = "Root";
static const char promptToSubmitKeyC[] = "PromptForSubmit";
static const char diffOptionsKeyC[] = "DiffOptions";
static const char describeByCommitIdKeyC[] = "DescribeByCommitId";
static const char defaultDiffOptions[] = "-du";
static const char timeOutKeyC[] = "TimeOut";
enum { defaultTimeOutS = 30 };
static QString defaultCommand()
{
return QLatin1String("cvs" QTC_HOST_EXE_SUFFIX);
}
namespace Cvs {
namespace Internal {
CvsSettings::CvsSettings() :
cvsCommand(defaultCommand()),
cvsDiffOptions(QLatin1String(defaultDiffOptions)),
timeOutS(defaultTimeOutS),
promptToSubmit(true),
describeByCommitId(true)
{
}
const QLatin1String CvsSettings::cvsRootKey("Root");
const QLatin1String CvsSettings::diffOptionsKey("DiffOptions");
const QLatin1String CvsSettings::describeByCommitIdKey("DescribeByCommitId");
const QLatin1String CvsSettings::diffIgnoreWhiteSpaceKey("DiffIgnoreWhiteSpace");
const QLatin1String CvsSettings::diffIgnoreBlankLinesKey("DiffIgnoreBlankLines");
void CvsSettings::fromSettings(QSettings *settings)
CvsSettings::CvsSettings()
{
settings->beginGroup(QLatin1String(groupC));
cvsCommand = settings->value(QLatin1String(commandKeyC), defaultCommand()).toString();
cvsBinaryPath = Utils::Environment::systemEnvironment().searchInPath(cvsCommand);
promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
cvsRoot = settings->value(QLatin1String(rootC), QString()).toString();
cvsDiffOptions = settings->value(QLatin1String(diffOptionsKeyC), QLatin1String(defaultDiffOptions)).toString();
describeByCommitId = settings->value(QLatin1String(describeByCommitIdKeyC), true).toBool();
timeOutS = settings->value(QLatin1String(timeOutKeyC), defaultTimeOutS).toInt();
settings->endGroup();
setSettingsGroup(QLatin1String("CVS"));
declareKey(binaryPathKey, QLatin1String("cvs" QTC_HOST_EXE_SUFFIX));
declareKey(cvsRootKey, QLatin1String(""));
declareKey(diffOptionsKey, QLatin1String("-du"));
declareKey(describeByCommitIdKey, true);
declareKey(diffIgnoreWhiteSpaceKey, false);
declareKey(diffIgnoreBlankLinesKey, false);
}
void CvsSettings::toSettings(QSettings *settings) const
int CvsSettings::timeOutMs() const
{
settings->beginGroup(QLatin1String(groupC));
settings->setValue(QLatin1String(commandKeyC), cvsCommand);
settings->setValue(QLatin1String(promptToSubmitKeyC), promptToSubmit);
settings->setValue(QLatin1String(rootC), cvsRoot);
settings->setValue(QLatin1String(diffOptionsKeyC), cvsDiffOptions);
settings->setValue(QLatin1String(timeOutKeyC), timeOutS);
settings->setValue(QLatin1String(describeByCommitIdKeyC), describeByCommitId);
settings->endGroup();
}
bool CvsSettings::equals(const CvsSettings &s) const
{
return promptToSubmit == s.promptToSubmit
&& describeByCommitId == s.describeByCommitId
&& cvsCommand == s.cvsCommand
&& cvsRoot == s.cvsRoot
&& timeOutS == s.timeOutS
&& cvsDiffOptions == s.cvsDiffOptions;
return 1000 * intValue(timeoutKey);
}
QStringList CvsSettings::addOptions(const QStringList &args) const
{
const QString cvsRoot = stringValue(cvsRootKey);
if (cvsRoot.isEmpty())
return args;
......@@ -110,5 +73,19 @@ QStringList CvsSettings::addOptions(const QStringList &args) const
return rc;
}
void CvsSettings::readLegacySettings(const QSettings *settings)
{
const QString keyRoot = settingsGroup() + QLatin1Char('/');
const QString oldBinaryPathKey = keyRoot + QLatin1String("Command");
const QString oldPromptOnSubmitKey = keyRoot + QLatin1String("PromptForSubmit");
const QString oldTimeoutKey = keyRoot + QLatin1String("TimeOut");
if (settings->contains(oldBinaryPathKey))
this->setValue(binaryPathKey, settings->value(oldBinaryPathKey).toString());
if (settings->contains(oldPromptOnSubmitKey))
this->setValue(promptOnSubmitKey, settings->value(oldPromptOnSubmitKey).toBool());
if (settings->contains(oldTimeoutKey))
this->setValue(timeoutKey, settings->value(oldTimeoutKey).toInt());
}
} // namespace Internal
} // namespace Cvs
......@@ -30,44 +30,30 @@
#ifndef CVSSETTINGS_H
#define CVSSETTINGS_H
#include <QStringList>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
#include <vcsbase/vcsbaseclientsettings.h>
namespace Cvs {
namespace Internal {
struct CvsSettings
class CvsSettings : public VcsBase::VcsBaseClientSettings
{
CvsSettings();
public:
static const QLatin1String cvsRootKey;
static const QLatin1String diffOptionsKey;
static const QLatin1String describeByCommitIdKey;
static const QLatin1String diffIgnoreWhiteSpaceKey;
static const QLatin1String diffIgnoreBlankLinesKey;
void fromSettings(QSettings *);
void toSettings(QSettings *) const;
CvsSettings();
int timeOutMS() const { return timeOutS * 1000; }
int longTimeOutMS() const { return timeOutS * 10000; }
int timeOutMs() const;
// Add common options to the command line
QStringList addOptions(const QStringList &args) const;
bool equals(const CvsSettings &s) const;
QString cvsCommand;
QString cvsBinaryPath;
QString cvsRoot;
QString cvsDiffOptions;
int timeOutS;
bool promptToSubmit;
bool describeByCommitId;
protected:
void readLegacySettings(const QSettings *settings);
};
inline bool operator==(const CvsSettings &p1, const CvsSettings &p2)
{ return p1.equals(p2); }
inline bool operator!=(const CvsSettings &p1, const CvsSettings &p2)
{ return !p1.equals(p2); }
} // namespace Internal
} // namespace Cvs
......
......@@ -54,24 +54,23 @@ SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
CvsSettings SettingsPageWidget::settings() const
{
CvsSettings rc;
rc.cvsCommand = m_ui.commandPathChooser->rawPath();
rc.cvsBinaryPath = m_ui.commandPathChooser->path();
rc.cvsRoot = m_ui.rootLineEdit->text();
rc.cvsDiffOptions = m_ui.diffOptionsLineEdit->text();
rc.timeOutS = m_ui.timeOutSpinBox->value();
rc.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
rc.describeByCommitId = m_ui.describeByCommitIdCheckBox->isChecked();
rc.setValue(CvsSettings::binaryPathKey, m_ui.commandPathChooser->rawPath());
rc.setValue(CvsSettings::cvsRootKey, m_ui.rootLineEdit->text());
rc.setValue(CvsSettings::diffOptionsKey, m_ui.diffOptionsLineEdit->text());
rc.setValue(CvsSettings::timeoutKey, m_ui.timeOutSpinBox->value());
rc.setValue(CvsSettings::promptOnSubmitKey, m_ui.promptToSubmitCheckBox->isChecked());
rc.setValue(CvsSettings::describeByCommitIdKey, m_ui.describeByCommitIdCheckBox->isChecked());
return rc;
}
void SettingsPageWidget::setSettings(const CvsSettings &s)
{
m_ui.commandPathChooser->setPath(s.cvsCommand);
m_ui.rootLineEdit->setText(s.cvsRoot);
m_ui.diffOptionsLineEdit->setText(s.cvsDiffOptions);
m_ui.timeOutSpinBox->setValue(s.timeOutS);
m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit);
m_ui.describeByCommitIdCheckBox->setChecked(s.describeByCommitId);
m_ui.commandPathChooser->setPath(s.binaryPath());
m_ui.rootLineEdit->setText(s.stringValue(CvsSettings::cvsRootKey));
m_ui.diffOptionsLineEdit->setText(s.stringValue(CvsSettings::diffOptionsKey));
m_ui.timeOutSpinBox->setValue(s.intValue(CvsSettings::timeoutKey));
m_ui.promptToSubmitCheckBox->setChecked(s.boolValue(CvsSettings::promptOnSubmitKey));
m_ui.describeByCommitIdCheckBox->setChecked(s.boolValue(CvsSettings::describeByCommitIdKey));
}
QString SettingsPageWidget::searchKeywords() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment