Commit 310194cb authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

VCS[svn]: Extract runSVN overload with username/password.

to aid trac plugin implementation.
parent d7747fe8
......@@ -83,7 +83,10 @@ QSharedPointer<VCSBase::AbstractCheckoutJob> CheckoutWizard::createJob(const QLi
args << QLatin1String("checkout") << cwp->repository() << directory;
const QString workingDirectory = cwp->path();
*checkoutPath = workingDirectory + QLatin1Char('/') + directory;
VCSBase::AbstractCheckoutJob *job = new VCSBase::ProcessCheckoutJob(binary, settings.addOptions(args),
const QStringList completeArgs = settings.hasAuthentication() ?
SubversionPlugin::addAuthenticationOptions(args, settings.user, settings.password) :
args;
VCSBase::AbstractCheckoutJob *job = new VCSBase::ProcessCheckoutJob(binary, completeArgs,
workingDirectory);
return QSharedPointer<VCSBase::AbstractCheckoutJob>(job);
}
......
......@@ -1035,11 +1035,46 @@ void SubversionPlugin::submitCurrentLog()
<< Core::EditorManager::instance()->currentEditor());
}
SubversionResponse
SubversionPlugin::runSvn(const QString &workingDir,
const QStringList &arguments,
int timeOut,
unsigned flags,
QTextCodec *outputCodec)
{
return m_settings.hasAuthentication() ?
runSvn(workingDir, m_settings.user, m_settings.password,
arguments, timeOut, flags, outputCodec) :
runSvn(workingDir, QString(), QString(),
arguments, timeOut, flags, outputCodec);
}
// Add authorization options to the command line arguments.
// SVN pre 1.5 does not accept "--userName" for "add", which is most likely
// an oversight. As no password is needed for the option, generally omit it.
QStringList SubversionPlugin::addAuthenticationOptions(const QStringList &args,
const QString &userName, const QString &password)
{
if (userName.isEmpty())
return args;
if (!args.empty() && args.front() == QLatin1String("add"))
return args;
QStringList rc;
rc.push_back(QLatin1String("--username"));
rc.push_back(userName);
if (!password.isEmpty()) {
rc.push_back(QLatin1String("--password"));
rc.push_back(password);
}
rc.append(args);
return rc;
}
SubversionResponse SubversionPlugin::runSvn(const QString &workingDir,
const QStringList &arguments,
int timeOut,
unsigned flags,
QTextCodec *outputCodec)
const QString &userName, const QString &password,
const QStringList &arguments, int timeOut,
unsigned flags, QTextCodec *outputCodec)
{
const QString executable = m_settings.svnCommand;
SubversionResponse response;
......@@ -1049,10 +1084,10 @@ SubversionResponse SubversionPlugin::runSvn(const QString &workingDir,
return response;
}
const QStringList completeArguments = SubversionPlugin::addAuthenticationOptions(arguments, userName, password);
const Utils::SynchronousProcessResponse sp_resp =
VCSBase::VCSBasePlugin::runVCS(workingDir, executable,
m_settings.addOptions(arguments),
timeOut, flags, outputCodec);
completeArguments, timeOut, flags, outputCodec);
response.error = sp_resp.result != Utils::SynchronousProcessResponse::Finished;
if (response.error)
......
......@@ -99,6 +99,11 @@ public:
static SubversionPlugin *subversionPluginInstance();
// Add authorization options to the command line arguments.
static QStringList addAuthenticationOptions(const QStringList &args,
const QString &userName = QString(),
const QString &password = QString());
public slots:
void vcsAnnotate(const QString &workingDir, const QString &file,
const QString &revision = QString(), int lineNumber = -1);
......@@ -136,9 +141,16 @@ private:
Core::IEditor * showOutputInEditor(const QString& title, const QString &output,
int editorType, const QString &source,
QTextCodec *codec);
// Run using the settings' authentication options.
SubversionResponse runSvn(const QString &workingDir,
const QStringList &arguments, int timeOut,
unsigned flags, QTextCodec *outputCodec = 0);
// Run using custom authentication options.
SubversionResponse runSvn(const QString &workingDir,
const QString &userName, const QString &password,
const QStringList &arguments, int timeOut,
unsigned flags, QTextCodec *outputCodec = 0);
void filelog(const QString &workingDir,
const QStringList &file = QStringList(),
bool enableAnnotationContextMenu = false);
......
......@@ -37,8 +37,6 @@ static const char userKeyC[] = "User";
static const char passwordKeyC[] = "Password";
static const char authenticationKeyC[] = "Authentication";
static const char userNameOptionC[] = "--username";
static const char passwordOptionC[] = "--password";
static const char promptToSubmitKeyC[] = "PromptForSubmit";
static const char timeOutKeyC[] = "TimeOut";
static const char spaceIgnorantAnnotationKeyC[] = "SpaceIgnorantAnnotation";
......@@ -107,23 +105,3 @@ bool SubversionSettings::equals(const SubversionSettings &s) const
&& promptToSubmit == s.promptToSubmit
&& spaceIgnorantAnnotation == s.spaceIgnorantAnnotation;
}
QStringList SubversionSettings::addOptions(const QStringList &args) const
{
if (!useAuthentication || user.isEmpty())
return args;
// SVN pre 1.5 does not accept "--userName" for "add", which is most likely
// an oversight. As no password is needed for the option, generally omit it.
if (!args.empty() && args.front() == QLatin1String("add"))
return args;
QStringList rc;
rc.push_back(QLatin1String(userNameOptionC));
rc.push_back(user);
if (!password.isEmpty()) {
rc.push_back(QLatin1String(passwordOptionC));
rc.push_back(password);
}
rc.append(args);
return rc;
}
......@@ -39,7 +39,6 @@ QT_END_NAMESPACE
namespace Subversion {
namespace Internal {
// Todo: Add user name and password?
struct SubversionSettings
{
SubversionSettings();
......@@ -50,9 +49,7 @@ struct SubversionSettings
inline int timeOutMS() const { return timeOutS * 1000; }
inline int longTimeOutMS() const { return timeOutS * 10000; }
// Add authentication and (maybe future) options to the
// command line
QStringList addOptions(const QStringList &args) const;
inline bool hasAuthentication() const { return useAuthentication && !user.isEmpty(); }
bool equals(const SubversionSettings &s) 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