forked from qt-creator/qt-creator
Git: Cache synchronousTopic results
Refresh when HEAD timestamp changes Change-Id: Ibb365d03074dabb700a55b96a924e31fed26c6ab Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
6a58cdffc2
commit
5ec925f7e7
@@ -1109,26 +1109,42 @@ static inline QString msgCannotDetermineBranch(const QString &workingDirectory,
|
|||||||
return GitClient::tr("Cannot retrieve branch of \"%1\": %2").arg(QDir::toNativeSeparators(workingDirectory), why);
|
return GitClient::tr("Cannot retrieve branch of \"%1\": %2").arg(QDir::toNativeSeparators(workingDirectory), why);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TopicData
|
||||||
|
{
|
||||||
|
QDateTime timeStamp;
|
||||||
|
QString topic;
|
||||||
|
};
|
||||||
|
|
||||||
// Retrieve head branch
|
// Retrieve head branch
|
||||||
QString GitClient::synchronousTopic(const QString &workingDirectory)
|
QString GitClient::synchronousTopic(const QString &workingDirectory)
|
||||||
{
|
{
|
||||||
|
static QHash<QString, TopicData> topicCache;
|
||||||
|
QString gitDir = findGitDirForRepository(workingDirectory);
|
||||||
|
if (gitDir.isEmpty())
|
||||||
|
return QString();
|
||||||
|
TopicData &data = topicCache[gitDir];
|
||||||
|
QDateTime lastModified = QFileInfo(gitDir + QLatin1String("/HEAD")).lastModified();
|
||||||
|
if (lastModified == data.timeStamp)
|
||||||
|
return data.topic;
|
||||||
|
data.timeStamp = lastModified;
|
||||||
QByteArray outputTextData;
|
QByteArray outputTextData;
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << QLatin1String("symbolic-ref") << QLatin1String("HEAD");
|
arguments << QLatin1String("symbolic-ref") << QLatin1String("HEAD");
|
||||||
// if HEAD is detached, the command is expected to fail.
|
// First try to find branch
|
||||||
if (!fullySynchronousGit(workingDirectory, arguments, &outputTextData))
|
if (fullySynchronousGit(workingDirectory, arguments, &outputTextData)) {
|
||||||
return QString();
|
QString branch = commandOutputFromLocal8Bit(outputTextData.trimmed());
|
||||||
QString branch = commandOutputFromLocal8Bit(outputTextData);
|
|
||||||
branch.remove(QLatin1Char('\n'));
|
|
||||||
|
|
||||||
// Must strip the "refs/heads/" prefix manually since the --short switch
|
// Must strip the "refs/heads/" prefix manually since the --short switch
|
||||||
// of git symbolic-ref only got introduced with git 1.7.10, which is not
|
// of git symbolic-ref only got introduced with git 1.7.10, which is not
|
||||||
// available for all popular Linux distributions yet.
|
// available for all popular Linux distributions yet.
|
||||||
const QString refsHeadsPrefix = QLatin1String("refs/heads/");
|
const QString refsHeadsPrefix = QLatin1String("refs/heads/");
|
||||||
if (branch.startsWith(refsHeadsPrefix))
|
if (branch.startsWith(refsHeadsPrefix))
|
||||||
branch.remove(0, refsHeadsPrefix.count());
|
branch.remove(0, refsHeadsPrefix.count());
|
||||||
|
|
||||||
return branch;
|
return data.topic = branch;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve head revision
|
// Retrieve head revision
|
||||||
|
|||||||
Reference in New Issue
Block a user