forked from qt-creator/qt-creator
Git: speed up findRepositoryForDirectory
Change-Id: I50ccb0f6e0e70f463e45feaea8237c434f5f76c4 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -367,25 +367,20 @@ QString GitClient::findRepositoryForDirectory(const QString &dir)
|
|||||||
{
|
{
|
||||||
if (dir.endsWith(QLatin1String("/.git")) || dir.contains(QLatin1String("/.git/")))
|
if (dir.endsWith(QLatin1String("/.git")) || dir.contains(QLatin1String("/.git/")))
|
||||||
return QString();
|
return QString();
|
||||||
// Find a directory to run git in:
|
|
||||||
const QString root = QDir::rootPath();
|
|
||||||
const QString home = QDir::homePath();
|
|
||||||
|
|
||||||
QDir directory(dir);
|
QDir directory(dir);
|
||||||
|
QString dotGit = QLatin1String(GIT_DIRECTORY);
|
||||||
|
// QFileInfo is outside loop, because it is faster this way
|
||||||
|
QFileInfo fileInfo;
|
||||||
do {
|
do {
|
||||||
const QString absDirPath = directory.absolutePath();
|
if (directory.exists(dotGit)) {
|
||||||
if (absDirPath == root || absDirPath == home)
|
fileInfo.setFile(directory, dotGit);
|
||||||
break;
|
if (fileInfo.isFile())
|
||||||
|
return directory.absolutePath();
|
||||||
if (directory.exists())
|
else if (directory.exists(QLatin1String(".git/config")))
|
||||||
break;
|
return directory.absolutePath();
|
||||||
|
}
|
||||||
} while (directory.cdUp());
|
} while (directory.cdUp());
|
||||||
|
return QString();
|
||||||
QByteArray outputText;
|
|
||||||
QStringList arguments;
|
|
||||||
arguments << QLatin1String("rev-parse") << QLatin1String("--show-toplevel");
|
|
||||||
fullySynchronousGit(directory.absolutePath(), arguments, &outputText, 0, false);
|
|
||||||
return QString::fromLocal8Bit(outputText.trimmed());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GitClient::findGitDirForRepository(const QString &repositoryDir)
|
QString GitClient::findGitDirForRepository(const QString &repositoryDir)
|
||||||
|
|||||||
Reference in New Issue
Block a user