forked from qt-creator/qt-creator
IVersionControl: Implement topic cache in the base class
Derivatives need to derive TopicCache, implement its pure virtual functions and pass it in IVersionControl's constructor. Change-Id: I3a904c84541fda95eee75296f86441c4bae55d79 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
c68ebeed2e
commit
cd48c5e513
@@ -2024,28 +2024,13 @@ bool GitClient::synchronousHeadRefs(const QString &workingDirectory, QStringList
|
||||
return true;
|
||||
}
|
||||
|
||||
struct TopicData
|
||||
{
|
||||
QDateTime timeStamp;
|
||||
QString topic;
|
||||
};
|
||||
|
||||
// Retrieve topic (branch, tag or HEAD hash)
|
||||
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;
|
||||
// First try to find branch
|
||||
QString branch = synchronousCurrentLocalBranch(workingDirectory);
|
||||
if (!branch.isEmpty())
|
||||
return data.topic = branch;
|
||||
return branch;
|
||||
|
||||
// Detached HEAD, try a tag or remote branch
|
||||
QStringList references;
|
||||
@@ -2059,10 +2044,8 @@ QString GitClient::synchronousTopic(const QString &workingDirectory)
|
||||
|
||||
foreach (const QString &ref, references) {
|
||||
int derefInd = ref.indexOf(dereference);
|
||||
if (ref.startsWith(tagStart)) {
|
||||
return data.topic = ref.mid(tagStart.size(),
|
||||
(derefInd == -1) ? -1 : derefInd - tagStart.size());
|
||||
}
|
||||
if (ref.startsWith(tagStart))
|
||||
return ref.mid(tagStart.size(), (derefInd == -1) ? -1 : derefInd - tagStart.size());
|
||||
if (ref.startsWith(remoteStart)) {
|
||||
remoteBranch = ref.mid(remoteStart.size(),
|
||||
(derefInd == -1) ? -1 : derefInd - remoteStart.size());
|
||||
@@ -2070,7 +2053,7 @@ QString GitClient::synchronousTopic(const QString &workingDirectory)
|
||||
}
|
||||
|
||||
// No tag
|
||||
return data.topic = remoteBranch.isEmpty() ? tr("Detached HEAD") : remoteBranch;
|
||||
return remoteBranch.isEmpty() ? tr("Detached HEAD") : remoteBranch;
|
||||
}
|
||||
|
||||
bool GitClient::synchronousRevParseCmd(const QString &workingDirectory, const QString &ref,
|
||||
|
||||
@@ -38,7 +38,32 @@
|
||||
namespace Git {
|
||||
namespace Internal {
|
||||
|
||||
class GitTopicCache : public Core::IVersionControl::TopicCache
|
||||
{
|
||||
public:
|
||||
GitTopicCache(GitClient *client) :
|
||||
m_client(client)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
QString trackFile(const QString &repository)
|
||||
{
|
||||
const QString gitDir = m_client->findGitDirForRepository(repository);
|
||||
return gitDir.isEmpty() ? QString() : (gitDir + QLatin1String("/HEAD"));
|
||||
}
|
||||
|
||||
QString refreshTopic(const QString &repository)
|
||||
{
|
||||
return m_client->synchronousTopic(repository);
|
||||
}
|
||||
|
||||
private:
|
||||
GitClient *m_client;
|
||||
};
|
||||
|
||||
GitVersionControl::GitVersionControl(GitClient *client) :
|
||||
Core::IVersionControl(new GitTopicCache(client)),
|
||||
m_client(client)
|
||||
{
|
||||
}
|
||||
@@ -120,7 +145,7 @@ QString GitVersionControl::vcsGetRepositoryURL(const QString &directory)
|
||||
|
||||
QString GitVersionControl::vcsTopic(const QString &directory)
|
||||
{
|
||||
QString topic = m_client->synchronousTopic(directory);
|
||||
QString topic = Core::IVersionControl::vcsTopic(directory);
|
||||
const QString commandInProgress = m_client->commandInProgressDescription(directory);
|
||||
if (!commandInProgress.isEmpty())
|
||||
topic += QLatin1String(" (") + commandInProgress + QLatin1Char(')');
|
||||
|
||||
Reference in New Issue
Block a user