forked from qt-creator/qt-creator
Vcs: Re-implement Fossil's topic indicator using a TopicCache sub-class
The functionality for tracking project's current topic/branch has long been folded into a base class Core::IVersionControl::TopicCache. Fossil plugin should just sub-class it and pass the instance to the base. Change-Id: I1b6c1631f5fc10987d8a608d573defeecbc31b37 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -568,36 +568,17 @@ QString FossilClient::synchronousGetRepositoryURL(const QString &workingDirector
|
||||
return output;
|
||||
}
|
||||
|
||||
struct TopicData
|
||||
{
|
||||
QDateTime timeStamp;
|
||||
QString topic;
|
||||
};
|
||||
|
||||
QString FossilClient::synchronousTopic(const QString &workingDirectory)
|
||||
{
|
||||
static QMap<QString, TopicData> topicCache;
|
||||
|
||||
if (workingDirectory.isEmpty())
|
||||
return QString();
|
||||
|
||||
// return current branch name
|
||||
|
||||
const QString topLevel = findTopLevelForFile(workingDirectory);
|
||||
const QFileInfo currentStateFile(topLevel + "/" + Constants::FOSSILREPO);
|
||||
|
||||
TopicData &data = topicCache[workingDirectory];
|
||||
const QDateTime lastModified = currentStateFile.lastModified();
|
||||
if (lastModified == data.timeStamp)
|
||||
return data.topic;
|
||||
|
||||
const BranchInfo branchInfo = synchronousCurrentBranch(workingDirectory);
|
||||
if (branchInfo.name().isEmpty())
|
||||
return QString();
|
||||
|
||||
data.timeStamp = lastModified;
|
||||
data.topic = branchInfo.name();
|
||||
return data.topic;
|
||||
return branchInfo.name();
|
||||
}
|
||||
|
||||
bool FossilClient::synchronousCreateRepository(const QString &workingDirectory, const QStringList &extraOptions)
|
||||
|
||||
@@ -41,9 +41,33 @@
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
|
||||
using namespace Fossil::Internal;
|
||||
namespace Fossil {
|
||||
namespace Internal {
|
||||
|
||||
class FossilTopicCache : public Core::IVersionControl::TopicCache
|
||||
{
|
||||
public:
|
||||
FossilTopicCache(FossilClient *client) :
|
||||
m_client(client)
|
||||
{ }
|
||||
|
||||
protected:
|
||||
QString trackFile(const QString &repository) final
|
||||
{
|
||||
return repository + "/" + Constants::FOSSILREPO;
|
||||
}
|
||||
|
||||
QString refreshTopic(const QString &repository) final
|
||||
{
|
||||
return m_client->synchronousTopic(repository);
|
||||
}
|
||||
|
||||
private:
|
||||
FossilClient *m_client;
|
||||
};
|
||||
|
||||
FossilControl::FossilControl(FossilClient *client) :
|
||||
Core::IVersionControl(new FossilTopicCache(client)),
|
||||
m_client(client)
|
||||
{ }
|
||||
|
||||
@@ -156,11 +180,6 @@ bool FossilControl::vcsAnnotate(const QString &file, int line)
|
||||
return true;
|
||||
}
|
||||
|
||||
QString FossilControl::vcsTopic(const QString &directory)
|
||||
{
|
||||
return m_client->synchronousTopic(directory);
|
||||
}
|
||||
|
||||
Core::ShellCommand *FossilControl::createInitialCheckoutCommand(const QString &sourceUrl,
|
||||
const Utils::FileName &baseDirectory,
|
||||
const QString &localName,
|
||||
@@ -287,3 +306,6 @@ void FossilControl::changed(const QVariant &v)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Fossil
|
||||
|
||||
@@ -59,7 +59,6 @@ public:
|
||||
bool vcsMove(const QString &from, const QString &to) final;
|
||||
bool vcsCreateRepository(const QString &directory) final;
|
||||
bool vcsAnnotate(const QString &file, int line) final;
|
||||
QString vcsTopic(const QString &directory) final;
|
||||
Core::ShellCommand *createInitialCheckoutCommand(const QString &sourceUrl,
|
||||
const Utils::FileName &baseDirectory,
|
||||
const QString &localName,
|
||||
|
||||
Reference in New Issue
Block a user