aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cvs/cvsplugin.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <[email protected]>2010-05-20 16:24:39 +0200
committerFriedemann Kleint <[email protected]>2010-05-20 16:24:56 +0200
commit7003b82e2ba68f24c9e5c27107aacd82898ba9cf (patch)
tree9b18d005e0b5f34089e82e9092ce852806d5a471 /src/plugins/cvs/cvsplugin.cpp
parent58a5da63a8b698de6f7faae95afa9e783569353c (diff)
Version control: Improve detection.
Merge managesDirectory() and findTopLevelForDirectory() into one giving managesDirectory() an optional topLevel parameter. This removes the need to go up the directory hierarchy twice when checking for Merurial or git and also saves some checks for CVS/Subversion. VCSManager: Check cache in reverse order starting out with the full path first to improve handling of nested repositories. Rubber-stamped-by: con Acked-by: dt
Diffstat (limited to 'src/plugins/cvs/cvsplugin.cpp')
-rw-r--r--src/plugins/cvs/cvsplugin.cpp65
1 files changed, 33 insertions, 32 deletions
diff --git a/src/plugins/cvs/cvsplugin.cpp b/src/plugins/cvs/cvsplugin.cpp
index 1f7e646fe1d..1bdb606be6b 100644
--- a/src/plugins/cvs/cvsplugin.cpp
+++ b/src/plugins/cvs/cvsplugin.cpp
@@ -827,8 +827,10 @@ void CVSPlugin::slotDescribe(const QString &source, const QString &changeNr)
bool CVSPlugin::describe(const QString &file, const QString &changeNr, QString *errorMessage)
{
- const QString toplevel = findTopLevelForDirectory(QFileInfo(file).absolutePath());
- if (toplevel.isEmpty()) {
+
+ QString toplevel;
+ const bool manages = managesDirectory(QFileInfo(file).absolutePath(), &toplevel);
+ if (!manages || toplevel.isEmpty()) {
*errorMessage = msgCannotFindTopLevel(file);
return false;
}
@@ -1122,45 +1124,44 @@ bool CVSPlugin::vcsDelete(const QString &workingDir, const QString &rawFileName)
/* CVS has a "CVS" directory in each directory it manages. The top level
* is the first directory under the directory that does not have it. */
-bool CVSPlugin::managesDirectory(const QString &directory) const
+bool CVSPlugin::managesDirectory(const QString &directory, QString *topLevel /* = 0 */) const
{
+ if (topLevel)
+ topLevel->clear();
+ bool manages = false;
const QDir dir(directory);
- const bool rc = dir.exists() && managesDirectory(dir);
- if (CVS::Constants::debug)
- qDebug() << "CVSPlugin::managesDirectory" << directory << rc;
- return rc;
+ do {
+ if (!dir.exists() || !checkCVSDirectory(dir))
+ break;
+ manages = true;
+ if (!topLevel)
+ break;
+ /* Recursing up, the top level is a child of the first directory that does
+ * not have a "CVS" directory. The starting directory must be a managed
+ * one. Go up and try to find the first unmanaged parent dir. */
+ QDir lastDirectory = dir;
+ for (QDir parentDir = lastDirectory; parentDir.cdUp() ; lastDirectory = parentDir) {
+ if (!checkCVSDirectory(parentDir)) {
+ *topLevel = lastDirectory.absolutePath();
+ break;
+ }
+ }
+ } while (false);
+ if (CVS::Constants::debug) {
+ QDebug nsp = qDebug().nospace();
+ nsp << "CVSPlugin::managesDirectory" << directory << manages;
+ if (topLevel)
+ nsp << *topLevel;
+ }
+ return manages;
}
-bool CVSPlugin::managesDirectory(const QDir &directory) const
+bool CVSPlugin::checkCVSDirectory(const QDir &directory) const
{
const QString cvsDir = directory.absoluteFilePath(QLatin1String("CVS"));
return QFileInfo(cvsDir).isDir();
}
-QString CVSPlugin::findTopLevelForDirectory(const QString &directory) const
-{
- // Debug wrapper
- const QString rc = findTopLevelForDirectoryI(directory);
- if (CVS::Constants::debug)
- qDebug() << "CVSPlugin::findTopLevelForDirectory" << directory << rc;
- return rc;
-}
-
-QString CVSPlugin::findTopLevelForDirectoryI(const QString &directory) const
-{
- /* Recursing up, the top level is a child of the first directory that does
- * not have a "CVS" directory. The starting directory must be a managed
- * one. Go up and try to find the first unmanaged parent dir. */
- QDir lastDirectory = QDir(directory);
- if (!lastDirectory.exists() || !managesDirectory(lastDirectory))
- return QString();
- for (QDir parentDir = lastDirectory; parentDir.cdUp() ; lastDirectory = parentDir) {
- if (!managesDirectory(parentDir))
- return lastDirectory.absolutePath();
- }
- return QString();
-}
-
CVSControl *CVSPlugin::cvsVersionControl() const
{
return static_cast<CVSControl *>(versionControl());