2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "vcsmanager.h"
|
|
|
|
|
#include "iversioncontrol.h"
|
2009-12-21 11:08:20 +01:00
|
|
|
#include "icore.h"
|
2012-02-14 16:43:51 +01:00
|
|
|
#include "documentmanager.h"
|
2013-06-11 13:59:06 +03:00
|
|
|
#include "idocument.h"
|
|
|
|
|
#include "infobar.h"
|
|
|
|
|
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <coreplugin/dialogs/addtovcsdialog.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-06-14 00:03:27 +02:00
|
|
|
#include <vcsbase/vcsbaseconstants.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2010-01-11 15:22:17 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QMap>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QMessageBox>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
2008-12-03 15:04:51 +01:00
|
|
|
typedef QList<IVersionControl *> VersionControlList;
|
|
|
|
|
|
|
|
|
|
static inline VersionControlList allVersionControls()
|
|
|
|
|
{
|
2012-06-18 11:34:15 +02:00
|
|
|
return ExtensionSystem::PluginManager::getObjects<IVersionControl>();
|
2008-12-03 15:04:51 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-06 13:38:36 +01:00
|
|
|
#if defined(WITH_TESTS)
|
|
|
|
|
const char TEST_PREFIX[] = "/8E3A9BA0-0B97-40DF-AEC1-2BDF9FC9EDBE/";
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
// ---- VCSManagerPrivate:
|
|
|
|
|
// Maintains a cache of top-level directory->version control.
|
|
|
|
|
|
2010-12-07 17:34:43 +01:00
|
|
|
class VcsManagerPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2011-04-08 13:44:48 +02:00
|
|
|
class VcsInfo {
|
|
|
|
|
public:
|
|
|
|
|
VcsInfo(IVersionControl *vc, const QString &tl) :
|
|
|
|
|
versionControl(vc), topLevel(tl)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
bool operator == (const VcsInfo &other) const
|
|
|
|
|
{
|
|
|
|
|
return versionControl == other.versionControl &&
|
|
|
|
|
topLevel == other.topLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IVersionControl *versionControl;
|
|
|
|
|
QString topLevel;
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-11 13:59:06 +03:00
|
|
|
VcsManagerPrivate() : m_unconfiguredVcs(0)
|
|
|
|
|
{ }
|
|
|
|
|
|
2011-04-08 13:44:48 +02:00
|
|
|
~VcsManagerPrivate()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_vcsInfoList);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-13 15:05:50 +00:00
|
|
|
VcsInfo *findInCache(const QString &dir)
|
2011-04-08 13:44:48 +02:00
|
|
|
{
|
2012-01-12 11:32:45 +01:00
|
|
|
QTC_ASSERT(QDir(dir).isAbsolute(), return 0);
|
|
|
|
|
QTC_ASSERT(!dir.endsWith(QLatin1Char('/')), return 0);
|
|
|
|
|
QTC_ASSERT(QDir::fromNativeSeparators(dir) == dir, return 0);
|
2011-09-13 15:05:50 +00:00
|
|
|
|
|
|
|
|
const QMap<QString, VcsInfo *>::const_iterator it = m_cachedMatches.constFind(dir);
|
2011-04-08 13:44:48 +02:00
|
|
|
if (it != m_cachedMatches.constEnd())
|
|
|
|
|
return it.value();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VcsInfo *findUpInCache(const QString &directory)
|
|
|
|
|
{
|
|
|
|
|
VcsInfo *result = 0;
|
2011-12-22 14:44:14 +01:00
|
|
|
const QChar slash = QLatin1Char('/');
|
2011-04-08 13:44:48 +02:00
|
|
|
// Split the path, trying to find the matching repository. We start from the reverse
|
|
|
|
|
// in order to detected nested repositories correctly (say, a git checkout under SVN).
|
2011-12-22 14:44:14 +01:00
|
|
|
for (int pos = directory.size() - 1; pos >= 0; pos = directory.lastIndexOf(slash, pos) - 1) {
|
2011-04-08 13:44:48 +02:00
|
|
|
const QString directoryPart = directory.left(pos);
|
|
|
|
|
result = findInCache(directoryPart);
|
|
|
|
|
if (result != 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-03 18:53:44 +02:00
|
|
|
void clearCache()
|
|
|
|
|
{
|
|
|
|
|
m_cachedMatches.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-12 14:27:40 +01:00
|
|
|
void resetCache(const QString &dir)
|
2011-09-13 15:05:50 +00:00
|
|
|
{
|
2012-01-12 14:27:40 +01:00
|
|
|
QTC_ASSERT(QDir(dir).isAbsolute(), return);
|
|
|
|
|
QTC_ASSERT(!dir.endsWith(QLatin1Char('/')), return);
|
|
|
|
|
QTC_ASSERT(QDir::fromNativeSeparators(dir) == dir, return);
|
|
|
|
|
|
2011-09-13 15:05:50 +00:00
|
|
|
const QString dirSlash = dir + QLatin1Char('/');
|
|
|
|
|
foreach (const QString &key, m_cachedMatches.keys()) {
|
|
|
|
|
if (key == dir || key.startsWith(dirSlash))
|
|
|
|
|
m_cachedMatches.remove(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-12 14:27:40 +01:00
|
|
|
void cache(IVersionControl *vc, const QString &topLevel, const QString &dir)
|
2011-04-08 13:44:48 +02:00
|
|
|
{
|
2012-01-12 14:27:40 +01:00
|
|
|
QTC_ASSERT(QDir(dir).isAbsolute(), return);
|
|
|
|
|
QTC_ASSERT(!dir.endsWith(QLatin1Char('/')), return);
|
|
|
|
|
QTC_ASSERT(QDir::fromNativeSeparators(dir) == dir, return);
|
2012-01-13 14:26:26 +01:00
|
|
|
QTC_ASSERT(dir.startsWith(topLevel + QLatin1Char('/'))
|
|
|
|
|
|| topLevel == dir || topLevel.isEmpty(), return);
|
|
|
|
|
QTC_ASSERT((topLevel.isEmpty() && !vc) || (!topLevel.isEmpty() && vc), return);
|
2012-01-12 14:27:40 +01:00
|
|
|
|
2011-04-08 13:44:48 +02:00
|
|
|
VcsInfo *newInfo = new VcsInfo(vc, topLevel);
|
|
|
|
|
bool createdNewInfo(true);
|
|
|
|
|
// Do we have a matching VcsInfo already?
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (VcsInfo *i, m_vcsInfoList) {
|
2011-04-08 13:44:48 +02:00
|
|
|
if (*i == *newInfo) {
|
|
|
|
|
delete newInfo;
|
|
|
|
|
newInfo = i;
|
|
|
|
|
createdNewInfo = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (createdNewInfo)
|
|
|
|
|
m_vcsInfoList.append(newInfo);
|
|
|
|
|
|
2011-09-13 15:05:50 +00:00
|
|
|
QString tmpDir = dir;
|
2011-12-22 14:44:14 +01:00
|
|
|
const QChar slash = QLatin1Char('/');
|
2013-03-11 22:02:29 +02:00
|
|
|
while (tmpDir.count() >= topLevel.count() && !tmpDir.isEmpty()) {
|
2011-04-08 13:44:48 +02:00
|
|
|
m_cachedMatches.insert(tmpDir, newInfo);
|
2013-03-11 22:02:29 +02:00
|
|
|
// if no vc was found, this might mean we're inside a repo internal directory (.git)
|
|
|
|
|
// Cache only input directory, not parents
|
|
|
|
|
if (!vc)
|
|
|
|
|
break;
|
2011-12-22 14:44:14 +01:00
|
|
|
const int slashPos = tmpDir.lastIndexOf(slash);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (slashPos >= 0)
|
2011-12-22 14:44:14 +01:00
|
|
|
tmpDir.truncate(slashPos);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2011-12-22 14:44:14 +01:00
|
|
|
tmpDir.clear();
|
2011-04-08 13:44:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMap<QString, VcsInfo *> m_cachedMatches;
|
|
|
|
|
QList<VcsInfo *> m_vcsInfoList;
|
2013-06-11 13:59:06 +03:00
|
|
|
IVersionControl *m_unconfiguredVcs;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2013-08-30 17:13:29 +02:00
|
|
|
static VcsManagerPrivate *d = 0;
|
|
|
|
|
static VcsManager *m_instance = 0;
|
2013-06-25 13:37:21 +02:00
|
|
|
|
2010-12-07 17:34:43 +01:00
|
|
|
VcsManager::VcsManager(QObject *parent) :
|
2013-06-25 13:37:21 +02:00
|
|
|
QObject(parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-08-30 17:13:29 +02:00
|
|
|
m_instance = this;
|
2013-06-25 13:37:21 +02:00
|
|
|
d = new VcsManagerPrivate;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-08 13:44:48 +02:00
|
|
|
// ---- VCSManager:
|
|
|
|
|
|
2010-12-07 17:34:43 +01:00
|
|
|
VcsManager::~VcsManager()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-08-30 17:13:29 +02:00
|
|
|
m_instance = 0;
|
2011-09-07 14:26:11 +02:00
|
|
|
delete d;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-27 15:57:51 +01:00
|
|
|
VcsManager *VcsManager::instance()
|
2013-08-30 17:13:29 +02:00
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-07 17:34:43 +01:00
|
|
|
void VcsManager::extensionsInitialized()
|
2009-11-11 14:32:54 +01:00
|
|
|
{
|
|
|
|
|
// Change signal connections
|
|
|
|
|
foreach (IVersionControl *versionControl, allVersionControls()) {
|
|
|
|
|
connect(versionControl, SIGNAL(filesChanged(QStringList)),
|
2012-02-14 16:43:51 +01:00
|
|
|
DocumentManager::instance(), SIGNAL(filesChangedInternally(QStringList)));
|
2009-11-11 14:32:54 +01:00
|
|
|
connect(versionControl, SIGNAL(repositoryChanged(QString)),
|
2013-08-30 17:13:29 +02:00
|
|
|
m_instance, SIGNAL(repositoryChanged(QString)));
|
2009-11-11 14:32:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-07 12:26:42 +01:00
|
|
|
static bool longerThanPath(QPair<QString, IVersionControl *> &pair1, QPair<QString, IVersionControl *> &pair2)
|
|
|
|
|
{
|
|
|
|
|
return pair1.first.size() > pair2.first.size();
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-13 15:05:50 +00:00
|
|
|
void VcsManager::resetVersionControlForDirectory(const QString &inputDirectory)
|
|
|
|
|
{
|
|
|
|
|
if (inputDirectory.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QString directory = QDir(inputDirectory).absolutePath();
|
|
|
|
|
|
|
|
|
|
d->resetCache(directory);
|
2013-08-30 17:13:29 +02:00
|
|
|
emit m_instance->repositoryChanged(directory);
|
2011-09-13 15:05:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-04 10:31:35 +02:00
|
|
|
IVersionControl* VcsManager::findVersionControlForDirectory(const QString &inputDirectory,
|
2009-12-08 14:26:41 +01:00
|
|
|
QString *topLevelDirectory)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-12-22 14:44:14 +01:00
|
|
|
typedef QPair<QString, IVersionControl *> StringVersionControlPair;
|
|
|
|
|
typedef QList<StringVersionControlPair> StringVersionControlPairs;
|
2013-11-28 14:20:46 +01:00
|
|
|
if (inputDirectory.isEmpty()) {
|
|
|
|
|
if (topLevelDirectory)
|
|
|
|
|
topLevelDirectory->clear();
|
2011-04-08 13:44:48 +02:00
|
|
|
return 0;
|
2013-11-28 14:20:46 +01:00
|
|
|
}
|
2010-05-20 16:24:39 +02:00
|
|
|
|
2013-01-30 11:28:47 +01:00
|
|
|
// Make sure we an absolute path:
|
2014-02-21 15:26:11 +01:00
|
|
|
QString directory = QDir(inputDirectory).absolutePath();
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
if (directory[0].isLetter() && directory.indexOf(QLatin1String(":") + QLatin1String(TEST_PREFIX)) == 1)
|
|
|
|
|
directory = directory.mid(2);
|
|
|
|
|
#endif
|
2011-09-07 14:26:11 +02:00
|
|
|
VcsManagerPrivate::VcsInfo *cachedData = d->findInCache(directory);
|
2011-04-08 13:44:48 +02:00
|
|
|
if (cachedData) {
|
2009-12-08 14:26:41 +01:00
|
|
|
if (topLevelDirectory)
|
2011-04-08 13:44:48 +02:00
|
|
|
*topLevelDirectory = cachedData->topLevel;
|
|
|
|
|
return cachedData->versionControl;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-08 13:44:48 +02:00
|
|
|
// Nothing: ask the IVersionControls directly.
|
2008-12-03 15:04:51 +01:00
|
|
|
const VersionControlList versionControls = allVersionControls();
|
2011-12-22 14:44:14 +01:00
|
|
|
StringVersionControlPairs allThatCanManage;
|
2010-12-07 12:26:42 +01:00
|
|
|
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (IVersionControl * versionControl, versionControls) {
|
2011-04-08 17:33:14 +02:00
|
|
|
QString topLevel;
|
2013-06-11 13:59:06 +03:00
|
|
|
if (versionControl->managesDirectory(directory, &topLevel))
|
2011-12-22 14:44:14 +01:00
|
|
|
allThatCanManage.push_back(StringVersionControlPair(topLevel, versionControl));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-12-07 12:26:42 +01:00
|
|
|
|
|
|
|
|
// To properly find a nested repository (say, git checkout inside SVN),
|
|
|
|
|
// we need to select the version control with the longest toplevel pathname.
|
|
|
|
|
qSort(allThatCanManage.begin(), allThatCanManage.end(), longerThanPath);
|
|
|
|
|
|
2011-04-08 13:44:48 +02:00
|
|
|
if (allThatCanManage.isEmpty()) {
|
2011-09-07 14:26:11 +02:00
|
|
|
d->cache(0, QString(), directory); // register that nothing was found!
|
2011-04-08 13:44:48 +02:00
|
|
|
|
|
|
|
|
// report result;
|
2010-12-07 12:26:42 +01:00
|
|
|
if (topLevelDirectory)
|
2011-04-08 13:44:48 +02:00
|
|
|
topLevelDirectory->clear();
|
|
|
|
|
return 0;
|
2010-12-07 12:26:42 +01:00
|
|
|
}
|
2011-04-08 13:44:48 +02:00
|
|
|
|
|
|
|
|
// Register Vcs(s) with the cache
|
2012-10-17 15:46:54 +02:00
|
|
|
QString tmpDir = QFileInfo(directory).canonicalFilePath();
|
2013-12-06 13:38:36 +01:00
|
|
|
#if defined WITH_TESTS
|
|
|
|
|
// Force caching of test directories (even though they do not exist):
|
|
|
|
|
if (directory.startsWith(QLatin1String(TEST_PREFIX)))
|
|
|
|
|
tmpDir = directory;
|
|
|
|
|
#endif
|
2013-10-11 16:10:08 +03:00
|
|
|
// directory might refer to a historical directory which doesn't exist.
|
|
|
|
|
// In this case, don't cache it.
|
|
|
|
|
if (!tmpDir.isEmpty()) {
|
|
|
|
|
const QChar slash = QLatin1Char('/');
|
|
|
|
|
const StringVersionControlPairs::const_iterator cend = allThatCanManage.constEnd();
|
|
|
|
|
for (StringVersionControlPairs::const_iterator i = allThatCanManage.constBegin(); i != cend; ++i) {
|
2013-10-30 11:21:20 +02:00
|
|
|
// If topLevel was already cached for another VC, skip this one
|
|
|
|
|
if (tmpDir.count() < i->first.count())
|
|
|
|
|
continue;
|
2013-10-11 16:10:08 +03:00
|
|
|
d->cache(i->second, i->first, tmpDir);
|
|
|
|
|
tmpDir = i->first;
|
|
|
|
|
const int slashPos = tmpDir.lastIndexOf(slash);
|
|
|
|
|
if (slashPos >= 0)
|
|
|
|
|
tmpDir.truncate(slashPos);
|
|
|
|
|
}
|
2011-04-08 13:44:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// return result
|
|
|
|
|
if (topLevelDirectory)
|
|
|
|
|
*topLevelDirectory = allThatCanManage.first().first;
|
2013-06-11 13:59:06 +03:00
|
|
|
IVersionControl *versionControl = allThatCanManage.first().second;
|
2013-06-13 20:40:18 +03:00
|
|
|
const bool isVcsConfigured = versionControl->isConfigured();
|
|
|
|
|
if (!isVcsConfigured || d->m_unconfiguredVcs) {
|
|
|
|
|
Id vcsWarning("VcsNotConfiguredWarning");
|
2013-07-09 11:52:44 +02:00
|
|
|
IDocument *curDocument = EditorManager::currentDocument();
|
2013-06-13 20:40:18 +03:00
|
|
|
if (isVcsConfigured) {
|
|
|
|
|
if (curDocument && d->m_unconfiguredVcs == versionControl) {
|
|
|
|
|
curDocument->infoBar()->removeInfo(vcsWarning);
|
|
|
|
|
d->m_unconfiguredVcs = 0;
|
2013-06-11 13:59:06 +03:00
|
|
|
}
|
2013-06-13 20:40:18 +03:00
|
|
|
return versionControl;
|
|
|
|
|
} else {
|
2013-06-26 14:02:45 +02:00
|
|
|
InfoBar *infoBar = curDocument ? curDocument->infoBar() : 0;
|
|
|
|
|
if (infoBar && infoBar->canInfoBeAdded(vcsWarning)) {
|
2013-06-13 20:40:18 +03:00
|
|
|
InfoBarEntry info(vcsWarning,
|
|
|
|
|
tr("%1 repository was detected but %1 is not configured.")
|
|
|
|
|
.arg(versionControl->displayName()),
|
|
|
|
|
InfoBarEntry::GlobalSuppressionEnabled);
|
|
|
|
|
d->m_unconfiguredVcs = versionControl;
|
2014-02-20 14:52:10 +01:00
|
|
|
info.setCustomButtonInfo(Core::ICore::msgShowOptionsDialog(), m_instance,
|
|
|
|
|
SLOT(configureVcs()));
|
2013-06-13 20:40:18 +03:00
|
|
|
infoBar->addInfo(info);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2013-06-11 13:59:06 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return versionControl;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-30 17:13:29 +02:00
|
|
|
QStringList VcsManager::repositories(const IVersionControl *vc)
|
2012-04-20 17:47:37 +02:00
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
foreach (const VcsManagerPrivate::VcsInfo *vi, d->m_vcsInfoList)
|
|
|
|
|
if (vi->versionControl == vc)
|
|
|
|
|
result.push_back(vi->topLevel);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-07 17:34:43 +01:00
|
|
|
bool VcsManager::promptToDelete(const QString &fileName)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-01-11 15:22:17 +01:00
|
|
|
if (IVersionControl *vc = findVersionControlForDirectory(QFileInfo(fileName).absolutePath()))
|
|
|
|
|
return promptToDelete(vc, fileName);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-07 17:34:43 +01:00
|
|
|
IVersionControl *VcsManager::checkout(const QString &versionControlType,
|
2010-09-29 12:16:35 +02:00
|
|
|
const QString &directory,
|
|
|
|
|
const QByteArray &url)
|
|
|
|
|
{
|
2010-09-29 12:16:37 +02:00
|
|
|
foreach (IVersionControl *versionControl, allVersionControls()) {
|
|
|
|
|
if (versionControl->displayName() == versionControlType
|
|
|
|
|
&& versionControl->supportsOperation(Core::IVersionControl::CheckoutOperation)) {
|
|
|
|
|
if (versionControl->vcsCheckout(directory, url)) {
|
2011-09-07 14:26:11 +02:00
|
|
|
d->cache(versionControl, directory, directory);
|
2010-09-29 12:16:35 +02:00
|
|
|
return versionControl;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-07 17:34:43 +01:00
|
|
|
bool VcsManager::promptToDelete(IVersionControl *vc, const QString &fileName)
|
2010-01-11 15:22:17 +01:00
|
|
|
{
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(vc, return true);
|
2010-01-11 15:22:17 +01:00
|
|
|
if (!vc->supportsOperation(IVersionControl::DeleteOperation))
|
2008-12-03 15:04:51 +01:00
|
|
|
return true;
|
2010-12-07 17:34:43 +01:00
|
|
|
const QString title = tr("Version Control");
|
|
|
|
|
const QString msg = tr("Would you like to remove this file from the version control system (%1)?\n"
|
|
|
|
|
"Note: This might remove the local file.").arg(vc->displayName());
|
2008-12-02 12:01:29 +01:00
|
|
|
const QMessageBox::StandardButton button =
|
|
|
|
|
QMessageBox::question(0, title, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
2008-12-03 15:04:51 +01:00
|
|
|
if (button != QMessageBox::Yes)
|
|
|
|
|
return true;
|
|
|
|
|
return vc->vcsDelete(fileName);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-07-27 15:43:00 +02:00
|
|
|
QString VcsManager::msgAddToVcsTitle()
|
|
|
|
|
{
|
|
|
|
|
return tr("Add to Version Control");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString VcsManager::msgPromptToAddToVcs(const QStringList &files, const IVersionControl *vc)
|
|
|
|
|
{
|
|
|
|
|
return files.size() == 1
|
|
|
|
|
? tr("Add the file\n%1\nto version control (%2)?")
|
|
|
|
|
.arg(files.front(), vc->displayName())
|
|
|
|
|
: tr("Add the files\n%1\nto version control (%2)?")
|
|
|
|
|
.arg(files.join(QString(QLatin1Char('\n'))), vc->displayName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString VcsManager::msgAddToVcsFailedTitle()
|
|
|
|
|
{
|
|
|
|
|
return tr("Adding to Version Control Failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString VcsManager::msgToAddToVcsFailed(const QStringList &files, const IVersionControl *vc)
|
|
|
|
|
{
|
|
|
|
|
return files.size() == 1
|
2013-10-17 13:48:04 +02:00
|
|
|
? tr("Could not add the file\n%1\nto version control (%2)")
|
|
|
|
|
.arg(files.front(), vc->displayName()) + QLatin1Char('\n')
|
2012-07-27 15:43:00 +02:00
|
|
|
: tr("Could not add the following files to version control (%1)\n%2")
|
|
|
|
|
.arg(vc->displayName(), files.join(QString(QLatin1Char('\n'))));
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-18 13:41:13 +04:00
|
|
|
void VcsManager::promptToAdd(const QString &directory, const QStringList &fileNames)
|
|
|
|
|
{
|
|
|
|
|
IVersionControl *vc = findVersionControlForDirectory(directory);
|
|
|
|
|
if (!vc || !vc->supportsOperation(Core::IVersionControl::AddOperation))
|
|
|
|
|
return;
|
|
|
|
|
|
2013-10-02 00:18:39 +03:00
|
|
|
QStringList unmanagedFiles;
|
|
|
|
|
QDir dir(directory);
|
|
|
|
|
foreach (const QString &fileName, fileNames) {
|
|
|
|
|
if (!vc->managesFile(directory, dir.relativeFilePath(fileName)))
|
|
|
|
|
unmanagedFiles << fileName;
|
|
|
|
|
}
|
|
|
|
|
if (unmanagedFiles.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2013-06-14 00:03:27 +02:00
|
|
|
Internal::AddToVcsDialog dlg(Core::ICore::mainWindow(), VcsManager::msgAddToVcsTitle(),
|
2013-10-02 00:18:39 +03:00
|
|
|
unmanagedFiles, vc->displayName());
|
2013-06-14 00:03:27 +02:00
|
|
|
if (dlg.exec() == QDialog::Accepted) {
|
2012-07-18 13:41:13 +04:00
|
|
|
QStringList notAddedToVc;
|
2013-10-02 00:18:39 +03:00
|
|
|
foreach (const QString &file, unmanagedFiles) {
|
2012-07-18 13:41:13 +04:00
|
|
|
if (!vc->vcsAdd(file))
|
|
|
|
|
notAddedToVc << file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!notAddedToVc.isEmpty()) {
|
2012-07-27 15:43:00 +02:00
|
|
|
QMessageBox::warning(Core::ICore::mainWindow(), VcsManager::msgAddToVcsFailedTitle(),
|
|
|
|
|
VcsManager::msgToAddToVcsFailed(notAddedToVc, vc));
|
2012-07-18 13:41:13 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-09 06:00:29 +03:00
|
|
|
void VcsManager::emitRepositoryChanged(const QString &repository)
|
|
|
|
|
{
|
2013-08-30 17:13:29 +02:00
|
|
|
emit m_instance->repositoryChanged(repository);
|
2013-06-09 06:00:29 +03:00
|
|
|
}
|
|
|
|
|
|
2013-06-03 18:53:44 +02:00
|
|
|
void VcsManager::clearVersionControlCache()
|
|
|
|
|
{
|
|
|
|
|
QStringList repoList = d->m_cachedMatches.keys();
|
|
|
|
|
d->clearCache();
|
|
|
|
|
foreach (const QString &repo, repoList)
|
2013-08-30 17:13:29 +02:00
|
|
|
emit m_instance->repositoryChanged(repo);
|
2013-06-03 18:53:44 +02:00
|
|
|
}
|
|
|
|
|
|
2013-06-11 13:59:06 +03:00
|
|
|
void VcsManager::configureVcs()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d->m_unconfiguredVcs, return);
|
|
|
|
|
ICore::showOptionsDialog(Id(VcsBase::Constants::VCS_SETTINGS_CATEGORY),
|
|
|
|
|
d->m_unconfiguredVcs->id());
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 15:08:31 +01:00
|
|
|
} // namespace Core
|
2013-12-06 13:38:36 +01:00
|
|
|
|
|
|
|
|
#if defined(WITH_TESTS)
|
|
|
|
|
|
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
|
|
#include "coreplugin.h"
|
|
|
|
|
#include "iversioncontrol.h"
|
|
|
|
|
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
const char ID_VCS_A[] = "A";
|
|
|
|
|
const char ID_VCS_B[] = "B";
|
|
|
|
|
|
|
|
|
|
typedef QHash<QString, QString> FileHash;
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
class ObjectPoolGuard
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ObjectPoolGuard(T *watch) : m_watched(watch)
|
|
|
|
|
{
|
|
|
|
|
ExtensionSystem::PluginManager::addObject(watch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
operator bool() { return m_watched; }
|
|
|
|
|
bool operator !() { return !m_watched; }
|
|
|
|
|
T &operator*() { return *m_watched; }
|
|
|
|
|
T *operator->() { return m_watched; }
|
|
|
|
|
T *value() { return m_watched; }
|
|
|
|
|
|
|
|
|
|
~ObjectPoolGuard()
|
|
|
|
|
{
|
|
|
|
|
ExtensionSystem::PluginManager::removeObject(m_watched);
|
|
|
|
|
delete m_watched;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
T *m_watched;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static FileHash makeHash(const QStringList &list)
|
|
|
|
|
{
|
|
|
|
|
FileHash result;
|
|
|
|
|
foreach (const QString &i, list) {
|
|
|
|
|
QStringList parts = i.split(QLatin1Char(':'));
|
|
|
|
|
QTC_ASSERT(parts.count() == 2, continue);
|
|
|
|
|
result.insert(QString::fromLatin1(TEST_PREFIX) + parts.at(0),
|
|
|
|
|
QString::fromLatin1(TEST_PREFIX) + parts.at(1));
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString makeString(const QString &s)
|
|
|
|
|
{
|
|
|
|
|
if (s.isEmpty())
|
|
|
|
|
return QString();
|
|
|
|
|
return QString::fromLatin1(TEST_PREFIX) + s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CorePlugin::testVcsManager_data()
|
|
|
|
|
{
|
|
|
|
|
// avoid conflicts with real files and directories:
|
|
|
|
|
|
|
|
|
|
QTest::addColumn<QStringList>("dirsVcsA"); // <directory>:<toplevel>
|
|
|
|
|
QTest::addColumn<QStringList>("dirsVcsB"); // <directory>:<toplevel>
|
|
|
|
|
// <directory>:<toplevel>:<vcsid>:<- from cache, * from VCS>
|
|
|
|
|
QTest::addColumn<QStringList>("results");
|
|
|
|
|
|
|
|
|
|
QTest::newRow("A and B next to each other")
|
|
|
|
|
<< (QStringList()
|
|
|
|
|
<< QLatin1String("a:a") << QLatin1String("a/1:a") << QLatin1String("a/2:a")
|
|
|
|
|
<< QLatin1String("a/2/5:a") << QLatin1String("a/2/5/6:a"))
|
|
|
|
|
<< (QStringList()
|
|
|
|
|
<< QLatin1String("b:b") << QLatin1String("b/3:b") << QLatin1String("b/4:b"))
|
|
|
|
|
<< (QStringList()
|
|
|
|
|
<< QLatin1String(":::-") // empty directory to look up
|
|
|
|
|
<< QLatin1String("c:::*") // Neither in A nor B
|
|
|
|
|
<< QLatin1String("a:a:A:*") // in A
|
|
|
|
|
<< QLatin1String("b:b:B:*") // in B
|
|
|
|
|
<< QLatin1String("b/3:b:B:*") // in B
|
|
|
|
|
<< QLatin1String("b/4:b:B:*") // in B
|
|
|
|
|
<< QLatin1String("a/1:a:A:*") // in A
|
|
|
|
|
<< QLatin1String("a/2:a:A:*") // in A
|
|
|
|
|
<< QLatin1String(":::-") // empty directory to look up
|
|
|
|
|
<< QLatin1String("a/2/5/6:a:A:*") // in A
|
|
|
|
|
<< QLatin1String("a/2/5:a:A:-") // in A (cached from before!)
|
|
|
|
|
// repeat: These need to come from the cache now:
|
|
|
|
|
<< QLatin1String("c:::-") // Neither in A nor B
|
|
|
|
|
<< QLatin1String("a:a:A:-") // in A
|
|
|
|
|
<< QLatin1String("b:b:B:-") // in B
|
|
|
|
|
<< QLatin1String("b/3:b:B:-") // in B
|
|
|
|
|
<< QLatin1String("b/4:b:B:-") // in B
|
|
|
|
|
<< QLatin1String("a/1:a:A:-") // in A
|
|
|
|
|
<< QLatin1String("a/2:a:A:-") // in A
|
|
|
|
|
<< QLatin1String("a/2/5/6:a:A:-") // in A
|
|
|
|
|
<< QLatin1String("a/2/5:a:A:-") // in A
|
|
|
|
|
);
|
|
|
|
|
QTest::newRow("B in A")
|
|
|
|
|
<< (QStringList()
|
|
|
|
|
<< QLatin1String("a:a") << QLatin1String("a/1:a") << QLatin1String("a/2:a")
|
|
|
|
|
<< QLatin1String("a/2/5:a") << QLatin1String("a/2/5/6:a"))
|
|
|
|
|
<< (QStringList()
|
|
|
|
|
<< QLatin1String("a/1/b:a/1/b") << QLatin1String("a/1/b/3:a/1/b")
|
|
|
|
|
<< QLatin1String("a/1/b/4:a/1/b") << QLatin1String("a/1/b/3/5:a/1/b")
|
|
|
|
|
<< QLatin1String("a/1/b/3/5/6:a/1/b"))
|
|
|
|
|
<< (QStringList()
|
|
|
|
|
<< QLatin1String("a:a:A:*") // in A
|
|
|
|
|
<< QLatin1String("c:::*") // Neither in A nor B
|
|
|
|
|
<< QLatin1String("a/3:::*") // Neither in A nor B
|
|
|
|
|
<< QLatin1String("a/1/b/x:::*") // Neither in A nor B
|
|
|
|
|
<< QLatin1String("a/1/b:a/1/b:B:*") // in B
|
|
|
|
|
<< QLatin1String("a/1:a:A:*") // in A
|
|
|
|
|
<< QLatin1String("a/1/b/../../2:a:A:*") // in A
|
|
|
|
|
);
|
|
|
|
|
QTest::newRow("A and B") // first one wins...
|
|
|
|
|
<< (QStringList() << QLatin1String("a:a") << QLatin1String("a/1:a") << QLatin1String("a/2:a"))
|
|
|
|
|
<< (QStringList() << QLatin1String("a:a") << QLatin1String("a/1:a") << QLatin1String("a/2:a"))
|
|
|
|
|
<< (QStringList() << QLatin1String("a/2:a:A:*"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CorePlugin::testVcsManager()
|
|
|
|
|
{
|
|
|
|
|
// setup:
|
|
|
|
|
ObjectPoolGuard<TestVersionControl> vcsA(new TestVersionControl(ID_VCS_A, QLatin1String("A")));
|
|
|
|
|
ObjectPoolGuard<TestVersionControl> vcsB(new TestVersionControl(ID_VCS_B, QLatin1String("B")));
|
|
|
|
|
|
|
|
|
|
// test:
|
|
|
|
|
QFETCH(QStringList, dirsVcsA);
|
|
|
|
|
QFETCH(QStringList, dirsVcsB);
|
|
|
|
|
QFETCH(QStringList, results);
|
|
|
|
|
|
|
|
|
|
vcsA->setManagedDirectories(makeHash(dirsVcsA));
|
|
|
|
|
vcsB->setManagedDirectories(makeHash(dirsVcsB));
|
|
|
|
|
|
|
|
|
|
QString realTopLevel = QLatin1String("ABC"); // Make sure this gets cleared if needed.
|
|
|
|
|
|
|
|
|
|
// From VCSes:
|
|
|
|
|
int expectedCount = 0;
|
|
|
|
|
foreach (const QString &result, results) {
|
|
|
|
|
// qDebug() << "Expecting:" << result;
|
|
|
|
|
|
|
|
|
|
QStringList split = result.split(QLatin1String(":"));
|
|
|
|
|
QCOMPARE(split.count(), 4);
|
|
|
|
|
QVERIFY(split.at(3) == QLatin1String("*") || split.at(3) == QLatin1String("-"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const QString directory = split.at(0);
|
|
|
|
|
const QString topLevel = split.at(1);
|
|
|
|
|
const QString vcsId = split.at(2);
|
|
|
|
|
bool fromCache = split.at(3) == QLatin1String("-");
|
|
|
|
|
|
|
|
|
|
if (!fromCache && !directory.isEmpty())
|
|
|
|
|
++expectedCount;
|
|
|
|
|
|
|
|
|
|
IVersionControl *vcs;
|
|
|
|
|
vcs = VcsManager::findVersionControlForDirectory(makeString(directory), &realTopLevel);
|
|
|
|
|
QCOMPARE(realTopLevel, makeString(topLevel));
|
|
|
|
|
if (vcs)
|
|
|
|
|
QCOMPARE(vcs->id().toString(), vcsId);
|
|
|
|
|
else
|
|
|
|
|
QCOMPARE(QString(), vcsId);
|
|
|
|
|
QCOMPARE(vcsA->dirCount(), expectedCount);
|
|
|
|
|
QCOMPARE(vcsA->fileCount(), 0);
|
|
|
|
|
QCOMPARE(vcsB->dirCount(), expectedCount);
|
|
|
|
|
QCOMPARE(vcsB->fileCount(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// teardown:
|
|
|
|
|
// handled by guards
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Core
|
|
|
|
|
|
|
|
|
|
#endif
|