diff options
author | Cristian Adam <cristian.adam@gmail.com> | 2016-05-19 13:34:56 +0200 |
---|---|---|
committer | Cristian Adam <cristian.adam@gmail.com> | 2016-05-19 15:00:35 +0000 |
commit | 30db0202a08c5397259bb25db1d2183b453d10ee (patch) | |
tree | 6264cc4653f56e5dba0eaa6fd4cf134a6aff9846 /src | |
parent | be44c8b20700848d2babacc894215e1430c38d9b (diff) | |
download | qt-creator-30db0202a08c5397259bb25db1d2183b453d10ee.tar.gz |
Perforce: fixed invalid setTopLevel calls
When using P4CONFIG one can user multiple p4 workspaces.
For every workspace one needs to have a p4config.txt file,
which contains the P4CLIENT, P4USER, P4PORT variable values.
Qt Creator will query on various directories for p4 configuration.
"p4 client" command will give an error if a p4config.txt file is
not present. p4 will try to connect to localhost when P4PORT is
not set and give and error, but it will take a long time to
timeout.
This timeout gives the impression that P4 does a lot of work and
Qt Creator will sometimes freeze.
The solution to this timeout is to set P4PORT and P4USER. In
this case "p4 client" will give back the same generic "Root:"
variable e.g. c:\p4, which will be seen as a valid path and
PerforcePlugin::setTopLevel will be called and thus setting the
path of the current workspace, which is not valid.
Fortunately in this case "Client:" and "Host:" variables in the
output given by the "p4 client" have the same value. "Client:"
will probably never have the same value as the "Host:" value,
thus making it safe to ignore these invalid "p4 client" calls.
Change-Id: Iafb2640cccd7bd10c455d33ea9d36c5eae2e2951
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/perforce/perforcechecker.cpp | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/src/plugins/perforce/perforcechecker.cpp b/src/plugins/perforce/perforcechecker.cpp index b7f5f56ccb..6f011502bd 100644 --- a/src/plugins/perforce/perforcechecker.cpp +++ b/src/plugins/perforce/perforcechecker.cpp @@ -28,7 +28,7 @@ #include <utils/qtcassert.h> #include <utils/synchronousprocess.h> -#include <QRegExp> +#include <QRegularExpression> #include <QTimer> #include <QFileInfo> #include <QDir> @@ -155,24 +155,51 @@ void PerforceChecker::slotFinished(int exitCode, QProcess::ExitStatus exitStatus } } +static inline QString findTerm(const QString& in, const QLatin1String& term) +{ + QRegularExpression regExp(QString("(\\n|\\r\\n|\\r)%1\\s*(.*)(\\n|\\r\\n|\\r)").arg(term)); + QTC_ASSERT(regExp.isValid(), return QString()); + QRegularExpressionMatch match = regExp.match(in); + if (match.hasMatch()) + return match.captured(2).trimmed(); + return QString(); +} + // Parse p4 client output for the top level static inline QString clientRootFromOutput(const QString &in) { - QRegExp regExp(QLatin1String("(\\n|\\r\\n|\\r)Root:\\s*(.*)(\\n|\\r\\n|\\r)")); - QTC_ASSERT(regExp.isValid(), return QString()); - regExp.setMinimal(true); - // Normalize slashes and capitalization of Windows drive letters for caching. - if (regExp.indexIn(in) != -1) - return QFileInfo(regExp.cap(2).trimmed()).absoluteFilePath(); + QString root = findTerm(in, QLatin1String("Root:")); + if (!root.isNull()) { + // Normalize slashes and capitalization of Windows drive letters for caching. + return QFileInfo(root).absoluteFilePath(); + } return QString(); } +// When p4 port and p4 user is set a preconfigured Root: is given, which doesn't relate with +// the current mapped project. In this case "Client:" has the same value as "Host:", which is an +// invalid case. +static inline bool clientAndHostAreEqual(const QString &in) +{ + QString client = findTerm(in, QLatin1String("Client:")); + QString host = findTerm(in, QLatin1String("Host:")); + + return client == host; +} + void PerforceChecker::parseOutput(const QString &response) { if (!response.contains(QLatin1String("View:")) && !response.contains(QLatin1String("//depot/"))) { emitFailed(tr("The client does not seem to contain any mapped files.")); return; } + + if (clientAndHostAreEqual(response)) { + // Is an invalid case. But not an error. QtC checks cmake install directories for + // p4 repositories, or the %temp% directory. + return; + } + const QString repositoryRoot = clientRootFromOutput(response); if (repositoryRoot.isEmpty()) { //: Unable to determine root of the p4 client installation |