diff options
author | Friedemann Kleint <[email protected]> | 2010-05-19 17:41:14 +0200 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2010-05-19 17:41:14 +0200 |
commit | b4b177fa27a084eef4e77df299987f9c90daab88 (patch) | |
tree | 5a5277e05368ea81fa477c3fc90a72ae30796cbb /src/plugins/vcsbase/vcsbaseplugin.cpp | |
parent | 9af9c91f93fb118c4c54ed46c9bc58ce708012b5 (diff) |
VCS[git/hg]: Prevent search for repository from creating folders
... when autofs is involved. Check for files instead of folders
and stop checking/recursing up at '/' or $HOME. Further fixup
will follow.
Task-number: QTCREATORBUG-1361
Task-number: QTBUG-10495
Diffstat (limited to 'src/plugins/vcsbase/vcsbaseplugin.cpp')
-rw-r--r-- | src/plugins/vcsbase/vcsbaseplugin.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/plugins/vcsbase/vcsbaseplugin.cpp b/src/plugins/vcsbase/vcsbaseplugin.cpp index 8cc60f0cfeb..7b1c3f40c1c 100644 --- a/src/plugins/vcsbase/vcsbaseplugin.cpp +++ b/src/plugins/vcsbase/vcsbaseplugin.cpp @@ -54,7 +54,7 @@ #include <QtGui/QFileDialog> #include <QtGui/QMainWindow> -enum { debug = 0 }; +enum { debug = 0, debugRepositorySearch = 0 }; namespace VCSBase { @@ -636,6 +636,40 @@ void VCSBasePlugin::slotTestRemoveSnapshot() d->m_testLastSnapshot.clear(); } +// Find top level for version controls like git/Mercurial that have +// a directory at the top of the repository. +// Note that checking for the existence of files is preferred over directories +// since checking for directories can cause them to be created when +// AutoFS is used (due its automatically creating mountpoints when querying +// a directory). In addition, bail out when reaching the home directory +// of the user or root (generally avoid '/', where mountpoints are created). +QString VCSBasePlugin::findRepositoryForDirectory(const QString &dirS, + const QString &checkFile) +{ + if (debugRepositorySearch) + qDebug() << ">VCSBasePlugin::findRepositoryForDirectory" << dirS << checkFile; + QTC_ASSERT(!dirS.isEmpty() && !checkFile.isEmpty(), return QString()); + + const QString root = QDir::rootPath(); + const QString home = QDir::homePath(); + + QDir directory(dirS); + do { + const QString absDirPath = directory.absolutePath(); + if (absDirPath == root || absDirPath == home) + break; + + if (QFileInfo(directory, checkFile).isFile()) { + if (debugRepositorySearch) + qDebug() << "<VCSBasePlugin::findRepositoryForDirectory> " << absDirPath; + return absDirPath; + } + } while (directory.cdUp()); + if (debugRepositorySearch) + qDebug() << "<VCSBasePlugin::findRepositoryForDirectory bailing out at " << directory.absolutePath(); + return QString(); +} + } // namespace VCSBase #include "vcsbaseplugin.moc" |