Commit e6bbf52f authored by cerf's avatar cerf Committed by Tobias Hunger
Browse files

Get rid of VCSBaseClient::ExtraCommandOptions



It is replaced by QStringList, allowing a simpler approach to add extra
arguments to a command.
The Bazaar and Mercurial VCS plugins are impacted by this change

Merge-request: 325
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent c647c7b2
......@@ -45,31 +45,6 @@
#include <QtCore/QTextStream>
#include <QtCore/QtDebug>
namespace {
void addBoolArgument(const QVariant &optionValue,
const QString &optionName,
QStringList *arguments)
{
if (arguments == 0)
return;
Q_ASSERT(optionValue.canConvert(QVariant::Bool));
if (optionValue.toBool())
arguments->append(optionName);
}
void addRevisionArgument(const QVariant &optionValue, QStringList *arguments)
{
if (arguments == 0)
return;
Q_ASSERT(optionValue.canConvert(QVariant::String));
const QString revision = optionValue.toString();
if (!revision.isEmpty())
(*arguments) << QLatin1String("-r") << revision;
}
} // Anonymous namespace
namespace Bazaar {
namespace Internal {
......@@ -139,42 +114,9 @@ QString BazaarClient::vcsEditorKind(VCSCommand cmd) const
QStringList BazaarClient::cloneArguments(const QString &srcLocation,
const QString &dstLocation,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
QStringList args;
// Fetch extra options
foreach (int iOption, extraOptions.keys()) {
const QVariant iOptValue = extraOptions[iOption];
switch (iOption) {
case UseExistingDirCloneOptionId :
::addBoolArgument(iOptValue, QLatin1String("--use-existing-dir"), &args);
break;
case StackedCloneOptionId :
::addBoolArgument(iOptValue, QLatin1String("--stacked"), &args);
break;
case StandAloneCloneOptionId :
::addBoolArgument(iOptValue, QLatin1String("--standalone"), &args);
break;
case BindCloneOptionId :
::addBoolArgument(iOptValue, QLatin1String("--bind"), &args);
break;
case SwitchCloneOptionId :
::addBoolArgument(iOptValue, QLatin1String("--switch"), &args);
break;
case HardLinkCloneOptionId :
::addBoolArgument(iOptValue, QLatin1String("--hardlink"), &args);
break;
case NoTreeCloneOptionId :
::addBoolArgument(iOptValue, QLatin1String("--no-tree"), &args);
break;
case RevisionCloneOptionId :
::addRevisionArgument(iOptValue, &args);
break;
default :
Q_ASSERT(false); // Invalid option !
}
} // end foreach ()
// Add arguments for common options
QStringList args(extraOptions);
args << srcLocation;
if (!dstLocation.isEmpty())
args << dstLocation;
......@@ -182,51 +124,18 @@ QStringList BazaarClient::cloneArguments(const QString &srcLocation,
}
QStringList BazaarClient::pullArguments(const QString &srcLocation,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
// Fetch extra options
QStringList args(commonPullOrPushArguments(extraOptions));
foreach (int iOption, extraOptions.keys()) {
const QVariant iOptValue = extraOptions[iOption];
switch (iOption) {
case RememberPullOrPushOptionId : break;
case OverwritePullOrPushOptionId : break;
case RevisionPullOrPushOptionId : break;
case LocalPullOptionId :
::addBoolArgument(iOptValue, QLatin1String("--local"), &args);
break;
default :
Q_ASSERT(false); // Invalid option !
}
} // end foreach ()
// Add arguments for common options
QStringList args(extraOptions);
if (!srcLocation.isEmpty())
args << srcLocation;
return args;
}
QStringList BazaarClient::pushArguments(const QString &dstLocation,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
// Fetch extra options
QStringList args(commonPullOrPushArguments(extraOptions));
foreach (int iOption, extraOptions.keys()) {
const QVariant iOptValue = extraOptions[iOption];
switch (iOption) {
case RememberPullOrPushOptionId : break;
case OverwritePullOrPushOptionId : break;
case RevisionPullOrPushOptionId : break;
case UseExistingDirPushOptionId :
::addBoolArgument(iOptValue, QLatin1String("--use-existing-dir"), &args);
break;
case CreatePrefixPushOptionId :
::addBoolArgument(iOptValue, QLatin1String("--create-prefix"), &args);
break;
default :
Q_ASSERT(false); // Invalid option !
}
} // end foreach ()
// Add arguments for common options
QStringList args(extraOptions);
if (!dstLocation.isEmpty())
args << dstLocation;
return args;
......@@ -234,38 +143,9 @@ QStringList BazaarClient::pushArguments(const QString &dstLocation,
QStringList BazaarClient::commitArguments(const QStringList &files,
const QString &commitMessageFile,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
QStringList args;
// Fetch extra options
foreach (int iOption, extraOptions.keys()) {
const QVariant iOptValue = extraOptions[iOption];
switch (iOption) {
case AuthorCommitOptionId :
{
Q_ASSERT(iOptValue.canConvert(QVariant::String));
const QString committerInfo = iOptValue.toString();
if (!committerInfo.isEmpty())
args << QString("--author=%1").arg(committerInfo);
break;
}
case FixesCommitOptionId :
{
Q_ASSERT(iOptValue.canConvert(QVariant::StringList));
foreach (const QString& iFix, iOptValue.toStringList()) {
if (!iFix.isEmpty())
args << QLatin1String("--fixes") << iFix;
}
break;
}
case LocalCommitOptionId :
::addBoolArgument(iOptValue, QLatin1String("--local"), &args);
break;
default :
Q_ASSERT(false); // Invalid option !
}
} // end foreach ()
// Add arguments for common options
QStringList args(extraOptions);
args << QLatin1String("-F") << commitMessageFile;
args << files;
return args;
......@@ -318,29 +198,16 @@ QStringList BazaarClient::annotateArguments(const QString &file,
}
QStringList BazaarClient::diffArguments(const QStringList &files,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
QStringList args;
foreach (const QVariant &extraOption, extraOptions) {
switch (extraOption.type()) {
case QVariant::String:
args.append(extraOption.toString());
break;
case QVariant::StringList:
args.append(extraOption.toStringList());
break;
default:
QTC_ASSERT(false, continue; )
break;
}
}
QStringList args(extraOptions);
if (!files.isEmpty())
args.append(files);
return args;
}
QStringList BazaarClient::logArguments(const QStringList &files,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
return diffArguments(files, extraOptions);
}
......@@ -406,35 +273,13 @@ QPair<QString, QString> BazaarClient::parseStatusLine(const QString &line) const
return status;
}
QStringList BazaarClient::commonPullOrPushArguments(const ExtraCommandOptions &extraOptions) const
{
QStringList args;
foreach (int iOption, extraOptions.keys()) {
const QVariant iOptValue = extraOptions[iOption];
switch (iOption) {
case RememberPullOrPushOptionId :
::addBoolArgument(iOptValue, QLatin1String("--remember"), &args);
break;
case OverwritePullOrPushOptionId :
::addBoolArgument(iOptValue, QLatin1String("--overwrite"), &args);
break;
case RevisionPullOrPushOptionId :
::addRevisionArgument(iOptValue, &args);
break;
default :
break; // Unknown option, do nothing
}
} // end foreach ()
return args;
}
// 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 BazaarDiffParameters
{
QString workingDir;
QStringList files;
VCSBase::VCSBaseClient::ExtraCommandOptions extraOptions;
QStringList extraOptions;
};
// Parameter widget controlling whitespace diff mode, associated with a parameter
......@@ -470,7 +315,7 @@ void BazaarDiffParameterWidget::triggerReRun()
if (!formatArguments.isEmpty()) {
const QString a = QLatin1String("--diff-options=")
+ formatArguments.join(QString(QLatin1Char(' ')));
effectiveParameters.extraOptions.insert(42, QVariant(a));
effectiveParameters.extraOptions.append(a);
}
emit reRunDiff(effectiveParameters);
}
......@@ -481,7 +326,7 @@ void BazaarClient::bazaarDiff(const Bazaar::Internal::BazaarDiffParameters &p)
}
void BazaarClient::initializeDiffEditor(const QString &workingDir, const QStringList &files,
const VCSBase::VCSBaseClient::ExtraCommandOptions &extra,
const QStringList &extraOptions,
VCSBase::VCSBaseEditorWidget *diffEditorWidget)
{
// Wire up the parameter widget to trigger a re-run on
......@@ -489,7 +334,7 @@ void BazaarClient::initializeDiffEditor(const QString &workingDir, const QString
BazaarDiffParameters parameters;
parameters.workingDir = workingDir;
parameters.files = files;
parameters.extraOptions = extra;
parameters.extraOptions = extraOptions;
diffEditorWidget->setRevertDiffChunkEnabled(true);
BazaarDiffParameterWidget *pw = new BazaarDiffParameterWidget(parameters);
connect(pw, SIGNAL(reRunDiff(Bazaar::Internal::BazaarDiffParameters)),
......
......@@ -44,32 +44,6 @@ class BazaarClient : public VCSBase::VCSBaseClient
{
Q_OBJECT
public:
enum ExtraOptionId
{
// Clone
UseExistingDirCloneOptionId,
StackedCloneOptionId,
StandAloneCloneOptionId,
BindCloneOptionId,
SwitchCloneOptionId,
HardLinkCloneOptionId,
NoTreeCloneOptionId,
RevisionCloneOptionId,
// Commit
AuthorCommitOptionId,
FixesCommitOptionId,
LocalCommitOptionId,
// Pull or push (common options)
RememberPullOrPushOptionId,
OverwritePullOrPushOptionId,
RevisionPullOrPushOptionId,
// Pull only
LocalPullOptionId,
// Push only
UseExistingDirPushOptionId,
CreatePrefixPushOptionId
};
BazaarClient(const VCSBase::VCSBaseClientSettings &settings);
bool synchronousSetUserId();
......@@ -84,14 +58,14 @@ protected:
QStringList cloneArguments(const QString &srcLocation,
const QString &dstLocation,
const ExtraCommandOptions &extraOptions) const;
const QStringList &extraOptions) const;
QStringList pullArguments(const QString &srcLocation,
const ExtraCommandOptions &extraOptions) const;
const QStringList &extraOptions) const;
QStringList pushArguments(const QString &dstLocation,
const ExtraCommandOptions &extraOptions) const;
const QStringList &extraOptions) const;
QStringList commitArguments(const QStringList &files,
const QString &commitMessageFile,
const ExtraCommandOptions &extraOptions) const;
const QStringList &extraOptions) const;
QStringList importArguments(const QStringList &files) const;
QStringList updateArguments(const QString &revision) const;
QStringList revertArguments(const QString &file, const QString &revision) const;
......@@ -99,18 +73,17 @@ protected:
QStringList annotateArguments(const QString &file,
const QString &revision, int lineNumber) const;
QStringList diffArguments(const QStringList &files,
const ExtraCommandOptions &extraOptions) const;
const QStringList &extraOptions) const;
void initializeDiffEditor(const QString &workingDir, const QStringList &files,
const VCSBase::VCSBaseClient::ExtraCommandOptions &extra,
const QStringList &extraOptions,
VCSBase::VCSBaseEditorWidget *diffEditorWidget);
QStringList logArguments(const QStringList &files,
const ExtraCommandOptions &extraOptions) const;
const QStringList &extraOptions) const;
QStringList statusArguments(const QString &file) const;
QStringList viewArguments(const QString &revision) const;
QPair<QString, QString> parseStatusLine(const QString &line) const;
private:
QStringList commonPullOrPushArguments(const ExtraCommandOptions &extraOptions) const;
friend class CloneWizard;
};
......
......@@ -319,7 +319,7 @@ void BazaarPlugin::logCurrentFile()
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return);
m_client->log(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()),
BazaarClient::ExtraCommandOptions(), true);
QStringList(), true);
}
void BazaarPlugin::revertCurrentFile()
......@@ -461,11 +461,15 @@ void BazaarPlugin::pull()
PullOrPushDialog dialog(PullOrPushDialog::PullMode);
if (dialog.exec() != QDialog::Accepted)
return;
BazaarClient::ExtraCommandOptions extraOptions;
extraOptions[BazaarClient::RememberPullOrPushOptionId] = dialog.isRememberOptionEnabled();
extraOptions[BazaarClient::OverwritePullOrPushOptionId] = dialog.isOverwriteOptionEnabled();
extraOptions[BazaarClient::RevisionPullOrPushOptionId] = dialog.revision();
extraOptions[BazaarClient::LocalPullOptionId] = dialog.isLocalOptionEnabled();
QStringList extraOptions;
if (dialog.isRememberOptionEnabled())
extraOptions += QLatin1String("--remember");
if (dialog.isOverwriteOptionEnabled())
extraOptions += QLatin1String("--overwrite");
if (dialog.isLocalOptionEnabled())
extraOptions += QLatin1String("--local");
if (!dialog.revision().isEmpty())
extraOptions << QLatin1String("-r") << dialog.revision();
m_client->synchronousPull(state.topLevel(), dialog.branchLocation(), extraOptions);
}
......@@ -477,12 +481,17 @@ void BazaarPlugin::push()
PullOrPushDialog dialog(PullOrPushDialog::PushMode);
if (dialog.exec() != QDialog::Accepted)
return;
BazaarClient::ExtraCommandOptions extraOptions;
extraOptions[BazaarClient::RememberPullOrPushOptionId] = dialog.isRememberOptionEnabled();
extraOptions[BazaarClient::OverwritePullOrPushOptionId] = dialog.isOverwriteOptionEnabled();
extraOptions[BazaarClient::RevisionPullOrPushOptionId] = dialog.revision();
extraOptions[BazaarClient::UseExistingDirPushOptionId] = dialog.isUseExistingDirectoryOptionEnabled();
extraOptions[BazaarClient::CreatePrefixPushOptionId] = dialog.isCreatePrefixOptionEnabled();
QStringList extraOptions;
if (dialog.isRememberOptionEnabled())
extraOptions += QLatin1String("--remember");
if (dialog.isOverwriteOptionEnabled())
extraOptions += QLatin1String("--overwrite");
if (dialog.isUseExistingDirectoryOptionEnabled())
extraOptions += QLatin1String("--use-existing-dir");
if (dialog.isCreatePrefixOptionEnabled())
extraOptions += QLatin1String("--create-prefix");
if (!dialog.revision().isEmpty())
extraOptions << QLatin1String("-r") << dialog.revision();
m_client->synchronousPush(state.topLevel(), dialog.branchLocation(), extraOptions);
}
......@@ -643,10 +652,18 @@ bool BazaarPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submit
}
const BazaarCommitWidget* commitWidget = commitEditor->commitWidget();
BazaarClient::ExtraCommandOptions extraOptions;
extraOptions[BazaarClient::AuthorCommitOptionId] = commitWidget->committer();
extraOptions[BazaarClient::FixesCommitOptionId] = commitWidget->fixedBugs();
extraOptions[BazaarClient::LocalCommitOptionId] = commitWidget->isLocalOptionEnabled();
QStringList extraOptions;
// Author
if (!commitWidget->committer().isEmpty())
extraOptions.append(QLatin1String("--author=") + commitWidget->committer());
// Fixed bugs
foreach (const QString &fix, commitWidget->fixedBugs()) {
if (!fix.isEmpty())
extraOptions << QLatin1String("--fixes") << fix;
}
// Whether local commit or not
if (commitWidget->isLocalOptionEnabled())
extraOptions += QLatin1String("--local");
m_client->commit(m_submitRepository, files, editorFile->fileName(), extraOptions);
}
return true;
......
......@@ -93,15 +93,23 @@ QSharedPointer<VCSBase::AbstractCheckoutJob> CloneWizard::createJob(const QList<
*checkoutPath = page->path() + QLatin1Char('/') + page->directory();
const CloneOptionsPanel *panel = page->cloneOptionsPanel();
BazaarClient::ExtraCommandOptions extraOptions;
extraOptions[BazaarClient::UseExistingDirCloneOptionId] = panel->isUseExistingDirectoryOptionEnabled();
extraOptions[BazaarClient::StackedCloneOptionId] = panel->isStackedOptionEnabled();
extraOptions[BazaarClient::StandAloneCloneOptionId] = panel->isStandAloneOptionEnabled();
extraOptions[BazaarClient::BindCloneOptionId] = panel->isBindOptionEnabled();
extraOptions[BazaarClient::SwitchCloneOptionId] = panel->isSwitchOptionEnabled();
extraOptions[BazaarClient::HardLinkCloneOptionId] = panel->isHardLinkOptionEnabled();
extraOptions[BazaarClient::NoTreeCloneOptionId] = panel->isNoTreeOptionEnabled();
extraOptions[BazaarClient::RevisionCloneOptionId] = panel->revision();
QStringList extraOptions;
if (panel->isUseExistingDirectoryOptionEnabled())
extraOptions += QLatin1String("--use-existing-dir");
if (panel->isStackedOptionEnabled())
extraOptions += QLatin1String("--stacked");
if (panel->isStandAloneOptionEnabled())
extraOptions += QLatin1String("--standalone");
if (panel->isBindOptionEnabled())
extraOptions += QLatin1String("--bind");
if (panel->isSwitchOptionEnabled())
extraOptions += QLatin1String("--switch");
if (panel->isHardLinkOptionEnabled())
extraOptions += QLatin1String("--hardlink");
if (panel->isNoTreeOptionEnabled())
extraOptions += QLatin1String("--no-tree");
if (!panel->revision().isEmpty())
extraOptions << QLatin1String("-r") << panel->revision();
const BazaarClient *client = BazaarPlugin::instance()->client();
args << client->vcsCommandString(BazaarClient::CloneCommand)
<< client->cloneArguments(page->repository(), page->directory(), extraOptions);
......
......@@ -79,7 +79,7 @@ bool MercurialClient::manifestSync(const QString &repository, const QString &rel
bool MercurialClient::synchronousClone(const QString &workingDir,
const QString &srcLocation,
const QString &dstLocation,
const ExtraCommandOptions &extraOptions)
const QStringList &extraOptions)
{
Q_UNUSED(workingDir);
Q_UNUSED(extraOptions);
......@@ -320,7 +320,7 @@ QString MercurialClient::vcsEditorKind(VCSCommand cmd) const
QStringList MercurialClient::cloneArguments(const QString &srcLocation,
const QString &dstLocation,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
Q_UNUSED(srcLocation);
Q_UNUSED(dstLocation);
......@@ -330,7 +330,7 @@ QStringList MercurialClient::cloneArguments(const QString &srcLocation,
}
QStringList MercurialClient::pullArguments(const QString &srcLocation,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
Q_UNUSED(extraOptions);
QStringList args;
......@@ -341,7 +341,7 @@ QStringList MercurialClient::pullArguments(const QString &srcLocation,
}
QStringList MercurialClient::pushArguments(const QString &dstLocation,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
Q_UNUSED(extraOptions);
QStringList args;
......@@ -353,36 +353,11 @@ QStringList MercurialClient::pushArguments(const QString &dstLocation,
QStringList MercurialClient::commitArguments(const QStringList &files,
const QString &commitMessageFile,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
QStringList args(QLatin1String("--noninteractive"));
// Fetch extra options
foreach (int iOption, extraOptions.keys())
{
const QVariant iOptValue = extraOptions[iOption];
switch (iOption)
{
case AuthorCommitOptionId :
{
Q_ASSERT(iOptValue.canConvert(QVariant::String));
const QString committerInfo = iOptValue.toString();
if (!committerInfo.isEmpty())
args << QLatin1String("-u") << committerInfo;
break;
}
case AutoAddRemoveCommitOptionId :
{
Q_ASSERT(iOptValue.canConvert(QVariant::Bool));
const bool autoAddRemove = iOptValue.toBool();
if (autoAddRemove)
args << QLatin1String("-A");
break;
}
default :
Q_ASSERT(false); // Invalid option !
}
} // end foreach ()
// Add arguments for common options
if (!args.isEmpty())
args.append(extraOptions);
args << QLatin1String("-l") << commitMessageFile;
args << files;
return args;
......@@ -435,30 +410,19 @@ QStringList MercurialClient::annotateArguments(const QString &file,
}
QStringList MercurialClient::diffArguments(const QStringList &files,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
QStringList args;
args << QLatin1String("-g") << QLatin1String("-p") << QLatin1String("-U 8");
foreach (const QVariant &extraOption, extraOptions) {
switch (extraOption.type()) {
case QVariant::String:
args.append(extraOption.toString());
break;
case QVariant::StringList:
args.append(extraOption.toStringList());
break;
default:
QTC_ASSERT(false, continue; )
break;
}
}
if (!args.isEmpty())
args.append(extraOptions);
if (!files.isEmpty())
args.append(files);
return args;
}
QStringList MercurialClient::logArguments(const QStringList &files,
const ExtraCommandOptions &extraOptions) const
const QStringList &extraOptions) const
{
Q_UNUSED(extraOptions);
QStringList args;
......@@ -514,7 +478,7 @@ struct MercurialDiffParameters
{
QString workingDir;
QStringList files;
VCSBase::VCSBaseClient::ExtraCommandOptions extraOptions;
QStringList extraOptions;
};
// Parameter widget controlling whitespace diff mode, associated with a parameter
......@@ -545,7 +509,7 @@ MercurialDiffParameterWidget::MercurialDiffParameterWidget(const MercurialDiffPa
void MercurialDiffParameterWidget::triggerReRun()
{
MercurialDiffParameters effectiveParameters = m_parameters;
effectiveParameters.extraOptions.insert(42, QVariant(arguments()));
effectiveParameters.extraOptions += arguments();
emit reRunDiff(effectiveParameters);
}
......@@ -555,7 +519,7 @@ void MercurialClient::mercurialDiff(const Mercurial::Internal::MercurialDiffPara
}
void MercurialClient::initializeDiffEditor(const QString &workingDir, const QStringList &files,
const VCSBase::VCSBaseClient::ExtraCommandOptions &extra,
const QStringList &extraOptions,
VCSBase::VCSBaseEditorWidget *diffEditorWidget)
{
// Wire up the parameter widget to trigger a re-run on
......@@ -563,7 +527,7 @@ void MercurialClient::initializeDiffEditor(const QString &workingDir, const QStr
MercurialDiffParameters parameters;
parameters.workingDir = workingDir;
parameters.files = files;
parameters.extraOptions = extra;
parameters.extraOptions = extraOptions;
diffEditorWidget->setRevertDiffChunkEnabled(true);
MercurialDiffParameterWidget *pw = new MercurialDiffParameterWidget(parameters);
connect(pw, SIGNAL(reRunDiff(Mercurial::Internal::MercurialDiffParameters)),
......
......@@ -43,18 +43,11 @@ class MercurialClient : public VCSBase::VCSBaseClient
{