aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEike Ziller <[email protected]>2024-11-27 15:37:24 +0100
committerEike Ziller <[email protected]>2024-11-29 09:21:56 +0000
commit71be035eb3d1aa9f2bffbd6c1498c74ab06c4b50 (patch)
treebaf77e3c920f358297a5298ea455dc2c0b1a517c /src
parent38be6222ee03d1829fc98fd23af79c997968ea09 (diff)
VCS: Consolidate managesDirectory()
Most version control implementations use one or one of a set of specific files to find a toplevel directory for that version control. Share the code that searches for these. Change-Id: Ia308262018f79e59de33b862a020b8cb8138f17f Reviewed-by: Orgad Shaneh <[email protected]> Reviewed-by: AndrĂ© Hartmann <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/bazaar/bazaarplugin.cpp2
-rw-r--r--src/plugins/fossil/fossilplugin.cpp3
-rw-r--r--src/plugins/git/gitclient.cpp15
-rw-r--r--src/plugins/mercurial/mercurialplugin.cpp4
-rw-r--r--src/plugins/subversion/subversionplugin.cpp40
-rw-r--r--src/plugins/vcsbase/vcsbaseplugin.cpp30
-rw-r--r--src/plugins/vcsbase/vcsbaseplugin.h4
7 files changed, 26 insertions, 72 deletions
diff --git a/src/plugins/bazaar/bazaarplugin.cpp b/src/plugins/bazaar/bazaarplugin.cpp
index 277bcbab353..a8b0baa67c1 100644
--- a/src/plugins/bazaar/bazaarplugin.cpp
+++ b/src/plugins/bazaar/bazaarplugin.cpp
@@ -872,7 +872,7 @@ bool BazaarPluginPrivate::isVcsFileOrDirectory(const Utils::FilePath &fileName)
bool BazaarPluginPrivate::managesDirectory(const FilePath &directory, FilePath *topLevel) const
{
const FilePath topLevelFound = VcsBase::findRepositoryForFile(
- directory, QLatin1String(Constants::BAZAARREPO) + "/branch-format");
+ directory, {QString(Constants::BAZAARREPO) + "/branch-format"});
if (topLevel)
*topLevel = topLevelFound;
return !topLevelFound.isEmpty();
diff --git a/src/plugins/fossil/fossilplugin.cpp b/src/plugins/fossil/fossilplugin.cpp
index b52afbafcd7..3c28916a778 100644
--- a/src/plugins/fossil/fossilplugin.cpp
+++ b/src/plugins/fossil/fossilplugin.cpp
@@ -800,7 +800,8 @@ bool FossilPluginPrivate::isVcsFileOrDirectory(const FilePath &filePath) const
bool FossilPluginPrivate::managesDirectory(const FilePath &directory, FilePath *topLevel) const
{
- const FilePath topLevelFound = VcsBase::findRepositoryForFile(directory, Constants::FOSSILREPO);
+ const FilePath topLevelFound
+ = VcsBase::findRepositoryForFile(directory, {Constants::FOSSILREPO});
if (topLevel)
*topLevel = topLevelFound;
return !topLevelFound.isEmpty();
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index 5973851fa20..b7ac7428de9 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -59,7 +59,6 @@
#include <QRegularExpression>
#include <QTextCodec>
-const char GIT_DIRECTORY[] = ".git";
const char HEAD[] = "HEAD";
const char CHERRY_PICK_HEAD[] = "CHERRY_PICK_HEAD";
const char BRANCHES_PREFIX[] = "Branches: ";
@@ -838,19 +837,7 @@ GitSettings &GitClient::settings()
FilePath GitClient::findRepositoryForDirectory(const FilePath &directory) const
{
- if (directory.isEmpty() || directory.endsWith("/.git") || directory.path().contains("/.git/"))
- return {};
- FilePath parent;
- for (FilePath dir = directory; !dir.isEmpty(); dir = dir.parentDir()) {
- const FilePath gitName = dir.pathAppended(GIT_DIRECTORY);
- if (!gitName.exists())
- continue; // parent might exist
- if (gitName.isFile())
- return dir;
- if (gitName.pathAppended("config").exists())
- return dir;
- }
- return {};
+ return VcsBase::findRepositoryForFile(directory, {".git", ".git/config"});
}
FilePath GitClient::findGitDirForRepository(const FilePath &repositoryDir) const
diff --git a/src/plugins/mercurial/mercurialplugin.cpp b/src/plugins/mercurial/mercurialplugin.cpp
index 242ad0eec0a..d45af47fd18 100644
--- a/src/plugins/mercurial/mercurialplugin.cpp
+++ b/src/plugins/mercurial/mercurialplugin.cpp
@@ -655,8 +655,8 @@ bool MercurialPluginPrivate::isVcsFileOrDirectory(const FilePath &filePath) cons
bool MercurialPluginPrivate::managesDirectory(const FilePath &filePath, FilePath *topLevel) const
{
- const FilePath topLevelFound = VcsBase::findRepositoryForFile(
- filePath, QLatin1String(Constants::MERCURIALREPO) + "/requires");
+ const FilePath topLevelFound
+ = VcsBase::findRepositoryForFile(filePath, {QString(Constants::MERCURIALREPO) + "/requires"});
if (topLevel)
*topLevel = topLevelFound;
return !topLevelFound.isEmpty();
diff --git a/src/plugins/subversion/subversionplugin.cpp b/src/plugins/subversion/subversionplugin.cpp
index 406ecf2ef96..8c27cad92e0 100644
--- a/src/plugins/subversion/subversionplugin.cpp
+++ b/src/plugins/subversion/subversionplugin.cpp
@@ -216,7 +216,6 @@ private:
bool enableAnnotationContextMenu = false);
void svnStatus(const FilePath &workingDir, const QString &relativePath = {});
void svnUpdate(const FilePath &workingDir, const QString &relativePath = {});
- bool checkSVNSubDir(const QDir &directory) const;
void startCommit(const FilePath &workingDir, const QStringList &files = {});
const QStringList m_svnDirectories;
@@ -1024,25 +1023,13 @@ bool SubversionPluginPrivate::vcsCheckout(const FilePath &directory, const QByte
bool SubversionPluginPrivate::managesDirectory(const FilePath &directory, FilePath *topLevel /* = 0 */) const
{
- const QDir dir(directory.toString());
+ const QStringList filesToCheck = transform(m_svnDirectories, [](const QString &s) {
+ return QString(s + "/wc.db");
+ });
+ const FilePath topLevelFound = VcsBase::findRepositoryForFile(directory, filesToCheck);
if (topLevel)
- topLevel->clear();
-
- /* Subversion >= 1.7 has ".svn" directory in the root of the working copy. Check for
- * furthest parent containing ".svn/wc.db". Need to check for furthest parent as closer
- * parents may be svn:externals. */
- QDir parentDir = dir;
- while (!parentDir.isRoot()) {
- if (checkSVNSubDir(parentDir)) {
- if (topLevel)
- *topLevel = FilePath::fromString(parentDir.absolutePath());
- return true;
- }
- if (!parentDir.cdUp())
- break;
- }
-
- return false;
+ *topLevel = topLevelFound;
+ return !topLevelFound.isEmpty();
}
bool SubversionPluginPrivate::managesFile(const FilePath &workingDirectory, const QString &fileName) const
@@ -1054,21 +1041,6 @@ bool SubversionPluginPrivate::managesFile(const FilePath &workingDirectory, cons
return output.isEmpty() || output.front() != QLatin1Char('?');
}
-// Check whether SVN management subdirs exist.
-bool SubversionPluginPrivate::checkSVNSubDir(const QDir &directory) const
-{
- const int dirCount = m_svnDirectories.size();
- for (int i = 0; i < dirCount; i++) {
- const QDir svnDir(directory.absoluteFilePath(m_svnDirectories.at(i)));
- if (!svnDir.exists())
- continue;
- if (!svnDir.exists(QLatin1String("wc.db")))
- continue;
- return true;
- }
- return false;
-}
-
Utils::Id SubversionPluginPrivate::id() const
{
return Utils::Id(VcsBase::Constants::VCS_ID_SUBVERSION);
diff --git a/src/plugins/vcsbase/vcsbaseplugin.cpp b/src/plugins/vcsbase/vcsbaseplugin.cpp
index 631eb0f248f..e8b051377f2 100644
--- a/src/plugins/vcsbase/vcsbaseplugin.cpp
+++ b/src/plugins/vcsbase/vcsbaseplugin.cpp
@@ -712,27 +712,21 @@ void VersionControlBase::discardCommit()
// 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).
-FilePath findRepositoryForFile(const FilePath &fileOrDir, const QString &checkFile)
+FilePath findRepositoryForFile(const FilePath &fileOrDir, const QStringList &checkFiles)
{
const FilePath dirS = fileOrDir.isDir() ? fileOrDir : fileOrDir.parentDir();
- qCDebug(findRepoLog) << ">" << dirS << checkFile;
- QTC_ASSERT(!dirS.isEmpty() && !checkFile.isEmpty(), return {});
-
- const QString root = QDir::rootPath();
- const QString home = QDir::homePath();
-
- QDir directory(dirS.toString());
- do {
- const QString absDirPath = directory.absolutePath();
- if (absDirPath == root || absDirPath == home)
- break;
-
- if (QFileInfo(directory, checkFile).isFile()) {
- qCDebug(findRepoLog) << "<" << absDirPath;
- return FilePath::fromString(absDirPath);
+ qCDebug(findRepoLog) << ">" << dirS << checkFiles;
+ QTC_ASSERT(!dirS.isEmpty(), return {});
+
+ FilePath parent;
+ for (FilePath dir = dirS; !dir.isEmpty() && !dir.isRootPath(); dir = dir.parentDir()) {
+ for (const QString &checkFile : checkFiles) {
+ if (dir.pathAppended(checkFile).isFile()) {
+ qCDebug(findRepoLog) << "<" << dir.toUserOutput();
+ return dir;
+ }
}
- } while (!directory.isRoot() && directory.cdUp());
- qCDebug(findRepoLog) << "< bailing out at" << directory.absolutePath();
+ }
return {};
}
diff --git a/src/plugins/vcsbase/vcsbaseplugin.h b/src/plugins/vcsbase/vcsbaseplugin.h
index b1c9abf32a8..7d7f38b0e56 100644
--- a/src/plugins/vcsbase/vcsbaseplugin.h
+++ b/src/plugins/vcsbase/vcsbaseplugin.h
@@ -98,8 +98,8 @@ private:
// systems that do not have directories like "CVS" in each managed subdirectory
// but have a directory at the top of the repository like ".git" containing
// a well known file. See implementation for gory details.
-VCSBASE_EXPORT Utils::FilePath findRepositoryForFile(const Utils::FilePath &fileOrDir,
- const QString &checkFile);
+VCSBASE_EXPORT Utils::FilePath findRepositoryForFile(
+ const Utils::FilePath &fileOrDir, const QStringList &checkFiles);
// Set up the environment for a version control command line call.
// Sets up SSH graphical password prompting (note that the latter