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

vcsbase: overhaul *Arguments() methods in VCSBaseClient



Refactor how sub VCS clients redefine commands like diff, log, ...
This allows sensible code shrinks in Bazaar and Mercurial plugins

Change-Id: Ifeaf366c5c1c2eee776ce5d6bc748c3872e53f5a
Merge-request: 2201
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
Reviewed-on: http://codereview.qt.nokia.com/3403

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
parent 31739dc0
......@@ -92,6 +92,21 @@ BranchInfo BazaarClient::synchronousBranchQuery(const QString &repositoryRoot) c
return BranchInfo(repositoryRoot, false);
}
void BazaarClient::commit(const QString &repositoryRoot, const QStringList &files,
const QString &commitMessageFile, const QStringList &extraOptions)
{
VCSBaseClient::commit(repositoryRoot, files, commitMessageFile,
QStringList(extraOptions) << QLatin1String("-F") << commitMessageFile);
}
void BazaarClient::annotate(const QString &workingDir, const QString &file,
const QString revision, int lineNumber,
const QStringList &extraOptions)
{
VCSBaseClient::annotate(workingDir, file, revision, lineNumber,
QStringList(extraOptions) << QLatin1String("--long"));
}
QString BazaarClient::findTopLevelForFile(const QFileInfo &file) const
{
const QString repositoryCheckFile =
......@@ -103,6 +118,13 @@ QString BazaarClient::findTopLevelForFile(const QFileInfo &file) const
repositoryCheckFile);
}
void BazaarClient::view(const QString &source, const QString &id, const QStringList &extraOptions)
{
QStringList args(QLatin1String("log"));
args << QLatin1String("-p") << QLatin1String("-v") << extraOptions;
VCSBaseClient::view(source, id, args);
}
QString BazaarClient::vcsEditorKind(VCSCommand cmd) const
{
switch(cmd) {
......@@ -117,54 +139,7 @@ QString BazaarClient::vcsEditorKind(VCSCommand cmd) const
}
}
QStringList BazaarClient::cloneArguments(const QString &srcLocation,
const QString &dstLocation,
const QStringList &extraOptions) const
{
QStringList args(extraOptions);
args << srcLocation;
if (!dstLocation.isEmpty())
args << dstLocation;
return args;
}
QStringList BazaarClient::pullArguments(const QString &srcLocation,
const QStringList &extraOptions) const
{
QStringList args(extraOptions);
if (!srcLocation.isEmpty())
args << srcLocation;
return args;
}
QStringList BazaarClient::pushArguments(const QString &dstLocation,
const QStringList &extraOptions) const
{
QStringList args(extraOptions);
if (!dstLocation.isEmpty())
args << dstLocation;
return args;
}
QStringList BazaarClient::commitArguments(const QStringList &files,
const QString &commitMessageFile,
const QStringList &extraOptions) const
{
QStringList args(extraOptions);
args << QLatin1String("-F") << commitMessageFile;
args << files;
return args;
}
QStringList BazaarClient::importArguments(const QStringList &files) const
{
QStringList args;
if (!files.isEmpty())
args.append(files);
return args;
}
QStringList BazaarClient::updateArguments(const QString &revision) const
QStringList BazaarClient::revisionSpec(const QString &revision) const
{
QStringList args;
if (!revision.isEmpty())
......@@ -172,67 +147,6 @@ QStringList BazaarClient::updateArguments(const QString &revision) const
return args;
}
QStringList BazaarClient::revertArguments(const QString &file,
const QString &revision) const
{
QStringList args;
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
if (!file.isEmpty())
args << file;
return args;
}
QStringList BazaarClient::revertAllArguments(const QString &revision) const
{
QStringList args;
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
return args;
}
QStringList BazaarClient::annotateArguments(const QString &file,
const QString &revision,
int lineNumber) const
{
Q_UNUSED(lineNumber);
QStringList args(QLatin1String("--long"));
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
return args << file;
}
QStringList BazaarClient::diffArguments(const QStringList &files,
const QStringList &extraOptions) const
{
QStringList args(extraOptions);
if (!files.isEmpty())
args.append(files);
return args;
}
QStringList BazaarClient::logArguments(const QStringList &files,
const QStringList &extraOptions) const
{
return diffArguments(files, extraOptions);
}
QStringList BazaarClient::statusArguments(const QString &file) const
{
QStringList args;
if (!file.isEmpty())
args.append(file);
return args;
}
QStringList BazaarClient::viewArguments(const QString &revision) const
{
QStringList args(QLatin1String("log"));
args << QLatin1String("-p") << QLatin1String("-v")
<< QLatin1String("-r") << revision;
return args;
}
BazaarClient::StatusItem BazaarClient::parseStatusLine(const QString &line) const
{
StatusItem item;
......
......@@ -52,40 +52,24 @@ public:
bool synchronousSetUserId();
BranchInfo synchronousBranchQuery(const QString &repositoryRoot) const;
void commit(const QString &repositoryRoot, const QStringList &files,
const QString &commitMessageFile, const QStringList &extraOptions = QStringList());
void annotate(const QString &workingDir, const QString &file,
const QString revision = QString(), int lineNumber = -1,
const QStringList &extraOptions = QStringList());
void view(const QString &source, const QString &id,
const QStringList &extraOptions = QStringList());
QString findTopLevelForFile(const QFileInfo &file) const;
protected:
QString vcsEditorKind(VCSCommand cmd) const;
QStringList cloneArguments(const QString &srcLocation,
const QString &dstLocation,
const QStringList &extraOptions) const;
QStringList pullArguments(const QString &srcLocation,
const QStringList &extraOptions) const;
QStringList pushArguments(const QString &dstLocation,
const QStringList &extraOptions) const;
QStringList commitArguments(const QStringList &files,
const QString &commitMessageFile,
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;
QStringList revertAllArguments(const QString &revision) const;
QStringList annotateArguments(const QString &file,
const QString &revision, int lineNumber) const;
QStringList diffArguments(const QStringList &files,
const QStringList &extraOptions) const;
QStringList revisionSpec(const QString &revision) const;
VCSBase::VCSBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
const QStringList &files,
const QStringList &extraOptions);
QStringList logArguments(const QStringList &files,
const QStringList &extraOptions) const;
VCSBase::VCSBaseEditorParameterWidget *createLogEditor(const QString &workingDir,
const QStringList &files,
const QStringList &extraOptions);
QStringList statusArguments(const QString &file) const;
QStringList viewArguments(const QString &revision) const;
StatusItem parseStatusLine(const QString &line) const;
private:
friend class CloneWizard;
......
......@@ -112,7 +112,7 @@ QSharedPointer<VCSBase::AbstractCheckoutJob> CloneWizard::createJob(const QList<
extraOptions << QLatin1String("-r") << panel->revision();
const BazaarClient *client = BazaarPlugin::instance()->client();
args << client->vcsCommandString(BazaarClient::CloneCommand)
<< client->cloneArguments(page->repository(), page->directory(), extraOptions);
<< extraOptions << page->repository() << page->directory();
VCSBase::ProcessCheckoutJob *job = new VCSBase::ProcessCheckoutJob;
job->addStep(settings.binary(), args, page->path());
......
......@@ -303,152 +303,79 @@ void MercurialClient::outgoing(const QString &repositoryRoot)
enqueueJob(job);
}
QString MercurialClient::findTopLevelForFile(const QFileInfo &file) const
void MercurialClient::annotate(const QString &workingDir, const QString &file,
const QString revision, int lineNumber,
const QStringList &extraOptions)
{
const QString repositoryCheckFile = QLatin1String(Constants::MECURIALREPO) + QLatin1String("/requires");
return file.isDir() ?
VCSBase::VCSBasePlugin::findRepositoryForDirectory(file.absoluteFilePath(), repositoryCheckFile) :
VCSBase::VCSBasePlugin::findRepositoryForDirectory(file.absolutePath(), repositoryCheckFile);
}
QString MercurialClient::vcsEditorKind(VCSCommand cmd) const
{
switch (cmd)
{
case AnnotateCommand : return QLatin1String(Constants::ANNOTATELOG);
case DiffCommand : return QLatin1String(Constants::DIFFLOG);
case LogCommand : return QLatin1String(Constants::FILELOG);
default : return QLatin1String("");
}
return QLatin1String("");
}
QStringList MercurialClient::cloneArguments(const QString &srcLocation,
const QString &dstLocation,
const QStringList &extraOptions) const
{
Q_UNUSED(srcLocation);
Q_UNUSED(dstLocation);
Q_UNUSED(extraOptions);
QStringList args;
return args;
QStringList args(extraOptions);
args << QLatin1String("-u") << QLatin1String("-c") << QLatin1String("-d");
VCSBaseClient::annotate(workingDir, file, revision, lineNumber, args);
}
QStringList MercurialClient::pullArguments(const QString &srcLocation,
const QStringList &extraOptions) const
void MercurialClient::commit(const QString &repositoryRoot, const QStringList &files,
const QString &commitMessageFile,
const QStringList &extraOptions)
{
Q_UNUSED(extraOptions);
QStringList args;
// Add arguments for common options
if (!srcLocation.isEmpty())
args << srcLocation;
return args;
QStringList args(extraOptions);
args << QLatin1String("--noninteractive") << QLatin1String("-l") << commitMessageFile;
VCSBaseClient::commit(repositoryRoot, files, commitMessageFile, args);
}
QStringList MercurialClient::pushArguments(const QString &dstLocation,
const QStringList &extraOptions) const
void MercurialClient::diff(const QString &workingDir, const QStringList &files,
const QStringList &extraOptions)
{
Q_UNUSED(extraOptions);
QStringList args;
// Add arguments for common options
if (!dstLocation.isEmpty())
args << dstLocation;
return args;
QStringList args(extraOptions);
args << QLatin1String("-g") << QLatin1String("-p") << QLatin1String("-U 8");
VCSBaseClient::diff(workingDir, files, args);
}
QStringList MercurialClient::commitArguments(const QStringList &files,
const QString &commitMessageFile,
const QStringList &extraOptions) const
void MercurialClient::import(const QString &repositoryRoot, const QStringList &files,
const QStringList &extraOptions)
{
QStringList args(QLatin1String("--noninteractive"));
if (!args.isEmpty())
args.append(extraOptions);
args << QLatin1String("-l") << commitMessageFile;
args << files;
return args;
VCSBaseClient::import(repositoryRoot, files,
QStringList(extraOptions) << QLatin1String("--no-commit"));
}
QStringList MercurialClient::importArguments(const QStringList &files) const
void MercurialClient::revertAll(const QString &workingDir, const QString &revision,
const QStringList &extraOptions)
{
QStringList args(QLatin1String("--no-commit"));
if (!files.isEmpty())
args.append(files);
return args;
VCSBaseClient::revertAll(workingDir, revision,
QStringList(extraOptions) << QLatin1String("--all"));
}
QStringList MercurialClient::updateArguments(const QString &revision) const
void MercurialClient::view(const QString &source, const QString &id,
const QStringList &extraOptions)
{
QStringList args;
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
return args;
args << QLatin1String("log") << QLatin1String("-p") << QLatin1String("-g");
VCSBaseClient::view(source, id, args << extraOptions);
}
QStringList MercurialClient::revertArguments(const QString &file,
const QString &revision) const
QString MercurialClient::findTopLevelForFile(const QFileInfo &file) const
{
QStringList args;
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
if (!file.isEmpty())
args << file;
return args;
const QString repositoryCheckFile = QLatin1String(Constants::MECURIALREPO) + QLatin1String("/requires");
return file.isDir() ?
VCSBase::VCSBasePlugin::findRepositoryForDirectory(file.absoluteFilePath(), repositoryCheckFile) :
VCSBase::VCSBasePlugin::findRepositoryForDirectory(file.absolutePath(), repositoryCheckFile);
}
QStringList MercurialClient::revertAllArguments(const QString &revision) const
QString MercurialClient::vcsEditorKind(VCSCommand cmd) const
{
QStringList args;
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
return args << QLatin1String("--all");
switch (cmd)
{
case AnnotateCommand : return QLatin1String(Constants::ANNOTATELOG);
case DiffCommand : return QLatin1String(Constants::DIFFLOG);
case LogCommand : return QLatin1String(Constants::FILELOG);
default : return QLatin1String("");
}
return QLatin1String("");
}
QStringList MercurialClient::annotateArguments(const QString &file,
const QString &revision,
int /*lineNumber*/) const
QStringList MercurialClient::revisionSpec(const QString &revision) const
{
QStringList args;
args << QLatin1String("-u") << QLatin1String("-c") << QLatin1String("-d");
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
return args << file;
}
QStringList MercurialClient::diffArguments(const QStringList &files,
const QStringList &extraOptions) const
{
QStringList args;
args << QLatin1String("-g") << QLatin1String("-p") << QLatin1String("-U 8");
if (!args.isEmpty())
args.append(extraOptions);
if (!files.isEmpty())
args.append(files);
return args;
}
QStringList MercurialClient::logArguments(const QStringList &files,
const QStringList &extraOptions) const
{
Q_UNUSED(extraOptions);
QStringList args;
if (!files.empty())
args.append(files);
return args;
}
QStringList MercurialClient::statusArguments(const QString &file) const
{
QStringList args;
if (!file.isEmpty())
args.append(file);
return args;
}
QStringList MercurialClient::viewArguments(const QString &revision) const
{
QStringList args;
args << QLatin1String("log") << QLatin1String("-p") << QLatin1String("-g")
<< QLatin1String("-r") << revision;
return args;
}
......
......@@ -68,38 +68,30 @@ public:
void outgoing(const QString &repositoryRoot);
QString vcsGetRepositoryURL(const QString &directory);
void annotate(const QString &workingDir, const QString &file,
const QString revision = QString(), int lineNumber = -1,
const QStringList &extraOptions = QStringList());
void commit(const QString &repositoryRoot, const QStringList &files,
const QString &commitMessageFile,
const QStringList &extraOptions = QStringList());
void diff(const QString &workingDir, const QStringList &files = QStringList(),
const QStringList &extraOptions = QStringList());
void import(const QString &repositoryRoot, const QStringList &files,
const QStringList &extraOptions = QStringList());
void revertAll(const QString &workingDir, const QString &revision = QString(),
const QStringList &extraOptions = QStringList());
void view(const QString &source, const QString &id,
const QStringList &extraOptions = QStringList());
public:
QString findTopLevelForFile(const QFileInfo &file) const;
protected:
QString vcsEditorKind(VCSCommand cmd) const;
QStringList cloneArguments(const QString &srcLocation,
const QString &dstLocation,
const QStringList &extraOptions) const;
QStringList pullArguments(const QString &srcLocation,
const QStringList &extraOptions) const;
QStringList pushArguments(const QString &dstLocation,
const QStringList &extraOptions) const;
QStringList commitArguments(const QStringList &files,
const QString &commitMessageFile,
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;
QStringList revertAllArguments(const QString &revision) const;
QStringList annotateArguments(const QString &file,
const QString &revision, int lineNumber) const;
QStringList diffArguments(const QStringList &files,
const QStringList &extraOptions) const;
QStringList revisionSpec(const QString &revision) const;
VCSBase::VCSBaseEditorParameterWidget *createDiffEditor(const QString &workingDir,
const QStringList &files,
const QStringList &extraOptions);
QStringList logArguments(const QStringList &files,
const QStringList &extraOptions) const;
QStringList statusArguments(const QString &file) const;
QStringList viewArguments(const QString &revision) const;
StatusItem parseStatusLine(const QString &line) const;
};
......
......@@ -155,9 +155,11 @@ VCSBaseClient::~VCSBaseClient()
}
}
bool VCSBaseClient::synchronousCreateRepository(const QString &workingDirectory)
bool VCSBaseClient::synchronousCreateRepository(const QString &workingDirectory,
const QStringList &extraOptions)
{
const QStringList args(vcsCommandString(CreateRepositoryCommand));
QStringList args(vcsCommandString(CreateRepositoryCommand));
args << extraOptions;
QByteArray outputData;
if (!vcsFullySynchronousExec(workingDirectory, args, &outputData))
return false;
......@@ -174,32 +176,35 @@ bool VCSBaseClient::synchronousClone(const QString &workingDir,
{
QStringList args;
args << vcsCommandString(CloneCommand)
<< cloneArguments(srcLocation, dstLocation, extraOptions);
<< extraOptions << srcLocation << dstLocation;
QByteArray stdOut;
return vcsFullySynchronousExec(workingDir, args, &stdOut);
}
bool VCSBaseClient::synchronousAdd(const QString &workingDir, const QString &filename)
bool VCSBaseClient::synchronousAdd(const QString &workingDir, const QString &filename,
const QStringList &extraOptions)
{
QStringList args;
args << vcsCommandString(AddCommand) << filename;
args << vcsCommandString(AddCommand) << extraOptions << filename;
QByteArray stdOut;
return vcsFullySynchronousExec(workingDir, args, &stdOut);
}
bool VCSBaseClient::synchronousRemove(const QString &workingDir, const QString &filename)
bool VCSBaseClient::synchronousRemove(const QString &workingDir, const QString &filename,
const QStringList &extraOptions)
{
QStringList args;
args << vcsCommandString(RemoveCommand) << filename;
args << vcsCommandString(RemoveCommand) << extraOptions << filename;
QByteArray stdOut;
return vcsFullySynchronousExec(workingDir, args, &stdOut);
}
bool VCSBaseClient::synchronousMove(const QString &workingDir,
const QString &from, const QString &to)
const QString &from, const QString &to,
const QStringList &extraOptions)
{
QStringList args;
args << vcsCommandString(MoveCommand) << from << to;
args << vcsCommandString(MoveCommand) << extraOptions << from << to;
QByteArray stdOut;
return vcsFullySynchronousExec(workingDir, args, &stdOut);
}
......@@ -209,7 +214,7 @@ bool VCSBaseClient::synchronousPull(const QString &workingDir,
const QStringList &extraOptions)
{
QStringList args;
args << vcsCommandString(PullCommand) << pullArguments(srcLocation, extraOptions);
args << vcsCommandString(PullCommand) << extraOptions << srcLocation;
// Disable UNIX terminals to suppress SSH prompting
const unsigned flags =
VCSBase::VCSBasePlugin::SshPasswordPrompt
......@@ -227,7 +232,7 @@ bool VCSBaseClient::synchronousPush(const QString &workingDir,
const QStringList &extraOptions)
{
QStringList args;
args << vcsCommandString(PushCommand) << pushArguments(dstLocation, extraOptions);
args << vcsCommandString(PushCommand) << extraOptions << dstLocation;
// Disable UNIX terminals to suppress SSH prompting
const unsigned flags =
VCSBase::VCSBasePlugin::SshPasswordPrompt
......@@ -289,12 +294,13 @@ Utils::SynchronousProcessResponse VCSBaseClient::vcsSynchronousExec(
void VCSBaseClient::annotate(const QString &workingDir, const QString &file,
const QString revision /* = QString() */,
int lineNumber /* = -1 */)
int lineNumber /* = -1 */,
const QStringList &extraOptions)
{
Q_UNUSED(lineNumber)
const QString vcsCmdString = vcsCommandString(AnnotateCommand);
QStringList args;
args << vcsCmdString << annotateArguments(file, revision, lineNumber);
args << vcsCmdString << revisionSpec(revision) << extraOptions << file;
const QString kind = vcsEditorKind(AnnotateCommand);
const QString id = VCSBase::VCSBaseEditorWidget::getSource(workingDir, QStringList(file));
const QString title = vcsEditorTitle(vcsCmdString, id);
......@@ -329,7 +335,7 @@ void VCSBaseClient::diff(const QString &workingDir, const QStringList &files,
QStringList args;
const QStringList paramArgs = paramWidget != 0 ? paramWidget->arguments() : QStringList();
args << vcsCmdString << diffArguments(files, extraOptions + paramArgs);
args << vcsCmdString << extraOptions << paramArgs << files;
QSharedPointer<VCSJob> job(new VCSJob(workingDir, args, editor));
enqueueJob(job);
}
......@@ -354,17 +360,18 @@ void VCSBaseClient::log(const QString &workingDir, const QStringList &files,
QStringList args;
const QStringList paramArgs = paramWidget != 0 ? paramWidget->arguments() : QStringList();
args << vcsCmdString << logArguments(files, extraOptions + paramArgs);
args << vcsCmdString << extraOptions << paramArgs << files;
QSharedPointer<VCSJob> job(new VCSJob(workingDir, args, editor));
enqueueJob(job);
}
void VCSBaseClient::revertFile(const QString &workingDir,
const QString &file,
const QString &revision)
const QString &revision,
const QStringList &extraOptions)
{