Vcs: Add variables containing the Vcs name (Git, etc.) and topic

This allows to have the git branch names (or tags, etc.) in the
build path or to pass that information to scripts.

Task-number: QTCREATORBUG-10376
Change-Id: I151990bdc7b85abbb427b2afae220adb4e918f4f
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Tobias Hunger
2014-02-24 12:36:47 +01:00
parent ead00db2d3
commit 3804de5023
3 changed files with 47 additions and 0 deletions

View File

@@ -28,12 +28,20 @@
****************************************************************************/
#include "vcsplugin.h"
#include "vcsbaseconstants.h"
#include "commonsettingspage.h"
#include "nicknamedialog.h"
#include "vcsbaseoutputwindow.h"
#include "corelistener.h"
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/variablemanager.h>
#include <coreplugin/vcsmanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <QtPlugin>
#include <QDebug>
@@ -74,6 +82,15 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
connect(m_settingsPage, SIGNAL(settingsChanged(VcsBase::Internal::CommonVcsSettings)),
this, SLOT(slotSettingsChanged()));
slotSettingsChanged();
connect(Core::VariableManager::instance(), SIGNAL(variableUpdateRequested(QByteArray)),
this, SLOT(updateVariable(QByteArray)));
Core::VariableManager::registerVariable(Constants::VAR_VCS_NAME,
tr("Name of the version control system in use by the current project."));
Core::VariableManager::registerVariable(Constants::VAR_VCS_TOPIC,
tr("The current version control topic (branch or tag) identification of the current project."));
return true;
}
@@ -122,6 +139,32 @@ void VcsPlugin::slotSettingsChanged()
populateNickNameModel();
}
void VcsPlugin::updateVariable(const QByteArray &variable)
{
static ProjectExplorer::Project *cachedProject = 0;
static Core::IVersionControl *cachedVc = 0;
static QString cachedTopLevel;
ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
if (cachedProject != project) {
cachedVc = Core::VcsManager::findVersionControlForDirectory(project->projectDirectory(),
&cachedTopLevel);
cachedProject = project;
}
if (variable == Constants::VAR_VCS_NAME) {
if (cachedVc)
Core::VariableManager::insert(variable, cachedVc->displayName());
else
Core::VariableManager::remove(variable);
} else if (variable == Constants::VAR_VCS_TOPIC) {
if (cachedVc)
Core::VariableManager::insert(variable, cachedVc->vcsTopic(cachedTopLevel));
else
Core::VariableManager::remove(variable);
}
}
} // namespace Internal
} // namespace VcsBase