Commit 3804de50 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

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: default avatarEike Ziller <eike.ziller@digia.com>
parent ead00db2
......@@ -49,6 +49,9 @@ const char VCS_ID_SUBVERSION[] = "J.Subversion";
const char VCS_ID_PERFORCE[] = "P.Perforce";
const char VCS_ID_CVS[] = "Z.CVS";
const char VAR_VCS_NAME[] = "CurrentProject:VcsName";
const char VAR_VCS_TOPIC[] = "CurrentProject:VcsTopic";
} // namespace Constants
} // namespace VcsBase
......
......@@ -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
......
......@@ -72,6 +72,7 @@ signals:
private slots:
void slotSettingsChanged();
void updateVariable(const QByteArray &variable);
private:
void populateNickNameModel();
......
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