SVN: Refactor SVN detection code

Reviewed-by: Jonathan Liu <net147@gmail.com>
Change-Id: Ib78251b69a89ee503bb78ab122c6e37a6ec7aacb
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
Tobias Hunger
2011-10-19 14:07:26 +00:00
parent 67ac492ca0
commit fa2c24d92b

View File

@@ -1357,58 +1357,43 @@ QString SubversionPlugin::vcsGetRepositoryURL(const QString &directory)
return QString(); return QString();
} }
/* Subversion < 1.7 has ".svn" directory in each directory
* it manages. The top level is the first directory
* under the directory that does not have a ".svn".
*
* Subversion >= 1.7 has ".svn" directory in the root of the
* working copy. The top level is the root of the working copy
* containg ".svn". */
bool SubversionPlugin::managesDirectory(const QString &directory, QString *topLevel /* = 0 */) const bool SubversionPlugin::managesDirectory(const QString &directory, QString *topLevel /* = 0 */) const
{ {
const QDir dir(directory); const QDir dir(directory);
if (!dir.exists())
return false;
if (topLevel) if (topLevel)
topLevel->clear(); topLevel->clear();
bool manages = false;
// Subversion >= 1.7: Check for furthest parent containing /* Subversion >= 1.7 has ".svn" directory in the root of the working copy. Check for
// ".svn/wc.db". Need to check for furthest parent as closer * furthest parent containing ".svn/wc.db". Need to check for furthest parent as closer
// parents may be svn:externals. * parents may be svn:externals. */
if (dir.exists()) {
QDir parentDir = dir; QDir parentDir = dir;
while (parentDir.cdUp()) { while (parentDir.cdUp()) {
if (checkSVNSubDir(parentDir, QLatin1String("wc.db"))) { if (checkSVNSubDir(parentDir, QLatin1String("wc.db"))) {
manages = true;
if (topLevel) if (topLevel)
*topLevel = parentDir.absolutePath(); *topLevel = parentDir.absolutePath();
return true;
} }
} }
}
do { /* Subversion < 1.7 has ".svn" directory in each directory
if (manages) * it manages. The top level is the first directory
break; * under the directory that does not have a ".svn".*/
if (!dir.exists() || !checkSVNSubDir(dir)) if (!checkSVNSubDir(dir))
break; return false;
manages = true;
if (!topLevel) if (topLevel) {
break;
/* Recursing up, the top level is a child of the first directory that does
* not have a ".svn" directory. The starting directory must be a managed
* one. Go up and try to find the first unmanaged parent dir. */
QDir lastDirectory = dir; QDir lastDirectory = dir;
for (QDir parentDir = lastDirectory; parentDir.cdUp() ; lastDirectory = parentDir) { for (parentDir = lastDirectory; parentDir.cdUp() ; lastDirectory = parentDir) {
if (!checkSVNSubDir(parentDir)) { if (!checkSVNSubDir(parentDir)) {
*topLevel = lastDirectory.absolutePath(); *topLevel = lastDirectory.absolutePath();
break; break;
} }
} }
} while (false);
if (Subversion::Constants::debug) {
QDebug nsp = qDebug().nospace();
nsp << "SubversionPlugin::managesDirectory" << directory << manages;
if (topLevel)
nsp << *topLevel;
} }
return manages; return false;
} }
// Check whether SVN management subdirs exist. // Check whether SVN management subdirs exist.