Commit c5c94206 authored by Tobias Hunger's avatar Tobias Hunger

VCS: Make initialization of a repo trigger updateActions

Make initialization/cloning of a repo trigger an updateActions.

This is needed to e.g. enable git actions after a git repo is created.

Reviewed-by: Hugues Delorme
Change-Id: Ia8513a216e584fe8e512fdd5d6215aa96c075f3f
Reviewed-on: http://codereview.qt-project.org/4878Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent d8c7dc8c
......@@ -85,9 +85,13 @@ public:
qDeleteAll(m_vcsInfoList);
}
VcsInfo *findInCache(const QString &directory)
VcsInfo *findInCache(const QString &dir)
{
const QMap<QString, VcsInfo *>::const_iterator it = m_cachedMatches.constFind(directory);
Q_ASSERT(QDir(dir).isAbsolute());
Q_ASSERT(!dir.endsWith(QLatin1Char('/')));
Q_ASSERT(QDir::fromNativeSeparators(dir) == dir);
const QMap<QString, VcsInfo *>::const_iterator it = m_cachedMatches.constFind(dir);
if (it != m_cachedMatches.constEnd())
return it.value();
return 0;
......@@ -108,9 +112,25 @@ public:
return result;
}
void cache(IVersionControl *vc, const QString topLevel, const QString directory)
void resetCache(const QString &dir)
{
Q_ASSERT(QDir(dir).isAbsolute());
Q_ASSERT(!dir.endsWith(QLatin1Char('/')));
Q_ASSERT(QDir::fromNativeSeparators(dir) == dir);
const QString dirSlash = dir + QLatin1Char('/');
foreach (const QString &key, m_cachedMatches.keys()) {
if (key == dir || key.startsWith(dirSlash))
m_cachedMatches.remove(key);
}
}
void cache(IVersionControl *vc, const QString topLevel, const QString dir)
{
Q_ASSERT(directory.startsWith(topLevel));
Q_ASSERT(QDir(dir).isAbsolute());
Q_ASSERT(!dir.endsWith(QLatin1Char('/')));
Q_ASSERT(QDir::fromNativeSeparators(dir) == dir);
Q_ASSERT(dir.startsWith(topLevel));
VcsInfo *newInfo = new VcsInfo(vc, topLevel);
bool createdNewInfo(true);
......@@ -126,7 +146,7 @@ public:
if (createdNewInfo)
m_vcsInfoList.append(newInfo);
QString tmpDir = directory;
QString tmpDir = dir;
while (tmpDir.count() >= topLevel.count() && tmpDir.count() > 0) {
m_cachedMatches.insert(tmpDir, newInfo);
int slashPos = tmpDir.lastIndexOf(SLASH);
......@@ -168,6 +188,17 @@ static bool longerThanPath(QPair<QString, IVersionControl *> &pair1, QPair<QStri
return pair1.first.size() > pair2.first.size();
}
void VcsManager::resetVersionControlForDirectory(const QString &inputDirectory)
{
if (inputDirectory.isEmpty())
return;
const QString directory = QDir(inputDirectory).absolutePath();
d->resetCache(directory);
emit repositoryChanged(directory);
}
IVersionControl* VcsManager::findVersionControlForDirectory(const QString &inputDirectory,
QString *topLevelDirectory)
{
......
......@@ -65,6 +65,7 @@ public:
void extensionsInitialized();
void resetVersionControlForDirectory(const QString &inputDirectory);
IVersionControl *findVersionControlForDirectory(const QString &directory,
QString *topLevelDirectory = 0);
IVersionControl *checkout(const QString &versionControlType,
......
......@@ -46,6 +46,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/id.h>
#include <coreplugin/filemanager.h>
#include <coreplugin/iversioncontrol.h>
......@@ -965,6 +966,11 @@ bool GitClient::synchronousInit(const QString &workingDirectory)
outputWindow()->append(commandOutputFromLocal8Bit(outputText));
if (!rc)
outputWindow()->appendError(commandOutputFromLocal8Bit(errorText));
else {
// TODO: Turn this into a VCSBaseClient and use resetCachedVcsInfo(...)
Core::VcsManager *vcsManager = m_core->vcsManager();
vcsManager->resetVersionControlForDirectory(workingDirectory);
}
return rc;
}
......@@ -2371,7 +2377,10 @@ bool GitClient::cloneRepository(const QString &directory,const QByteArray &url)
workingDirectory.cdUp();
const Utils::SynchronousProcessResponse resp =
synchronousGit(workingDirectory.path(), arguments, flags);
return resp.result == Utils::SynchronousProcessResponse::Finished;
// TODO: Turn this into a VCSBaseClient and use resetCachedVcsInfo(...)
Core::VcsManager *vcsManager = m_core->vcsManager();
vcsManager->resetVersionControlForDirectory(workingDirectory.absolutePath());
return (resp.result == Utils::SynchronousProcessResponse::Finished);
}
}
......
......@@ -39,6 +39,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/vcsmanager.h>
#include <utils/qtcassert.h>
#include <utils/synchronousprocess.h>
......@@ -166,6 +167,9 @@ bool VCSBaseClient::synchronousCreateRepository(const QString &workingDirectory,
QString output = QString::fromLocal8Bit(outputData);
output.remove(QLatin1Char('\r'));
VCSBase::VCSBaseOutputWindow::instance()->append(output);
resetCachedVcsInfo(workingDirectory);
return true;
}
......@@ -178,7 +182,9 @@ bool VCSBaseClient::synchronousClone(const QString &workingDir,
args << vcsCommandString(CloneCommand)
<< extraOptions << srcLocation << dstLocation;
QByteArray stdOut;
return vcsFullySynchronousExec(workingDir, args, &stdOut);
const bool cloneOk = vcsFullySynchronousExec(workingDir, args, &stdOut);
resetCachedVcsInfo(workingDir);
return cloneOk;
}
bool VCSBaseClient::synchronousAdd(const QString &workingDir, const QString &filename,
......@@ -567,6 +573,12 @@ VCSBase::VCSBaseEditorWidget *VCSBaseClient::createVCSEditor(const QString &kind
return baseEditor;
}
void VCSBaseClient::resetCachedVcsInfo(const QString &workingDir)
{
Core::VcsManager *vcsManager = d->m_core->vcsManager();
vcsManager->resetVersionControlForDirectory(workingDir);
}
void VCSBaseClient::enqueueJob(const QSharedPointer<VCSJob> &job)
{
if (!d->m_jobManager) {
......
......@@ -37,14 +37,11 @@
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QPair>
#include <QtCore/QSharedPointer>
#include <QtCore/QScopedPointer>
#include <QtCore/QVariant>
QT_BEGIN_NAMESPACE
class QFileInfo;
class QVariant;
QT_END_NAMESPACE
namespace Utils {
......@@ -179,6 +176,8 @@ protected:
const char *registerDynamicProperty,
const QString &dynamicPropertyValue) const;
void resetCachedVcsInfo(const QString &workingDir);
private:
friend class VCSBaseClientPrivate;
QScopedPointer<VCSBaseClientPrivate> d;
......
......@@ -209,6 +209,8 @@ StateListener::StateListener(QObject *parent) :
this, SLOT(slotStateChanged()));
connect(core->editorManager()->instance(), SIGNAL(currentEditorStateChanged(Core::IEditor*)),
this, SLOT(slotStateChanged()));
connect(core->vcsManager(), SIGNAL(repositoryChanged(QString)),
this, SLOT(slotStateChanged()));
if (ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance())
connect(pe, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
......
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