Commit d9bfc67d authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Mercurial: Add cache for branch query



Change-Id: Ied6f2008324b80b9d4869ba17d67e6d55a91d08c
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent cd48c5e5
......@@ -39,6 +39,7 @@
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <QDateTime>
#include <QDir>
#include <QFileInfo>
#include <QTextCodec>
......@@ -155,10 +156,12 @@ bool MercurialClient::synchronousPull(const QString &workingDir, const QString &
QString MercurialClient::branchQuerySync(const QString &repositoryRoot)
{
QByteArray output;
if (vcsFullySynchronousExec(repositoryRoot, QStringList(QLatin1String("branch")), &output))
return QTextCodec::codecForLocale()->toUnicode(output).trimmed();
QFile branchFile(repositoryRoot + QLatin1String("/.hg/branch"));
if (branchFile.open(QFile::ReadOnly)) {
const QByteArray branch = branchFile.readAll().trimmed();
if (!branch.isEmpty())
return QString::fromLocal8Bit(branch);
}
return QLatin1String("Unknown Branch");
}
......
......@@ -33,6 +33,8 @@
#include <vcsbase/vcsbaseclientsettings.h>
#include <vcsbase/vcsbaseconstants.h>
#include <coreplugin/vcsmanager.h>
#include <QFileInfo>
#include <QVariant>
#include <QStringList>
......@@ -40,8 +42,29 @@
using namespace Mercurial::Internal;
class MercurialTopicCache : public Core::IVersionControl::TopicCache
{
public:
MercurialTopicCache(MercurialClient *client) : m_client(client) {}
protected:
QString trackFile(const QString &repository)
{
return repository + QLatin1String("/.hg/branch");
}
QString refreshTopic(const QString &repository)
{
return m_client->branchQuerySync(repository);
}
private:
MercurialClient *m_client;
};
MercurialControl::MercurialControl(MercurialClient *client)
: mercurialClient(client)
: Core::IVersionControl(new MercurialTopicCache(client))
, mercurialClient(client)
{
}
......@@ -136,11 +159,6 @@ bool MercurialControl::vcsAnnotate(const QString &file, int line)
return true;
}
QString MercurialControl::vcsTopic(const QString &directory)
{
return mercurialClient->branchQuerySync(directory);
}
bool MercurialControl::sccManaged(const QString &filename)
{
const QFileInfo fi(filename);
......
......@@ -65,7 +65,6 @@ public:
QString vcsGetRepositoryURL(const QString &directory);
bool sccManaged(const QString &filename);
bool vcsAnnotate(const QString &file, int line);
QString vcsTopic(const QString &directory);
public slots:
// To be connected to the HgTask's success signal to emit the repository/
......
......@@ -581,7 +581,7 @@ void MercurialPlugin::showCommitWidget(const QList<VcsBaseClient::StatusItem> &s
arg(QDir::toNativeSeparators(m_submitRepository));
commitEditor->document()->setDisplayName(msg);
QString branch = m_client->branchQuerySync(m_submitRepository);
QString branch = versionControl()->vcsTopic(m_submitRepository);
commitEditor->setFields(m_submitRepository, branch,
mercurialSettings.stringValue(MercurialSettings::userNameKey),
mercurialSettings.stringValue(MercurialSettings::userEmailKey), status);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment