diff --git a/plugins/bazaar/bazaarplugin.cpp b/plugins/bazaar/bazaarplugin.cpp
index 31853d928a..e4463a5ff7 100644
--- a/plugins/bazaar/bazaarplugin.cpp
+++ b/plugins/bazaar/bazaarplugin.cpp
@@ -1,336 +1,346 @@
/***************************************************************************
* Copyright 2013-2014 Maciej Poleski *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License or (at your option) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
#include "bazaarplugin.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "bazaarutils.h"
#include "bzrannotatejob.h"
#include "copyjob.h"
#include "diffjob.h"
using namespace KDevelop;
BazaarPlugin::BazaarPlugin(QObject* parent, const QVariantList& args) :
IPlugin(QStringLiteral("kdevbazaar"), parent),
m_vcsPluginHelper(new KDevelop::VcsPluginHelper(this, this))
{
Q_UNUSED(args); // What is this?
if (QStandardPaths::findExecutable(QStringLiteral("bzr")).isEmpty()) {
setErrorDescription(i18n("Unable to find Bazaar (bzr) executable Is it installed on the system?"));
return;
}
setObjectName(QStringLiteral("Bazaar"));
}
BazaarPlugin::~BazaarPlugin()
{
}
QString BazaarPlugin::name() const
{
return QStringLiteral("Bazaar");
}
+bool BazaarPlugin::isValidRemoteRepositoryUrl(const QUrl& remoteLocation)
+{
+ const QString scheme = remoteLocation.scheme();
+ if (scheme == QLatin1String("bzr") ||
+ scheme == QLatin1String("bzr+ssh")) {
+ return true;
+ }
+ return false;
+}
+
VcsJob* BazaarPlugin::add(const QList& localLocations, IBasicVersionControl::RecursionMode recursion)
{
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localLocations[0]), this);
job->setType(VcsJob::Add);
*job << "bzr" << "add";
if(recursion == NonRecursive)
*job << "--no-recurse";
*job << localLocations;
return job;
}
VcsJob* BazaarPlugin::annotate(const QUrl& localLocation, const VcsRevision& rev)
{
VcsJob* job = new BzrAnnotateJob(BazaarUtils::workingCopy(localLocation), BazaarUtils::getRevisionSpec(rev), localLocation, this, KDevelop::OutputJob::Silent);
return job;
}
VcsJob* BazaarPlugin::commit(const QString& message, const QList& localLocations, IBasicVersionControl::RecursionMode recursion)
{
QDir dir = BazaarUtils::workingCopy(localLocations[0]);
DVcsJob* job = new DVcsJob(dir, this);
job->setType(VcsJob::Commit);
*job << "bzr" << "commit" << BazaarUtils::handleRecursion(localLocations, recursion) << "-m" << message;
return job;
}
VcsJob* BazaarPlugin::copy(const QUrl& localLocationSrc, const QUrl& localLocationDstn)
{
return new CopyJob(localLocationSrc, localLocationDstn, this);
}
VcsImportMetadataWidget* BazaarPlugin::createImportMetadataWidget(QWidget* parent)
{
return new DvcsImportMetadataWidget(parent);
}
VcsJob* BazaarPlugin::createWorkingCopy(const VcsLocation& sourceRepository, const QUrl& destinationDirectory, IBasicVersionControl::RecursionMode recursion)
{
Q_UNUSED(recursion);
// What is the purpose of recursion parameter?
DVcsJob* job = new DVcsJob(BazaarUtils::toQDir(sourceRepository.localUrl()), this);
job->setType(VcsJob::Import);
*job << "bzr" << "branch" << sourceRepository.localUrl().url() << destinationDirectory;
return job;
}
VcsJob* BazaarPlugin::diff(const QUrl& fileOrDirectory, const VcsRevision& srcRevision, const VcsRevision& dstRevision, VcsDiff::Type, IBasicVersionControl::RecursionMode recursion)
{
Q_UNUSED(recursion);
VcsJob* job = new DiffJob(BazaarUtils::workingCopy(fileOrDirectory), BazaarUtils::getRevisionSpecRange(srcRevision, dstRevision), fileOrDirectory, this);
return job;
}
VcsJob* BazaarPlugin::init(const QUrl& localRepositoryRoot)
{
DVcsJob* job = new DVcsJob(BazaarUtils::toQDir(localRepositoryRoot), this);
job->setType(VcsJob::Import);
*job << "bzr" << "init";
return job;
}
bool BazaarPlugin::isVersionControlled(const QUrl& localLocation)
{
QDir workCopy = BazaarUtils::workingCopy(localLocation);
DVcsJob* job = new DVcsJob(workCopy, this, OutputJob::Silent);
job->setType(VcsJob::Unknown);
job->setIgnoreError(true);
*job << "bzr" << "ls" << "--from-root" << "-R" << "-V";
job->exec();
if (job->status() == VcsJob::JobSucceeded) {
QList filesAndDirectoriesList;
foreach (const QString& fod, job->output().split('\n')) {
filesAndDirectoriesList.append(QFileInfo(workCopy.absolutePath() + QDir::separator() + fod));
}
QFileInfo fi(localLocation.toLocalFile());
if (fi.isDir() || fi.isFile()) {
QFileInfo file(localLocation.toLocalFile());
return filesAndDirectoriesList.contains(file);
}
}
return false;
}
VcsJob* BazaarPlugin::log(const QUrl& localLocation, const VcsRevision& rev, long unsigned int limit)
{
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localLocation), this);
job->setType(VcsJob::Log);
*job << "bzr" << "log" << "--long" << "-v" << localLocation << BazaarUtils::getRevisionSpecRange(rev) << "-l" << QString::number(limit);
connect(job, &DVcsJob::readyForParsing, this, &BazaarPlugin::parseBzrLog);
return job;
}
VcsJob* BazaarPlugin::log(const QUrl& localLocation, const VcsRevision& rev, const VcsRevision& limit)
{
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localLocation), this);
job->setType(VcsJob::Log);
*job << "bzr" << "log" << "--long" << "-v" << localLocation << BazaarUtils::getRevisionSpecRange(limit, rev);
connect(job, &DVcsJob::readyForParsing, this, &BazaarPlugin::parseBzrLog);
return job;
}
void BazaarPlugin::parseBzrLog(DVcsJob* job)
{
QVariantList result;
auto parts = job->output().split(QStringLiteral("------------------------------------------------------------"), QString::SkipEmptyParts);
foreach (const QString& part, parts) {
auto event = BazaarUtils::parseBzrLogPart(part);
if (event.revision().revisionType() != VcsRevision::Invalid)
result.append(QVariant::fromValue(event));
}
job->setResults(result);
}
VcsJob* BazaarPlugin::move(const QUrl& localLocationSrc, const QUrl& localLocationDst)
{
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localLocationSrc), this);
job->setType(VcsJob::JobType::Move);
*job << "bzr" << "move" << localLocationSrc << localLocationDst;
return job;
}
VcsJob* BazaarPlugin::pull(const VcsLocation& localOrRepoLocationSrc, const QUrl& localRepositoryLocation)
{
// API describes hg pull which is git fetch equivalent
// bzr has pull, but it succeeds only if fast-forward is possible
// in other cases bzr merge should be used instead (bzr pull would fail)
// Information about repository must be provided at least once.
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localRepositoryLocation), this);
job->setType(VcsJob::JobType::Pull);
*job << "bzr" << "pull";
if (!localOrRepoLocationSrc.localUrl().isEmpty()) {
*job << localOrRepoLocationSrc.localUrl();
}
// localUrl always makes sense. Even on remote repositores which are handled
// transparently.
return job;
}
VcsJob* BazaarPlugin::push(const QUrl& localRepositoryLocation, const VcsLocation& localOrRepoLocationDst)
{
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localRepositoryLocation), this);
job->setType(VcsJob::JobType::Push);
*job << "bzr" << "push" << localOrRepoLocationDst.localUrl();
// localUrl always makes sense. Even on remote repositores which are handled
// transparently.
return job;
}
VcsJob* BazaarPlugin::remove(const QList& localLocations)
{
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localLocations[0]), this);
job->setType(VcsJob::JobType::Remove);
*job << "bzr" << "remove" << localLocations;
return job;
}
VcsJob* BazaarPlugin::repositoryLocation(const QUrl& localLocation)
{
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localLocation), this);
job->setType(VcsJob::JobType::Unknown);
*job << "bzr" << "root" << localLocation; // It is only to make sure
connect(job, &DVcsJob::readyForParsing, this, &BazaarPlugin::parseBzrRoot);
return job;
}
void BazaarPlugin::parseBzrRoot(DVcsJob* job)
{
QString filename = job->dvcsCommand().at(2);
QString rootDirectory = job->output();
QString localFilename = QFileInfo(QUrl::fromLocalFile(filename).toLocalFile()).absoluteFilePath();
QString result = localFilename.mid(localFilename.indexOf(rootDirectory) + rootDirectory.length());
job->setResults(QVariant::fromValue(result));
}
VcsJob* BazaarPlugin::resolve(const QList& localLocations, IBasicVersionControl::RecursionMode recursion)
{
return add(localLocations, recursion);
// How to provide "a conflict solving dialog to the user"?
// In any case this plugin is unable to make any conflict.
}
VcsJob* BazaarPlugin::revert(const QList& localLocations, IBasicVersionControl::RecursionMode recursion)
{
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localLocations[0]), this);
job->setType(VcsJob::JobType::Revert);
*job << "bzr" << "revert" << BazaarUtils::handleRecursion(localLocations, recursion);
return job;
}
VcsJob* BazaarPlugin::status(const QList& localLocations, IBasicVersionControl::RecursionMode recursion)
{
Q_UNUSED(recursion);
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localLocations[0]), this);
job->setType(VcsJob::Status);
*job << "bzr" << "status" << "--short" << "--no-pending" << "--no-classify" << localLocations;
connect(job, &DVcsJob::readyForParsing, this, &BazaarPlugin::parseBzrStatus);
return job;
}
void BazaarPlugin::parseBzrStatus(DVcsJob* job)
{
QVariantList result;
QSet filesWithStatus;
QDir workingCopy = job->directory();
foreach (const QString& line, job->output().split('\n')) {
auto status = BazaarUtils::parseVcsStatusInfoLine(line);
result.append(QVariant::fromValue(status));
filesWithStatus.insert(BazaarUtils::concatenatePath(workingCopy, status.url()));
}
QStringList command = job->dvcsCommand();
for (auto it = command.constBegin() + command.indexOf(QStringLiteral("--no-classify")) + 1, itEnd = command.constEnd(); it != itEnd; ++it) {
QString path = QFileInfo(*it).absoluteFilePath();
if (!filesWithStatus.contains(path)) {
filesWithStatus.insert(path);
KDevelop::VcsStatusInfo status;
status.setState(VcsStatusInfo::ItemUpToDate);
status.setUrl(QUrl::fromLocalFile(*it));
result.append(QVariant::fromValue(status));
}
}
job->setResults(result);
}
VcsJob* BazaarPlugin::update(const QList& localLocations, const VcsRevision& rev, IBasicVersionControl::RecursionMode recursion)
{
// bzr update is stronger than API (it's effectively merge)
// the best approximation is bzr pull
DVcsJob* job = new DVcsJob(BazaarUtils::workingCopy(localLocations[0]), this);
Q_UNUSED(recursion);
// recursion and file locations are ignored - we can update only whole
// working copy
job->setType(VcsJob::JobType::Update);
*job << "bzr" << "pull" << BazaarUtils::getRevisionSpec(rev);
return job;
}
VcsLocationWidget* BazaarPlugin::vcsLocation(QWidget* parent) const
{
return new KDevelop::StandardVcsLocationWidget(parent);
}
ContextMenuExtension BazaarPlugin::contextMenuExtension(Context* context)
{
m_vcsPluginHelper->setupFromContext(context);
QList const& ctxUrlList = m_vcsPluginHelper->contextUrlList();
bool isWorkingDirectory = false;
for (const QUrl & url : ctxUrlList) {
if (BazaarUtils::isValidDirectory(url)) {
isWorkingDirectory = true;
break;
}
}
if (!isWorkingDirectory) { // Not part of a repository
return ContextMenuExtension();
}
QMenu* menu = m_vcsPluginHelper->commonActions();
ContextMenuExtension menuExt;
menuExt.addAction(ContextMenuExtension::VcsGroup, menu->menuAction());
return menuExt;
}
diff --git a/plugins/bazaar/bazaarplugin.h b/plugins/bazaar/bazaarplugin.h
index e538f2f48d..c5fee4615e 100644
--- a/plugins/bazaar/bazaarplugin.h
+++ b/plugins/bazaar/bazaarplugin.h
@@ -1,77 +1,79 @@
/***************************************************************************
* Copyright 2013-2014 Maciej Poleski *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License or (at your option) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
#ifndef BAZAAR_BAZAARPLUGIN_H
#define BAZAAR_BAZAARPLUGIN_H
#include
#include
#include
#include
namespace KDevelop
{
class DVcsJob;
}
class BazaarPlugin : public KDevelop::IPlugin, public KDevelop::IDistributedVersionControl
{
Q_OBJECT
Q_INTERFACES(KDevelop::IBasicVersionControl KDevelop::IDistributedVersionControl)
public:
explicit BazaarPlugin(QObject* parent, const QVariantList& args = QVariantList());
~BazaarPlugin() override;
QString name() const override;
+ bool isValidRemoteRepositoryUrl(const QUrl& remoteLocation) override;
+
KDevelop::VcsJob* add(const QList& localLocations, RecursionMode recursion=Recursive) override;
KDevelop::VcsJob* annotate(const QUrl& localLocation, const KDevelop::VcsRevision& rev) override;
KDevelop::VcsJob* commit(const QString& message, const QList& localLocations, RecursionMode recursion=Recursive) override;
KDevelop::VcsJob* copy(const QUrl& localLocationSrc, const QUrl& localLocationDstn) override;
KDevelop::VcsImportMetadataWidget* createImportMetadataWidget(QWidget* parent) override;
KDevelop::VcsJob* createWorkingCopy(const KDevelop::VcsLocation& sourceRepository, const QUrl& destinationDirectory, RecursionMode recursion=Recursive) override;
KDevelop::VcsJob* diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, KDevelop::VcsDiff::Type, RecursionMode recursion=Recursive) override;
KDevelop::VcsJob* init(const QUrl& localRepositoryRoot) override;
bool isVersionControlled(const QUrl& localLocation) override;
KDevelop::VcsJob* log(const QUrl& localLocation, const KDevelop::VcsRevision& rev, long unsigned int limit) override;
KDevelop::VcsJob* log(const QUrl& localLocation, const KDevelop::VcsRevision& rev, const KDevelop::VcsRevision& limit) override;
KDevelop::VcsJob* move(const QUrl& localLocationSrc, const QUrl& localLocationDst) override;
KDevelop::VcsJob* pull(const KDevelop::VcsLocation& localOrRepoLocationSrc, const QUrl& localRepositoryLocation) override;
KDevelop::VcsJob* push(const QUrl& localRepositoryLocation, const KDevelop::VcsLocation& localOrRepoLocationDst) override;
KDevelop::VcsJob* remove(const QList& localLocations) override;
KDevelop::VcsJob* repositoryLocation(const QUrl& localLocation) override;
KDevelop::VcsJob* resolve(const QList& localLocations, RecursionMode recursio=Recursive) override;
KDevelop::VcsJob* revert(const QList& localLocations, RecursionMode recursion=Recursive) override;
KDevelop::VcsJob* status(const QList& localLocations, RecursionMode recursion=Recursive) override;
KDevelop::VcsJob* update(const QList& localLocations, const KDevelop::VcsRevision& rev, RecursionMode recursion=Recursive) override;
KDevelop::VcsLocationWidget* vcsLocation(QWidget* parent) const override;
KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override;
private slots:
void parseBzrStatus(KDevelop::DVcsJob* job);
void parseBzrLog(KDevelop::DVcsJob* job);
void parseBzrRoot(KDevelop::DVcsJob* job);
private:
KDevelop::VcsPluginHelper* m_vcsPluginHelper;
};
#endif // BAZAAR_BAZAARPLUGIN_H
diff --git a/plugins/cvs/cvsplugin.cpp b/plugins/cvs/cvsplugin.cpp
index 0f99da4ac0..b37980b204 100644
--- a/plugins/cvs/cvsplugin.cpp
+++ b/plugins/cvs/cvsplugin.cpp
@@ -1,486 +1,493 @@
/***************************************************************************
* Copyright 2007 Robert Gruber *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "cvsplugin.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "cvsmainview.h"
#include "cvsproxy.h"
#include "cvsjob.h"
#include "editorsview.h"
#include "commitdialog.h"
#include "cvsgenericoutputview.h"
#include "checkoutdialog.h"
#include "importdialog.h"
#include "importmetadatawidget.h"
#include "debug.h"
#include
#include
#include
Q_LOGGING_CATEGORY(PLUGIN_CVS, "kdevplatform.plugins.cvs")
K_PLUGIN_FACTORY(KDevCvsFactory, registerPlugin();)
// K_EXPORT_PLUGIN(KDevCvsFactory(KAboutData("kdevcvs", "kdevcvs", ki18n("CVS"), "0.1", ki18n("Support for CVS version control system"), KAboutData::License_GPL)))
class KDevCvsViewFactory: public KDevelop::IToolViewFactory
{
public:
explicit KDevCvsViewFactory(CvsPlugin *plugin): m_plugin(plugin) {}
QWidget* create(QWidget *parent = nullptr) override {
return new CvsMainView(m_plugin, parent);
}
Qt::DockWidgetArea defaultPosition() override {
return Qt::BottomDockWidgetArea;
}
QString id() const override {
return QStringLiteral("org.kdevelop.CVSView");
}
private:
CvsPlugin *m_plugin;
};
class CvsPluginPrivate
{
public:
explicit CvsPluginPrivate(CvsPlugin *pThis)
: m_factory(new KDevCvsViewFactory(pThis))
, m_proxy(new CvsProxy(pThis))
, m_common(new KDevelop::VcsPluginHelper(pThis, pThis)) {}
KDevCvsViewFactory* m_factory;
QPointer m_proxy;
QScopedPointer m_common;
};
CvsPlugin::CvsPlugin(QObject *parent, const QVariantList &)
: KDevelop::IPlugin(QStringLiteral("kdevcvs"), parent)
, d(new CvsPluginPrivate(this))
{
core()->uiController()->addToolView(i18n("CVS"), d->m_factory);
setXMLFile(QStringLiteral("kdevcvs.rc"));
setupActions();
}
CvsPlugin::~CvsPlugin()
{
}
void CvsPlugin::unload()
{
core()->uiController()->removeToolView( d->m_factory );
}
CvsProxy* CvsPlugin::proxy()
{
return d->m_proxy;
}
void CvsPlugin::setupActions()
{
QAction *action;
action = actionCollection()->addAction(QStringLiteral("cvs_import"));
action->setText(i18n("Import Directory..."));
connect(action, &QAction::triggered, this, &CvsPlugin::slotImport);
action = actionCollection()->addAction(QStringLiteral("cvs_checkout"));
action->setText(i18n("Checkout..."));
connect(action, &QAction::triggered, this, &CvsPlugin::slotCheckout);
action = actionCollection()->addAction(QStringLiteral("cvs_status"));
action->setText(i18n("Status..."));
connect(action, &QAction::triggered, this, &CvsPlugin::slotStatus);
}
const QUrl CvsPlugin::urlFocusedDocument() const
{
KParts::ReadOnlyPart *plugin =
dynamic_cast(core()->partController()->activePart());
if (plugin) {
if (plugin->url().isLocalFile()) {
return plugin->url();
}
}
return QUrl();
}
void CvsPlugin::slotImport()
{
QUrl url = urlFocusedDocument();
ImportDialog dlg(this, url);
dlg.exec();
}
void CvsPlugin::slotCheckout()
{
///@todo don't use proxy directly; use interface instead
CheckoutDialog dlg(this);
dlg.exec();
}
void CvsPlugin::slotStatus()
{
QUrl url = urlFocusedDocument();
QList urls;
urls << url;
KDevelop::VcsJob* j = status(urls, KDevelop::IBasicVersionControl::Recursive);
CvsJob* job = dynamic_cast(j);
if (job) {
CvsGenericOutputView* view = new CvsGenericOutputView(job);
emit addNewTabToMainView(view, i18n("Status"));
KDevelop::ICore::self()->runController()->registerJob(job);
}
}
KDevelop::ContextMenuExtension CvsPlugin::contextMenuExtension(KDevelop::Context* context)
{
d->m_common->setupFromContext(context);
QList const & ctxUrlList = d->m_common->contextUrlList();
bool hasVersionControlledEntries = false;
foreach(const QUrl &url, ctxUrlList) {
if (d->m_proxy->isValidDirectory(url)) {
hasVersionControlledEntries = true;
break;
}
}
qCDebug(PLUGIN_CVS) << "version controlled?" << hasVersionControlledEntries;
if (!hasVersionControlledEntries)
return IPlugin::contextMenuExtension(context);
QMenu* menu = d->m_common->commonActions();
menu->addSeparator();
QAction *action;
// Just add actions which are not covered by the cvscommon plugin
action = new QAction(i18n("Edit"), this);
connect(action, &QAction::triggered, this, &CvsPlugin::ctxEdit);
menu->addAction(action);
action = new QAction(i18n("Unedit"), this);
connect(action, &QAction::triggered, this, &CvsPlugin::ctxUnEdit);
menu->addAction(action);
action = new QAction(i18n("Show Editors"), this);
connect(action, &QAction::triggered, this, &CvsPlugin::ctxEditors);
menu->addAction(action);
KDevelop::ContextMenuExtension menuExt;
menuExt.addAction(KDevelop::ContextMenuExtension::VcsGroup, menu->menuAction());
return menuExt;
}
void CvsPlugin::ctxEdit()
{
QList const & urls = d->m_common->contextUrlList();
Q_ASSERT(!urls.empty());
KDevelop::VcsJob* j = edit(urls.front());
CvsJob* job = dynamic_cast(j);
if (job) {
connect(job, &CvsJob::result,
this, &CvsPlugin::jobFinished);
KDevelop::ICore::self()->runController()->registerJob(job);
}
}
void CvsPlugin::ctxUnEdit()
{
QList const & urls = d->m_common->contextUrlList();
Q_ASSERT(!urls.empty());
KDevelop::VcsJob* j = unedit(urls.front());
CvsJob* job = dynamic_cast(j);
if (job) {
connect(job, &CvsJob::result,
this, &CvsPlugin::jobFinished);
KDevelop::ICore::self()->runController()->registerJob(job);
}
}
void CvsPlugin::ctxEditors()
{
QList const & urls = d->m_common->contextUrlList();
Q_ASSERT(!urls.empty());
CvsJob* job = d->m_proxy->editors(findWorkingDir(urls.front()),
urls);
if (job) {
KDevelop::ICore::self()->runController()->registerJob(job);
EditorsView* view = new EditorsView(job);
emit addNewTabToMainView(view, i18n("Editors"));
}
}
QString CvsPlugin::findWorkingDir(const QUrl& location)
{
QFileInfo fileInfo(location.toLocalFile());
// find out correct working directory
if (fileInfo.isFile()) {
return fileInfo.absolutePath();
} else {
return fileInfo.absoluteFilePath();
}
}
// Begin: KDevelop::IBasicVersionControl
+bool CvsPlugin::isValidRemoteRepositoryUrl(const QUrl& remoteLocation)
+{
+ Q_UNUSED(remoteLocation);
+ // TODO
+ return false;
+}
+
bool CvsPlugin::isVersionControlled(const QUrl & localLocation)
{
return d->m_proxy->isVersionControlled(localLocation);
}
KDevelop::VcsJob * CvsPlugin::repositoryLocation(const QUrl & localLocation)
{
Q_UNUSED(localLocation);
return nullptr;
}
KDevelop::VcsJob * CvsPlugin::add(const QList & localLocations, KDevelop::IBasicVersionControl::RecursionMode recursion)
{
CvsJob* job = d->m_proxy->add(findWorkingDir(localLocations[0]),
localLocations,
(recursion == KDevelop::IBasicVersionControl::Recursive) ? true : false);
return job;
}
KDevelop::VcsJob * CvsPlugin::remove(const QList & localLocations)
{
CvsJob* job = d->m_proxy->remove(findWorkingDir(localLocations[0]),
localLocations);
return job;
}
KDevelop::VcsJob * CvsPlugin::localRevision(const QUrl & localLocation, KDevelop::VcsRevision::RevisionType)
{
Q_UNUSED(localLocation)
return nullptr;
}
KDevelop::VcsJob * CvsPlugin::status(const QList & localLocations, KDevelop::IBasicVersionControl::RecursionMode recursion)
{
CvsJob* job = d->m_proxy->status(findWorkingDir(localLocations[0]),
localLocations,
(recursion == KDevelop::IBasicVersionControl::Recursive) ? true : false);
return job;
}
KDevelop::VcsJob * CvsPlugin::unedit(const QUrl& localLocation)
{
CvsJob* job = d->m_proxy->unedit(findWorkingDir(localLocation),
QList() << localLocation);
return job;
}
KDevelop::VcsJob * CvsPlugin::edit(const QUrl& localLocation)
{
CvsJob* job = d->m_proxy->edit(findWorkingDir(localLocation),
QList() << localLocation);
return job;
}
KDevelop::VcsJob * CvsPlugin::copy(const QUrl & localLocationSrc, const QUrl & localLocationDstn)
{
bool ok = QFile::copy(localLocationSrc.toLocalFile(), localLocationDstn.path());
if (!ok) {
return nullptr;
}
QList listDstn;
listDstn << localLocationDstn;
CvsJob* job = d->m_proxy->add(findWorkingDir(localLocationDstn),
listDstn, true);
return job;
}
KDevelop::VcsJob * CvsPlugin::move(const QUrl &, const QUrl &)
{
return nullptr;
}
KDevelop::VcsJob * CvsPlugin::revert(const QList & localLocations, KDevelop::IBasicVersionControl::RecursionMode recursion)
{
KDevelop::VcsRevision rev;
CvsJob* job = d->m_proxy->update(findWorkingDir(localLocations[0]),
localLocations,
rev,
QStringLiteral("-C"),
(recursion == KDevelop::IBasicVersionControl::Recursive) ? true : false,
false, false);
return job;
}
KDevelop::VcsJob * CvsPlugin::update(const QList & localLocations, const KDevelop::VcsRevision & rev, KDevelop::IBasicVersionControl::RecursionMode recursion)
{
CvsJob* job = d->m_proxy->update(findWorkingDir(localLocations[0]),
localLocations,
rev,
QString(),
(recursion == KDevelop::IBasicVersionControl::Recursive) ? true : false,
false, false);
return job;
}
KDevelop::VcsJob * CvsPlugin::commit(const QString & message, const QList & localLocations, KDevelop::IBasicVersionControl::RecursionMode recursion)
{
Q_UNUSED(recursion);
QString msg = message;
if (msg.isEmpty()) {
CommitDialog dlg;
if (dlg.exec() == QDialog::Accepted) {
msg = dlg.message();
}
}
CvsJob* job = d->m_proxy->commit(findWorkingDir(localLocations[0]),
localLocations,
msg);
return job;
}
KDevelop::VcsJob * CvsPlugin::diff(const QUrl & fileOrDirectory, const KDevelop::VcsRevision & srcRevision, const KDevelop::VcsRevision & dstRevision, KDevelop::VcsDiff::Type, KDevelop::IBasicVersionControl::RecursionMode)
{
CvsJob* job = d->m_proxy->diff(fileOrDirectory, srcRevision, dstRevision, QStringLiteral("-uN")/*always unified*/);
return job;
}
KDevelop::VcsJob * CvsPlugin::log(const QUrl & localLocation, const KDevelop::VcsRevision & rev, unsigned long limit)
{
Q_UNUSED(limit)
CvsJob* job = d->m_proxy->log(localLocation, rev);
return job;
}
KDevelop::VcsJob * CvsPlugin::log(const QUrl & localLocation, const KDevelop::VcsRevision & rev, const KDevelop::VcsRevision & limit)
{
Q_UNUSED(limit)
return log(localLocation, rev, 0);
}
KDevelop::VcsJob * CvsPlugin::annotate(const QUrl & localLocation, const KDevelop::VcsRevision & rev)
{
CvsJob* job = d->m_proxy->annotate(localLocation, rev);
return job;
}
KDevelop::VcsJob * CvsPlugin::resolve(const QList & localLocations, KDevelop::IBasicVersionControl::RecursionMode recursion)
{
Q_UNUSED(localLocations);
Q_UNUSED(recursion);
return nullptr;
}
KDevelop::VcsJob * CvsPlugin::import(const QString& commitMessage, const QUrl& sourceDirectory, const KDevelop::VcsLocation& destinationRepository)
{
if (commitMessage.isEmpty()
|| !sourceDirectory.isLocalFile()
|| !destinationRepository.isValid()
|| destinationRepository.type() != KDevelop::VcsLocation::RepositoryLocation) {
return nullptr;
}
qCDebug(PLUGIN_CVS) << "CVS Import requested "
<< "src:" << sourceDirectory.toLocalFile()
<< "srv:" << destinationRepository.repositoryServer()
<< "module:" << destinationRepository.repositoryModule();
CvsJob* job = d->m_proxy->import(sourceDirectory,
destinationRepository.repositoryServer(),
destinationRepository.repositoryModule(),
destinationRepository.userData().toString(),
destinationRepository.repositoryTag(),
commitMessage);
return job;
}
KDevelop::VcsJob * CvsPlugin::createWorkingCopy(const KDevelop::VcsLocation & sourceRepository, const QUrl & destinationDirectory, KDevelop::IBasicVersionControl::RecursionMode recursion)
{
Q_UNUSED(recursion);
if (!destinationDirectory.isLocalFile()
|| !sourceRepository.isValid()
|| sourceRepository.type() != KDevelop::VcsLocation::RepositoryLocation) {
return nullptr;
}
qCDebug(PLUGIN_CVS) << "CVS Checkout requested "
<< "dest:" << destinationDirectory.toLocalFile()
<< "srv:" << sourceRepository.repositoryServer()
<< "module:" << sourceRepository.repositoryModule()
<< "branch:" << sourceRepository.repositoryBranch() << endl;
CvsJob* job = d->m_proxy->checkout(destinationDirectory,
sourceRepository.repositoryServer(),
sourceRepository.repositoryModule(),
QString(),
sourceRepository.repositoryBranch(),
true, true);
return job;
}
QString CvsPlugin::name() const
{
return i18n("CVS");
}
KDevelop::VcsImportMetadataWidget* CvsPlugin::createImportMetadataWidget(QWidget* parent)
{
return new ImportMetadataWidget(parent);
}
KDevelop::VcsLocationWidget* CvsPlugin::vcsLocation(QWidget* parent) const
{
return new KDevelop::StandardVcsLocationWidget(parent);
}
// End: KDevelop::IBasicVersionControl
#include "cvsplugin.moc"
diff --git a/plugins/cvs/cvsplugin.h b/plugins/cvs/cvsplugin.h
index fc97ac5287..fa5efe6f9f 100644
--- a/plugins/cvs/cvsplugin.h
+++ b/plugins/cvs/cvsplugin.h
@@ -1,139 +1,140 @@
/***************************************************************************
* Copyright 2007 Robert Gruber *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef KDEVPLATFORM_PLUGIN_CVSPLUGIN_H
#define KDEVPLATFORM_PLUGIN_CVSPLUGIN_H
#include
#include
#include
#include
#include
#include
class CvsProxy;
namespace KDevelop
{
class ContextMenuExtension;
}
class CvsPluginPrivate;
/**
* This is the main class of KDevelop's CVS plugin.
*
* It implements the IVersionControl interface.
*
* @author Robert Gruber
*/
class CvsPlugin : public KDevelop::IPlugin, public KDevelop::ICentralizedVersionControl
{
Q_OBJECT
Q_INTERFACES(KDevelop::IBasicVersionControl KDevelop::ICentralizedVersionControl)
friend class CvsProxy;
public:
explicit CvsPlugin(QObject *parent, const QVariantList & args = QVariantList());
~CvsPlugin() override;
void unload() override;
QString name() const override;
KDevelop::VcsImportMetadataWidget* createImportMetadataWidget(QWidget* parent) override;
// From KDevelop::IPlugin
KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context*) override;
// Begin: KDevelop::IBasicVersionControl
+ bool isValidRemoteRepositoryUrl(const QUrl& remoteLocation) override;
bool isVersionControlled(const QUrl& localLocation) override;
KDevelop::VcsJob* repositoryLocation(const QUrl& localLocation) override;
KDevelop::VcsJob* add(const QList& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion) override;
KDevelop::VcsJob* remove(const QList& localLocations) override;
KDevelop::VcsJob* copy(const QUrl& localLocationSrc,
const QUrl& localLocationDstn) override;
KDevelop::VcsJob* move(const QUrl& localLocationSrc,
const QUrl& localLocationDst) override;
KDevelop::VcsJob* status(const QList& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion) override;
KDevelop::VcsJob* revert(const QList& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion) override;
KDevelop::VcsJob* update(const QList& localLocations,
const KDevelop::VcsRevision& rev,
KDevelop::IBasicVersionControl::RecursionMode recursion) override;
KDevelop::VcsJob* commit(const QString& message,
const QList& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion) override;
KDevelop::VcsJob* diff(const QUrl& fileOrDirectory,
const KDevelop::VcsRevision& srcRevision,
const KDevelop::VcsRevision& dstRevision,
KDevelop::VcsDiff::Type,
KDevelop::IBasicVersionControl::RecursionMode = KDevelop::IBasicVersionControl::Recursive) override;
KDevelop::VcsJob* log(const QUrl& localLocation,
const KDevelop::VcsRevision& rev,
unsigned long limit) override;
KDevelop::VcsJob* log(const QUrl& localLocation,
const KDevelop::VcsRevision& rev,
const KDevelop::VcsRevision& limit) override;
KDevelop::VcsJob* annotate(const QUrl& localLocation,
const KDevelop::VcsRevision& rev) override;
KDevelop::VcsJob* resolve(const QList& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion) override;
KDevelop::VcsJob* createWorkingCopy(const KDevelop::VcsLocation & sourceRepository, const QUrl & destinationDirectory, KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive) override;
// End: KDevelop::IBasicVersionControl
// Begin: KDevelop::ICentralizedVersionControl
KDevelop::VcsJob* edit(const QUrl& localLocation) override;
KDevelop::VcsJob* unedit(const QUrl& localLocation) override;
KDevelop::VcsJob* localRevision(const QUrl& localLocation,
KDevelop::VcsRevision::RevisionType) override;
KDevelop::VcsJob* import(const QString& commitMessage, const QUrl& sourceDirectory, const KDevelop::VcsLocation& destinationRepository) override;
// End: KDevelop::ICentralizedVersionControl
CvsProxy* proxy();
const QUrl urlFocusedDocument() const;
KDevelop::VcsLocationWidget* vcsLocation(QWidget* parent) const override;
public slots:
// slots for context menu
void ctxEdit();
void ctxUnEdit();
void ctxEditors();
// slots for menu
void slotImport();
void slotCheckout();
void slotStatus();
signals:
/**
* Some actions like commit, add, remove... will connect the job's
* result() signal to this signal. Anybody, like for instance the
* CvsMainView class, that is interested in getting notified about
* jobs that finished can connect to this signal.
* @see class CvsMainView
*/
void jobFinished(KJob* job);
/**
* Gets emmited when a job like log, editors... was created.
* CvsPlugin will connect the newly created view to the result() signal
* of a job. So the new view will show the output of that job as
* soon as it has finished.
*/
void addNewTabToMainView(QWidget* tab, QString label);
private:
void setupActions();
QScopedPointer d;
QString findWorkingDir(const QUrl& location);
};
#endif
diff --git a/plugins/git/gitplugin.cpp b/plugins/git/gitplugin.cpp
index c5c7f8f5a5..b56d53df38 100644
--- a/plugins/git/gitplugin.cpp
+++ b/plugins/git/gitplugin.cpp
@@ -1,1510 +1,1536 @@
/***************************************************************************
* Copyright 2008 Evgeniy Ivanov *
* Copyright 2009 Hugo Parente Lima *
* Copyright 2010 Aleix Pol Gonzalez *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License or (at your option) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
#include "gitplugin.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "gitclonejob.h"
#include
#include
#include "stashmanagerdialog.h"
#include
#include
#include
#include
#include
#include
#include "gitjob.h"
#include "gitmessagehighlighter.h"
#include "gitplugincheckinrepositoryjob.h"
#include "gitnameemaildialog.h"
#include "debug.h"
Q_LOGGING_CATEGORY(PLUGIN_GIT, "kdevplatform.plugins.git")
using namespace KDevelop;
QVariant runSynchronously(KDevelop::VcsJob* job)
{
QVariant ret;
if(job->exec() && job->status()==KDevelop::VcsJob::JobSucceeded) {
ret = job->fetchResults();
}
delete job;
return ret;
}
namespace
{
QDir dotGitDirectory(const QUrl& dirPath)
{
const QFileInfo finfo(dirPath.toLocalFile());
QDir dir = finfo.isDir() ? QDir(finfo.filePath()): finfo.absoluteDir();
static const QString gitDir = QStringLiteral(".git");
while (!dir.exists(gitDir) && dir.cdUp()) {} // cdUp, until there is a sub-directory called .git
if (dir.isRoot()) {
qCWarning(PLUGIN_GIT) << "couldn't find the git root for" << dirPath;
}
return dir;
}
/**
* Whenever a directory is provided, change it for all the files in it but not inner directories,
* that way we make sure we won't get into recursion,
*/
static QList preventRecursion(const QList& urls)
{
QList ret;
foreach(const QUrl& url, urls) {
QDir d(url.toLocalFile());
if(d.exists()) {
QStringList entries = d.entryList(QDir::Files | QDir::NoDotAndDotDot);
foreach(const QString& entry, entries) {
QUrl entryUrl = QUrl::fromLocalFile(d.absoluteFilePath(entry));
ret += entryUrl;
}
} else
ret += url;
}
return ret;
}
QString toRevisionName(const KDevelop::VcsRevision& rev, QString currentRevision=QString())
{
switch(rev.revisionType()) {
case VcsRevision::Special:
switch(rev.revisionValue().value()) {
case VcsRevision::Head:
return QStringLiteral("^HEAD");
case VcsRevision::Base:
return QString();
case VcsRevision::Working:
return QString();
case VcsRevision::Previous:
Q_ASSERT(!currentRevision.isEmpty());
return currentRevision + "^1";
case VcsRevision::Start:
return QString();
case VcsRevision::UserSpecialType: //Not used
Q_ASSERT(false && "i don't know how to do that");
}
break;
case VcsRevision::GlobalNumber:
return rev.revisionValue().toString();
case VcsRevision::Date:
case VcsRevision::FileNumber:
case VcsRevision::Invalid:
case VcsRevision::UserSpecialType:
Q_ASSERT(false);
}
return QString();
}
QString revisionInterval(const KDevelop::VcsRevision& rev, const KDevelop::VcsRevision& limit)
{
QString ret;
if(rev.revisionType()==VcsRevision::Special &&
rev.revisionValue().value()==VcsRevision::Start) //if we want it to the beginning just put the revisionInterval
ret = toRevisionName(limit, QString());
else {
QString dst = toRevisionName(limit);
if(dst.isEmpty())
ret = dst;
else {
QString src = toRevisionName(rev, dst);
if(src.isEmpty())
ret = src;
else
ret = src+".."+dst;
}
}
return ret;
}
QDir urlDir(const QUrl& url)
{
QFileInfo f(url.toLocalFile());
if(f.isDir())
return QDir(url.toLocalFile());
else
return f.absoluteDir();
}
QDir urlDir(const QList& urls) { return urlDir(urls.first()); } //TODO: could be improved
}
GitPlugin::GitPlugin( QObject *parent, const QVariantList & )
: DistributedVersionControlPlugin(parent, QStringLiteral("kdevgit")), m_oldVersion(false), m_usePrefix(true)
{
if (QStandardPaths::findExecutable(QStringLiteral("git")).isEmpty()) {
setErrorDescription(i18n("Unable to find git executable. Is it installed on the system?"));
return;
}
setObjectName(QStringLiteral("Git"));
DVcsJob* versionJob = new DVcsJob(QDir::tempPath(), this, KDevelop::OutputJob::Silent);
*versionJob << "git" << "--version";
connect(versionJob, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitVersionOutput);
ICore::self()->runController()->registerJob(versionJob);
m_watcher = new KDirWatch(this);
connect(m_watcher, &KDirWatch::dirty, this, &GitPlugin::fileChanged);
connect(m_watcher, &KDirWatch::created, this, &GitPlugin::fileChanged);
}
GitPlugin::~GitPlugin()
{}
bool emptyOutput(DVcsJob* job)
{
QScopedPointer _job(job);
if(job->exec() && job->status()==VcsJob::JobSucceeded)
return job->rawOutput().trimmed().isEmpty();
return false;
}
bool GitPlugin::hasStashes(const QDir& repository)
{
return !emptyOutput(gitStash(repository, QStringList(QStringLiteral("list")), KDevelop::OutputJob::Silent));
}
bool GitPlugin::hasModifications(const QDir& d)
{
return !emptyOutput(lsFiles(d, QStringList(QStringLiteral("-m")), OutputJob::Silent));
}
bool GitPlugin::hasModifications(const QDir& repo, const QUrl& file)
{
return !emptyOutput(lsFiles(repo, QStringList() << QStringLiteral("-m") << file.path(), OutputJob::Silent));
}
void GitPlugin::additionalMenuEntries(QMenu* menu, const QList& urls)
{
m_urls = urls;
QDir dir=urlDir(urls);
bool hasSt = hasStashes(dir);
menu->addSeparator()->setText(i18n("Git Stashes"));
menu->addAction(i18n("Stash Manager"), this, SLOT(ctxStashManager()))->setEnabled(hasSt);
menu->addAction(i18n("Push Stash"), this, SLOT(ctxPushStash()));
menu->addAction(i18n("Pop Stash"), this, SLOT(ctxPopStash()))->setEnabled(hasSt);
}
void GitPlugin::ctxPushStash()
{
VcsJob* job = gitStash(urlDir(m_urls), QStringList(), KDevelop::OutputJob::Verbose);
ICore::self()->runController()->registerJob(job);
}
void GitPlugin::ctxPopStash()
{
VcsJob* job = gitStash(urlDir(m_urls), QStringList(QStringLiteral("pop")), KDevelop::OutputJob::Verbose);
ICore::self()->runController()->registerJob(job);
}
void GitPlugin::ctxStashManager()
{
QPointer d = new StashManagerDialog(urlDir(m_urls), this, nullptr);
d->exec();
delete d;
}
DVcsJob* GitPlugin::errorsFound(const QString& error, KDevelop::OutputJob::OutputJobVerbosity verbosity=OutputJob::Verbose)
{
DVcsJob* j = new DVcsJob(QDir::temp(), this, verbosity);
*j << "echo" << i18n("error: %1", error) << "-n";
return j;
}
QString GitPlugin::name() const
{
return QStringLiteral("Git");
}
QUrl GitPlugin::repositoryRoot(const QUrl& path)
{
return QUrl::fromLocalFile(dotGitDirectory(path).absolutePath());
}
bool GitPlugin::isValidDirectory(const QUrl & dirPath)
{
QDir dir=dotGitDirectory(dirPath);
return dir.exists(QStringLiteral(".git/HEAD"));
}
+bool GitPlugin::isValidRemoteRepositoryUrl(const QUrl& remoteLocation)
+{
+ if (remoteLocation.isLocalFile()) {
+ QFileInfo fileInfo(remoteLocation.toLocalFile());
+ if (fileInfo.isDir()) {
+ QDir dir(fileInfo.filePath());
+ if (dir.exists(QStringLiteral(".git/HEAD"))) {
+ return true;
+ }
+ // TODO: check also for bare repo
+ }
+ } else {
+ const QString scheme = remoteLocation.scheme();
+ if (scheme == QLatin1String("git")) {
+ return true;
+ }
+ // heuristic check, anything better we can do here without talking to server?
+ if ((scheme == QLatin1String("http") ||
+ scheme == QLatin1String("https")) &&
+ remoteLocation.path().endsWith(QLatin1String(".git"))) {
+ return true;
+ }
+ }
+ return false;
+}
+
bool GitPlugin::isVersionControlled(const QUrl &path)
{
QFileInfo fsObject(path.toLocalFile());
if (!fsObject.exists()) {
return false;
}
if (fsObject.isDir()) {
return isValidDirectory(path);
}
QString filename = fsObject.fileName();
QStringList otherFiles = getLsFiles(fsObject.dir(), QStringList(QStringLiteral("--")) << filename, KDevelop::OutputJob::Silent);
return !otherFiles.empty();
}
VcsJob* GitPlugin::init(const QUrl &directory)
{
DVcsJob* job = new DVcsJob(urlDir(directory), this);
job->setType(VcsJob::Import);
*job << "git" << "init";
return job;
}
VcsJob* GitPlugin::createWorkingCopy(const KDevelop::VcsLocation & source, const QUrl& dest, KDevelop::IBasicVersionControl::RecursionMode)
{
DVcsJob* job = new GitCloneJob(urlDir(dest), this);
job->setType(VcsJob::Import);
*job << "git" << "clone" << "--progress" << "--" << source.localUrl().url() << dest;
return job;
}
VcsJob* GitPlugin::add(const QList& localLocations, KDevelop::IBasicVersionControl::RecursionMode recursion)
{
if (localLocations.empty())
return errorsFound(i18n("Did not specify the list of files"), OutputJob::Verbose);
DVcsJob* job = new GitJob(dotGitDirectory(localLocations.front()), this);
job->setType(VcsJob::Add);
*job << "git" << "add" << "--" << (recursion == IBasicVersionControl::Recursive ? localLocations : preventRecursion(localLocations));
return job;
}
KDevelop::VcsJob* GitPlugin::status(const QList& localLocations, KDevelop::IBasicVersionControl::RecursionMode recursion)
{
if (localLocations.empty())
return errorsFound(i18n("Did not specify the list of files"), OutputJob::Verbose);
DVcsJob* job = new GitJob(urlDir(localLocations), this, OutputJob::Silent);
job->setType(VcsJob::Status);
if(m_oldVersion) {
*job << "git" << "ls-files" << "-t" << "-m" << "-c" << "-o" << "-d" << "-k" << "--directory";
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitStatusOutput_old);
} else {
*job << "git" << "status" << "--porcelain";
job->setIgnoreError(true);
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitStatusOutput);
}
*job << "--" << (recursion == IBasicVersionControl::Recursive ? localLocations : preventRecursion(localLocations));
return job;
}
VcsJob* GitPlugin::diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision,
VcsDiff::Type /*type*/, IBasicVersionControl::RecursionMode recursion)
{
//TODO: control different types
DVcsJob* job = new GitJob(dotGitDirectory(fileOrDirectory), this, KDevelop::OutputJob::Silent);
job->setType(VcsJob::Diff);
*job << "git" << "diff" << "--no-color" << "--no-ext-diff";
if (!usePrefix()) {
// KDE's ReviewBoard now requires p1 patchfiles, so `git diff --no-prefix` to generate p0 patches
// has become optional.
*job << "--no-prefix";
}
if (dstRevision.revisionType() == VcsRevision::Special &&
dstRevision.specialType() == VcsRevision::Working) {
if (srcRevision.revisionType() == VcsRevision::Special &&
srcRevision.specialType() == VcsRevision::Base) {
*job << "HEAD";
} else {
*job << "--cached" << srcRevision.revisionValue().toString();
}
} else {
QString revstr = revisionInterval(srcRevision, dstRevision);
if(!revstr.isEmpty())
*job << revstr;
}
*job << "--";
if (recursion == IBasicVersionControl::Recursive) {
*job << fileOrDirectory;
} else {
*job << preventRecursion(QList() << fileOrDirectory);
}
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitDiffOutput);
return job;
}
VcsJob* GitPlugin::revert(const QList& localLocations, IBasicVersionControl::RecursionMode recursion)
{
if(localLocations.isEmpty() )
return errorsFound(i18n("Could not revert changes"), OutputJob::Verbose);
QDir repo = urlDir(repositoryRoot(localLocations.first()));
QString modified;
for (const auto& file: localLocations) {
if (hasModifications(repo, file)) {
modified.append(file.toDisplayString(QUrl::PreferLocalFile) + "
");
}
}
if (!modified.isEmpty()) {
auto res = KMessageBox::questionYesNo(nullptr, i18n("The following files have uncommited changes, "
"which will be lost. Continue?") + "
" + modified);
if (res != KMessageBox::Yes) {
return errorsFound(QString(), OutputJob::Silent);
}
}
DVcsJob* job = new GitJob(dotGitDirectory(localLocations.front()), this);
job->setType(VcsJob::Revert);
*job << "git" << "checkout" << "--";
*job << (recursion == IBasicVersionControl::Recursive ? localLocations : preventRecursion(localLocations));
return job;
}
//TODO: git doesn't like empty messages, but "KDevelop didn't provide any message, it may be a bug" looks ugly...
//If no files specified then commit already added files
VcsJob* GitPlugin::commit(const QString& message,
const QList& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion)
{
if (localLocations.empty() || message.isEmpty())
return errorsFound(i18n("No files or message specified"));
const QDir dir = dotGitDirectory(localLocations.front());
if (!ensureValidGitIdentity(dir)) {
return errorsFound(i18n("Email or name for Git not specified"));
}
DVcsJob* job = new DVcsJob(dir, this);
job->setType(VcsJob::Commit);
QList files = (recursion == IBasicVersionControl::Recursive ? localLocations : preventRecursion(localLocations));
addNotVersionedFiles(dir, files);
*job << "git" << "commit" << "-m" << message;
*job << "--" << files;
return job;
}
bool GitPlugin::ensureValidGitIdentity(const QDir& dir)
{
const QUrl url = QUrl::fromLocalFile(dir.absolutePath());
const QString name = readConfigOption(url, QStringLiteral("user.name"));
const QString email = readConfigOption(url, QStringLiteral("user.email"));
if (!email.isEmpty() && !name.isEmpty()) {
return true; // already okay
}
GitNameEmailDialog dialog;
dialog.setName(name);
dialog.setEmail(email);
if (!dialog.exec()) {
return false;
}
runSynchronously(setConfigOption(url, QStringLiteral("user.name"), dialog.name(), dialog.isGlobal()));
runSynchronously(setConfigOption(url, QStringLiteral("user.email"), dialog.email(), dialog.isGlobal()));
return true;
}
void GitPlugin::addNotVersionedFiles(const QDir& dir, const QList& files)
{
QStringList otherStr = getLsFiles(dir, QStringList() << QStringLiteral("--others"), KDevelop::OutputJob::Silent);
QList toadd, otherFiles;
foreach(const QString& file, otherStr) {
QUrl v = QUrl::fromLocalFile(dir.absoluteFilePath(file));
otherFiles += v;
}
//We add the files that are not versioned
foreach(const QUrl& file, files) {
if(otherFiles.contains(file) && QFileInfo(file.toLocalFile()).isFile())
toadd += file;
}
if(!toadd.isEmpty()) {
VcsJob* job = add(toadd);
job->exec();
}
}
bool isEmptyDirStructure(const QDir &dir)
{
foreach (const QFileInfo &i, dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot)) {
if (i.isDir()) {
if (!isEmptyDirStructure(QDir(i.filePath()))) return false;
} else if (i.isFile()) {
return false;
}
}
return true;
}
VcsJob* GitPlugin::remove(const QList& files)
{
if (files.isEmpty())
return errorsFound(i18n("No files to remove"));
QDir dotGitDir = dotGitDirectory(files.front());
QList files_(files);
QMutableListIterator i(files_);
while (i.hasNext()) {
QUrl file = i.next();
QFileInfo fileInfo(file.toLocalFile());
QStringList otherStr = getLsFiles(dotGitDir, QStringList() << QStringLiteral("--others") << QStringLiteral("--") << file.toLocalFile(), KDevelop::OutputJob::Silent);
if(!otherStr.isEmpty()) {
//remove files not under version control
QList otherFiles;
foreach(const QString &f, otherStr) {
otherFiles << QUrl::fromLocalFile(dotGitDir.path()+'/'+f);
}
if (fileInfo.isFile()) {
//if it's an unversioned file we are done, don't use git rm on it
i.remove();
}
auto trashJob = KIO::trash(otherFiles);
trashJob->exec();
qCDebug(PLUGIN_GIT) << "other files" << otherFiles;
}
if (fileInfo.isDir()) {
if (isEmptyDirStructure(QDir(file.toLocalFile()))) {
//remove empty folders, git doesn't do that
auto trashJob = KIO::trash(file);
trashJob->exec();
qCDebug(PLUGIN_GIT) << "empty folder, removing" << file;
//we already deleted it, don't use git rm on it
i.remove();
}
}
}
if (files_.isEmpty()) return nullptr;
DVcsJob* job = new GitJob(dotGitDir, this);
job->setType(VcsJob::Remove);
// git refuses to delete files with local modifications
// use --force to overcome this
*job << "git" << "rm" << "-r" << "--force";
*job << "--" << files_;
return job;
}
VcsJob* GitPlugin::log(const QUrl& localLocation,
const KDevelop::VcsRevision& src, const KDevelop::VcsRevision& dst)
{
DVcsJob* job = new GitJob(dotGitDirectory(localLocation), this, KDevelop::OutputJob::Silent);
job->setType(VcsJob::Log);
*job << "git" << "log" << "--date=raw" << "--name-status" << "-M80%" << "--follow";
QString rev = revisionInterval(dst, src);
if(!rev.isEmpty())
*job << rev;
*job << "--" << localLocation;
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitLogOutput);
return job;
}
VcsJob* GitPlugin::log(const QUrl& localLocation, const KDevelop::VcsRevision& rev, unsigned long int limit)
{
DVcsJob* job = new GitJob(dotGitDirectory(localLocation), this, KDevelop::OutputJob::Silent);
job->setType(VcsJob::Log);
*job << "git" << "log" << "--date=raw" << "--name-status" << "-M80%" << "--follow";
QString revStr = toRevisionName(rev, QString());
if(!revStr.isEmpty())
*job << revStr;
if(limit>0)
*job << QStringLiteral("-%1").arg(limit);
*job << "--" << localLocation;
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitLogOutput);
return job;
}
KDevelop::VcsJob* GitPlugin::annotate(const QUrl &localLocation, const KDevelop::VcsRevision&)
{
DVcsJob* job = new GitJob(dotGitDirectory(localLocation), this, KDevelop::OutputJob::Silent);
job->setType(VcsJob::Annotate);
*job << "git" << "blame" << "--porcelain" << "-w";
*job << "--" << localLocation;
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitBlameOutput);
return job;
}
void GitPlugin::parseGitBlameOutput(DVcsJob *job)
{
QVariantList results;
VcsAnnotationLine* annotation = nullptr;
const auto output = job->output();
const auto lines = output.splitRef('\n');
bool skipNext=false;
QMap definedRevisions;
for(QVector::const_iterator it=lines.constBegin(), itEnd=lines.constEnd();
it!=itEnd; ++it)
{
if(skipNext) {
skipNext=false;
results += qVariantFromValue(*annotation);
continue;
}
if(it->isEmpty())
continue;
QStringRef name = it->left(it->indexOf(' '));
QStringRef value = it->right(it->size()-name.size()-1);
if(name==QLatin1String("author"))
annotation->setAuthor(value.toString());
else if(name==QLatin1String("author-mail")) {} //TODO: do smth with the e-mail?
else if(name==QLatin1String("author-tz")) {} //TODO: does it really matter?
else if(name==QLatin1String("author-time"))
annotation->setDate(QDateTime::fromTime_t(value.toUInt()));
else if(name==QLatin1String("summary"))
annotation->setCommitMessage(value.toString());
else if(name.startsWith(QStringLiteral("committer"))) {} //We will just store the authors
else if(name==QLatin1String("previous")) {} //We don't need that either
else if(name==QLatin1String("filename")) { skipNext=true; }
else if(name==QLatin1String("boundary")) {
definedRevisions.insert(QStringLiteral("boundary"), VcsAnnotationLine());
}
else
{
const auto values = value.split(' ');
VcsRevision rev;
rev.setRevisionValue(name.left(8).toString(), KDevelop::VcsRevision::GlobalNumber);
skipNext = definedRevisions.contains(name.toString());
if(!skipNext)
definedRevisions.insert(name.toString(), VcsAnnotationLine());
annotation = &definedRevisions[name.toString()];
annotation->setLineNumber(values[1].toInt() - 1);
annotation->setRevision(rev);
}
}
job->setResults(results);
}
DVcsJob* GitPlugin::lsFiles(const QDir &repository, const QStringList &args,
OutputJob::OutputJobVerbosity verbosity)
{
DVcsJob* job = new DVcsJob(repository, this, verbosity);
*job << "git" << "ls-files" << args;
return job;
}
DVcsJob* GitPlugin::gitStash(const QDir& repository, const QStringList& args, OutputJob::OutputJobVerbosity verbosity)
{
DVcsJob* job = new DVcsJob(repository, this, verbosity);
*job << "git" << "stash" << args;
return job;
}
VcsJob* GitPlugin::tag(const QUrl& repository, const QString& commitMessage, const VcsRevision& rev, const QString& tagName)
{
DVcsJob* job = new DVcsJob(urlDir(repository), this);
*job << "git" << "tag" << "-m" << commitMessage << tagName;
if(rev.revisionValue().isValid())
*job << rev.revisionValue().toString();
return job;
}
VcsJob* GitPlugin::switchBranch(const QUrl &repository, const QString &branch)
{
QDir d=urlDir(repository);
if(hasModifications(d) && KMessageBox::questionYesNo(nullptr, i18n("There are pending changes, do you want to stash them first?"))==KMessageBox::Yes) {
QScopedPointer stash(gitStash(d, QStringList(), KDevelop::OutputJob::Verbose));
stash->exec();
}
DVcsJob* job = new DVcsJob(d, this);
*job << "git" << "checkout" << branch;
return job;
}
VcsJob* GitPlugin::branch(const QUrl& repository, const KDevelop::VcsRevision& rev, const QString& branchName)
{
Q_ASSERT(!branchName.isEmpty());
DVcsJob* job = new DVcsJob(urlDir(repository), this);
*job << "git" << "branch" << "--" << branchName;
if(!rev.prettyValue().isEmpty())
*job << rev.revisionValue().toString();
return job;
}
VcsJob* GitPlugin::deleteBranch(const QUrl& repository, const QString& branchName)
{
DVcsJob* job = new DVcsJob(urlDir(repository), this, OutputJob::Silent);
*job << "git" << "branch" << "-D" << branchName;
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitCurrentBranch);
return job;
}
VcsJob* GitPlugin::renameBranch(const QUrl& repository, const QString& oldBranchName, const QString& newBranchName)
{
DVcsJob* job = new DVcsJob(urlDir(repository), this, OutputJob::Silent);
*job << "git" << "branch" << "-m" << newBranchName << oldBranchName;
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitCurrentBranch);
return job;
}
VcsJob* GitPlugin::mergeBranch(const QUrl& repository, const QString& branchName)
{
Q_ASSERT(!branchName.isEmpty());
DVcsJob* job = new DVcsJob(urlDir(repository), this);
*job << "git" << "merge" << branchName;
return job;
}
VcsJob* GitPlugin::currentBranch(const QUrl& repository)
{
DVcsJob* job = new DVcsJob(urlDir(repository), this, OutputJob::Silent);
job->setIgnoreError(true);
*job << "git" << "symbolic-ref" << "-q" << "--short" << "HEAD";
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitCurrentBranch);
return job;
}
void GitPlugin::parseGitCurrentBranch(DVcsJob* job)
{
QString out = job->output().trimmed();
job->setResults(out);
}
VcsJob* GitPlugin::branches(const QUrl &repository)
{
DVcsJob* job=new DVcsJob(urlDir(repository));
*job << "git" << "branch" << "-a";
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitBranchOutput);
return job;
}
void GitPlugin::parseGitBranchOutput(DVcsJob* job)
{
const auto output = job->output();
const auto branchListDirty = output.splitRef('\n', QString::SkipEmptyParts);
QStringList branchList;
foreach(const auto & branch, branchListDirty)
{
// Skip pointers to another branches (one example of this is "origin/HEAD -> origin/master");
// "git rev-list" chokes on these entries and we do not need duplicate branches altogether.
if (branch.contains(QStringLiteral("->")))
continue;
// Skip entries such as '(no branch)'
if (branch.contains(QStringLiteral("(no branch)")))
continue;
QStringRef name = branch;
if (name.startsWith('*'))
name = branch.right(branch.size()-2);
branchList << name.trimmed().toString();
}
job->setResults(branchList);
}
/* Few words about how this hardcore works:
1. get all commits (with --paretns)
2. select master (root) branch and get all unicial commits for branches (git-rev-list br2 ^master ^br3)
3. parse allCommits. While parsing set mask (columns state for every row) for BRANCH, INITIAL, CROSS,
MERGE and INITIAL are also set in DVCScommit::setParents (depending on parents count)
another setType(INITIAL) is used for "bottom/root/first" commits of branches
4. find and set merges, HEADS. It's an ittaration through all commits.
- first we check if parent is from the same branch, if no then we go through all commits searching parent's index
and set CROSS/HCROSS for rows (in 3 rows are set EMPTY after commit with parent from another tree met)
- then we check branchesShas[i][0] to mark heads
4 can be a seporate function. TODO: All this porn require refactoring (rewriting is better)!
It's a very dirty implementation.
FIXME:
1. HEAD which is head has extra line to connect it with further commit
2. If you menrge branch2 to master, only new commits of branch2 will be visible (it's fine, but there will be
extra merge rectangle in master. If there are no extra commits in branch2, but there are another branches, then the place for branch2 will be empty (instead of be used for branch3).
3. Commits that have additional commit-data (not only history merging, but changes to fix conflicts) are shown incorrectly
*/
QList GitPlugin::getAllCommits(const QString &repo)
{
initBranchHash(repo);
QStringList args;
args << QStringLiteral("--all") << QStringLiteral("--pretty") << QStringLiteral("--parents");
QScopedPointer job(gitRevList(repo, args));
bool ret = job->exec();
Q_ASSERT(ret && job->status()==VcsJob::JobSucceeded && "TODO: provide a fall back in case of failing");
Q_UNUSED(ret);
QStringList commits = job->output().split('\n', QString::SkipEmptyParts);
static QRegExp rx_com("commit \\w{40,40}");
QListcommitList;
DVcsEvent item;
//used to keep where we have empty/cross/branch entry
//true if it's an active branch (then cross or branch) and false if not
QVector additionalFlags(branchesShas.count());
additionalFlags.fill(false);
//parse output
for(int i = 0; i < commits.count(); ++i)
{
if (commits[i].contains(rx_com))
{
qCDebug(PLUGIN_GIT) << "commit found in " << commits[i];
item.setCommit(commits[i].section(' ', 1, 1).trimmed());
// qCDebug(PLUGIN_GIT) << "commit is: " << commits[i].section(' ', 1);
QStringList parents;
QString parent = commits[i].section(' ', 2);
int section = 2;
while (!parent.isEmpty())
{
/* qCDebug(PLUGIN_GIT) << "Parent is: " << parent;*/
parents.append(parent.trimmed());
section++;
parent = commits[i].section(' ', section);
}
item.setParents(parents);
//Avoid Merge string
while (!commits[i].contains(QStringLiteral("Author: ")))
++i;
item.setAuthor(commits[i].section(QStringLiteral("Author: "), 1).trimmed());
// qCDebug(PLUGIN_GIT) << "author is: " << commits[i].section("Author: ", 1);
item.setDate(commits[++i].section(QStringLiteral("Date: "), 1).trimmed());
// qCDebug(PLUGIN_GIT) << "date is: " << commits[i].section("Date: ", 1);
QString log;
i++; //next line!
while (i < commits.count() && !commits[i].contains(rx_com))
log += commits[i++];
--i; //while took commit line
item.setLog(log.trimmed());
// qCDebug(PLUGIN_GIT) << "log is: " << log;
//mask is used in CommitViewDelegate to understand what we should draw for each branch
QList mask;
//set mask (properties for each graph column in row)
for(int i = 0; i < branchesShas.count(); ++i)
{
qCDebug(PLUGIN_GIT)<<"commit: " << item.getCommit();
if (branchesShas[i].contains(item.getCommit()))
{
mask.append(item.getType()); //we set type in setParents
//check if parent from the same branch, if not then we have found a root of the branch
//and will use empty column for all futher (from top to bottom) revisions
//FIXME: we should set CROSS between parent and child (and do it when find merge point)
additionalFlags[i] = false;
foreach(const QString &sha, item.getParents())
{
if (branchesShas[i].contains(sha))
additionalFlags[i] = true;
}
if (additionalFlags[i] == false)
item.setType(DVcsEvent::INITIAL); //hasn't parents from the same branch, used in drawing
}
else
{
if (additionalFlags[i] == false)
mask.append(DVcsEvent::EMPTY);
else
mask.append(DVcsEvent::CROSS);
}
qCDebug(PLUGIN_GIT) << "mask " << i << "is " << mask[i];
}
item.setProperties(mask);
commitList.append(item);
}
}
//find and set merges, HEADS, require refactoring!
for(QList::iterator iter = commitList.begin();
iter != commitList.end(); ++iter)
{
QStringList parents = iter->getParents();
//we need only only child branches
if (parents.count() != 1)
break;
QString parent = parents[0];
QString commit = iter->getCommit();
bool parent_checked = false;
int heads_checked = 0;
for(int i = 0; i < branchesShas.count(); ++i)
{
//check parent
if (branchesShas[i].contains(commit))
{
if (!branchesShas[i].contains(parent))
{
//parent and child are not in same branch
//since it is list, than parent has i+1 index
//set CROSS and HCROSS
for(QList::iterator f_iter = iter;
f_iter != commitList.end(); ++f_iter)
{
if (parent == f_iter->getCommit())
{
for(int j = 0; j < i; ++j)
{
if(branchesShas[j].contains(parent))
f_iter->setPropetry(j, DVcsEvent::MERGE);
else
f_iter->setPropetry(j, DVcsEvent::HCROSS);
}
f_iter->setType(DVcsEvent::MERGE);
f_iter->setPropetry(i, DVcsEvent::MERGE_RIGHT);
qCDebug(PLUGIN_GIT) << parent << " is parent of " << commit;
qCDebug(PLUGIN_GIT) << f_iter->getCommit() << " is merge";
parent_checked = true;
break;
}
else
f_iter->setPropetry(i, DVcsEvent::CROSS);
}
}
}
//mark HEADs
if (!branchesShas[i].empty() && commit == branchesShas[i][0])
{
iter->setType(DVcsEvent::HEAD);
iter->setPropetry(i, DVcsEvent::HEAD);
heads_checked++;
qCDebug(PLUGIN_GIT) << "HEAD found";
}
//some optimization
if (heads_checked == branchesShas.count() && parent_checked)
break;
}
}
return commitList;
}
void GitPlugin::initBranchHash(const QString &repo)
{
const QUrl repoUrl = QUrl::fromLocalFile(repo);
QStringList gitBranches = runSynchronously(branches(repoUrl)).toStringList();
qCDebug(PLUGIN_GIT) << "BRANCHES: " << gitBranches;
//Now root branch is the current branch. In future it should be the longest branch
//other commitLists are got with git-rev-lits branch ^br1 ^ br2
QString root = runSynchronously(currentBranch(repoUrl)).toString();
QScopedPointer job(gitRevList(repo, QStringList(root)));
bool ret = job->exec();
Q_ASSERT(ret && job->status()==VcsJob::JobSucceeded && "TODO: provide a fall back in case of failing");
Q_UNUSED(ret);
QStringList commits = job->output().split('\n', QString::SkipEmptyParts);
// qCDebug(PLUGIN_GIT) << "\n\n\n commits" << commits << "\n\n\n";
branchesShas.append(commits);
foreach(const QString &branch, gitBranches)
{
if (branch == root)
continue;
QStringList args(branch);
foreach(const QString &branch_arg, gitBranches)
{
if (branch_arg != branch)
//man gitRevList for '^'
args<<'^' + branch_arg;
}
QScopedPointer job(gitRevList(repo, args));
bool ret = job->exec();
Q_ASSERT(ret && job->status()==VcsJob::JobSucceeded && "TODO: provide a fall back in case of failing");
Q_UNUSED(ret);
QStringList commits = job->output().split('\n', QString::SkipEmptyParts);
// qCDebug(PLUGIN_GIT) << "\n\n\n commits" << commits << "\n\n\n";
branchesShas.append(commits);
}
}
//Actually we can just copy the output without parsing. So it's a kind of draft for future
void GitPlugin::parseLogOutput(const DVcsJob * job, QList& commits) const
{
// static QRegExp rx_sep( "[-=]+" );
// static QRegExp rx_date( "date:\\s+([^;]*);\\s+author:\\s+([^;]*).*" );
static QRegularExpression rx_com( "commit \\w{1,40}" );
const auto output = job->output();
const auto lines = output.splitRef('\n', QString::SkipEmptyParts);
DVcsEvent item;
QString commitLog;
for (int i=0; i= 0x050500
if (rx_com.match(lines[i]).hasMatch()) {
#else
if (rx_com.match(lines[i].toString()).hasMatch()) {
#endif
// qCDebug(PLUGIN_GIT) << "MATCH COMMIT";
item.setCommit(lines[++i].toString());
item.setAuthor(lines[++i].toString());
item.setDate(lines[++i].toString());
item.setLog(commitLog);
commits.append(item);
}
else
{
//FIXME: add this in a loop to the if, like in getAllCommits()
commitLog += lines[i].toString() +'\n';
}
}
}
VcsItemEvent::Actions actionsFromString(char c)
{
switch(c) {
case 'A': return VcsItemEvent::Added;
case 'D': return VcsItemEvent::Deleted;
case 'R': return VcsItemEvent::Replaced;
case 'M': return VcsItemEvent::Modified;
}
return VcsItemEvent::Modified;
}
void GitPlugin::parseGitLogOutput(DVcsJob * job)
{
static QRegExp commitRegex( "^commit (\\w{8})\\w{32}" );
static QRegExp infoRegex( "^(\\w+):(.*)" );
static QRegExp modificationsRegex("^([A-Z])[0-9]*\t([^\t]+)\t?(.*)", Qt::CaseSensitive, QRegExp::RegExp2);
//R099 plugins/git/kdevgit.desktop plugins/git/kdevgit.desktop.cmake
//M plugins/grepview/CMakeLists.txt
QList commits;
QString contents = job->output();
// check if git-log returned anything
if (contents.isEmpty()) {
job->setResults(commits); // empty list
return;
}
// start parsing the output
QTextStream s(&contents);
VcsEvent item;
QString message;
bool pushCommit = false;
while (!s.atEnd()) {
QString line = s.readLine();
if (commitRegex.exactMatch(line)) {
if (pushCommit) {
item.setMessage(message.trimmed());
commits.append(QVariant::fromValue(item));
item.setItems(QList());
} else {
pushCommit = true;
}
VcsRevision rev;
rev.setRevisionValue(commitRegex.cap(1), KDevelop::VcsRevision::GlobalNumber);
item.setRevision(rev);
message.clear();
} else if (infoRegex.exactMatch(line)) {
QString cap1 = infoRegex.cap(1);
if (cap1 == QLatin1String("Author")) {
item.setAuthor(infoRegex.cap(2).trimmed());
} else if (cap1 == QLatin1String("Date")) {
item.setDate(QDateTime::fromTime_t(infoRegex.cap(2).trimmed().split(' ')[0].toUInt()));
}
} else if (modificationsRegex.exactMatch(line)) {
VcsItemEvent::Actions a = actionsFromString(modificationsRegex.cap(1).at(0).toLatin1());
QString filenameA = modificationsRegex.cap(2);
VcsItemEvent itemEvent;
itemEvent.setActions(a);
itemEvent.setRepositoryLocation(filenameA);
if(a==VcsItemEvent::Replaced) {
QString filenameB = modificationsRegex.cap(3);
itemEvent.setRepositoryCopySourceLocation(filenameB);
}
item.addItem(itemEvent);
} else if (line.startsWith(QLatin1String(" "))) {
message += line.remove(0, 4);
message += '\n';
}
}
item.setMessage(message.trimmed());
commits.append(QVariant::fromValue(item));
job->setResults(commits);
}
void GitPlugin::parseGitDiffOutput(DVcsJob* job)
{
VcsDiff diff;
diff.setDiff(job->output());
diff.setBaseDiff(repositoryRoot(QUrl::fromLocalFile(job->directory().absolutePath())));
diff.setDepth(usePrefix()? 1 : 0);
job->setResults(qVariantFromValue(diff));
}
static VcsStatusInfo::State lsfilesToState(char id)
{
switch(id) {
case 'H': return VcsStatusInfo::ItemUpToDate; //Cached
case 'S': return VcsStatusInfo::ItemUpToDate; //Skip work tree
case 'M': return VcsStatusInfo::ItemHasConflicts; //unmerged
case 'R': return VcsStatusInfo::ItemDeleted; //removed/deleted
case 'C': return VcsStatusInfo::ItemModified; //modified/changed
case 'K': return VcsStatusInfo::ItemDeleted; //to be killed
case '?': return VcsStatusInfo::ItemUnknown; //other
}
Q_ASSERT(false);
return VcsStatusInfo::ItemUnknown;
}
void GitPlugin::parseGitStatusOutput_old(DVcsJob* job)
{
QStringList outputLines = job->output().split('\n', QString::SkipEmptyParts);
QDir dir = job->directory();
QMap allStatus;
foreach(const QString& line, outputLines) {
VcsStatusInfo::State status = lsfilesToState(line[0].toLatin1());
QUrl url = QUrl::fromLocalFile(dir.absoluteFilePath(line.right(line.size()-2)));
allStatus[url] = status;
}
QVariantList statuses;
QMap< QUrl, VcsStatusInfo::State >::const_iterator it = allStatus.constBegin(), itEnd=allStatus.constEnd();
for(; it!=itEnd; ++it) {
VcsStatusInfo status;
status.setUrl(it.key());
status.setState(it.value());
statuses.append(qVariantFromValue(status));
}
job->setResults(statuses);
}
void GitPlugin::parseGitStatusOutput(DVcsJob* job)
{
const auto output = job->output();
const auto outputLines = output.splitRef('\n', QString::SkipEmptyParts);
QDir workingDir = job->directory();
QDir dotGit = dotGitDirectory(QUrl::fromLocalFile(workingDir.absolutePath()));
QVariantList statuses;
QList processedFiles;
foreach(const QStringRef& line, outputLines) {
//every line is 2 chars for the status, 1 space then the file desc
QStringRef curr=line.right(line.size()-3);
QStringRef state = line.left(2);
int arrow = curr.indexOf(QStringLiteral(" -> "));
if(arrow>=0) {
VcsStatusInfo status;
status.setUrl(QUrl::fromLocalFile(dotGit.absoluteFilePath(curr.toString().left(arrow))));
status.setState(VcsStatusInfo::ItemDeleted);
statuses.append(qVariantFromValue(status));
processedFiles += status.url();
curr = curr.mid(arrow+4);
}
if(curr.startsWith('\"') && curr.endsWith('\"')) { //if the path is quoted, unquote
curr = curr.mid(1, curr.size()-2);
}
VcsStatusInfo status;
status.setUrl(QUrl::fromLocalFile(dotGit.absoluteFilePath(curr.toString())));
status.setState(messageToState(state));
processedFiles.append(status.url());
qCDebug(PLUGIN_GIT) << "Checking git status for " << line << curr << status.state();
statuses.append(qVariantFromValue(status));
}
QStringList paths;
QStringList oldcmd=job->dvcsCommand();
QStringList::const_iterator it=oldcmd.constBegin()+oldcmd.indexOf(QStringLiteral("--"))+1, itEnd=oldcmd.constEnd();
for(; it!=itEnd; ++it)
paths += *it;
//here we add the already up to date files
QStringList files = getLsFiles(job->directory(), QStringList() << QStringLiteral("-c") << QStringLiteral("--") << paths, OutputJob::Silent);
foreach(const QString& file, files) {
QUrl fileUrl = QUrl::fromLocalFile(workingDir.absoluteFilePath(file));
if(!processedFiles.contains(fileUrl)) {
VcsStatusInfo status;
status.setUrl(fileUrl);
status.setState(VcsStatusInfo::ItemUpToDate);
statuses.append(qVariantFromValue(status));
}
}
job->setResults(statuses);
}
void GitPlugin::parseGitVersionOutput(DVcsJob* job)
{
const auto output = job->output().trimmed();
auto versionString = output.midRef(output.lastIndexOf(' ')).split('.');
static const QList minimumVersion = QList() << 1 << 7;
qCDebug(PLUGIN_GIT) << "checking git version" << versionString << "against" << minimumVersion;
m_oldVersion = false;
if (versionString.size() < minimumVersion.size()) {
m_oldVersion = true;
qCWarning(PLUGIN_GIT) << "invalid git version string:" << job->output().trimmed();
return;
}
foreach(int num, minimumVersion) {
QStringRef curr = versionString.takeFirst();
int valcurr = curr.toInt();
if (valcurr < num) {
m_oldVersion = true;
break;
}
if (valcurr > num) {
m_oldVersion = false;
break;
}
}
qCDebug(PLUGIN_GIT) << "the current git version is old: " << m_oldVersion;
}
QStringList GitPlugin::getLsFiles(const QDir &directory, const QStringList &args,
KDevelop::OutputJob::OutputJobVerbosity verbosity)
{
QScopedPointer job(lsFiles(directory, args, verbosity));
if (job->exec() && job->status() == KDevelop::VcsJob::JobSucceeded)
return job->output().split('\n', QString::SkipEmptyParts);
return QStringList();
}
DVcsJob* GitPlugin::gitRevParse(const QString &repository, const QStringList &args,
KDevelop::OutputJob::OutputJobVerbosity verbosity)
{
DVcsJob* job = new DVcsJob(QDir(repository), this, verbosity);
*job << "git" << "rev-parse" << args;
return job;
}
DVcsJob* GitPlugin::gitRevList(const QString& directory, const QStringList& args)
{
DVcsJob* job = new DVcsJob(urlDir(QUrl::fromLocalFile(directory)), this, KDevelop::OutputJob::Silent);
{
*job << "git" << "rev-list" << args;
return job;
}
}
VcsStatusInfo::State GitPlugin::messageToState(const QStringRef& msg)
{
Q_ASSERT(msg.size()==1 || msg.size()==2);
VcsStatusInfo::State ret = VcsStatusInfo::ItemUnknown;
if(msg.contains('U') || msg == QLatin1String("AA") || msg == QLatin1String("DD"))
ret = VcsStatusInfo::ItemHasConflicts;
else switch(msg.at(0).toLatin1())
{
case 'M':
ret = VcsStatusInfo::ItemModified;
break;
case 'A':
ret = VcsStatusInfo::ItemAdded;
break;
case 'R':
ret = VcsStatusInfo::ItemModified;
break;
case 'C':
ret = VcsStatusInfo::ItemHasConflicts;
break;
case ' ':
ret = msg.at(1) == 'M' ? VcsStatusInfo::ItemModified : VcsStatusInfo::ItemDeleted;
break;
case 'D':
ret = VcsStatusInfo::ItemDeleted;
break;
case '?':
ret = VcsStatusInfo::ItemUnknown;
break;
default:
qCDebug(PLUGIN_GIT) << "Git status not identified:" << msg;
break;
}
return ret;
}
StandardJob::StandardJob(IPlugin* parent, KJob* job,
OutputJob::OutputJobVerbosity verbosity)
: VcsJob(parent, verbosity)
, m_job(job)
, m_plugin(parent)
, m_status(JobNotStarted)
{}
void StandardJob::start()
{
connect(m_job, &KJob::result, this, &StandardJob::result);
m_job->start();
m_status=JobRunning;
}
void StandardJob::result(KJob* job)
{
m_status=job->error() == 0? JobSucceeded : JobFailed; emitResult();
}
VcsJob* GitPlugin::copy(const QUrl& localLocationSrc, const QUrl& localLocationDstn)
{
//TODO: Probably we should "git add" after
return new StandardJob(this, KIO::copy(localLocationSrc, localLocationDstn), KDevelop::OutputJob::Silent);
}
VcsJob* GitPlugin::move(const QUrl& source, const QUrl& destination)
{
QDir dir = urlDir(source);
QFileInfo fileInfo(source.toLocalFile());
if (fileInfo.isDir()) {
if (isEmptyDirStructure(QDir(source.toLocalFile()))) {
//move empty folder, git doesn't do that
qCDebug(PLUGIN_GIT) << "empty folder" << source;
return new StandardJob(this, KIO::move(source, destination), KDevelop::OutputJob::Silent);
}
}
QStringList otherStr = getLsFiles(dir, QStringList() << QStringLiteral("--others") << QStringLiteral("--") << source.toLocalFile(), KDevelop::OutputJob::Silent);
if(otherStr.isEmpty()) {
DVcsJob* job = new DVcsJob(dir, this, KDevelop::OutputJob::Verbose);
*job << "git" << "mv" << source.toLocalFile() << destination.toLocalFile();
return job;
} else {
return new StandardJob(this, KIO::move(source, destination), KDevelop::OutputJob::Silent);
}
}
void GitPlugin::parseGitRepoLocationOutput(DVcsJob* job)
{
job->setResults(QVariant::fromValue(QUrl::fromLocalFile(job->output())));
}
VcsJob* GitPlugin::repositoryLocation(const QUrl& localLocation)
{
DVcsJob* job = new DVcsJob(urlDir(localLocation), this);
//Probably we should check first if origin is the proper remote we have to use but as a first attempt it works
*job << "git" << "config" << "remote.origin.url";
connect(job, &DVcsJob::readyForParsing, this, &GitPlugin::parseGitRepoLocationOutput);
return job;
}
VcsJob* GitPlugin::pull(const KDevelop::VcsLocation& localOrRepoLocationSrc, const QUrl& localRepositoryLocation)
{
DVcsJob* job = new DVcsJob(urlDir(localRepositoryLocation), this);
job->setCommunicationMode(KProcess::MergedChannels);
*job << "git" << "pull";
if(!localOrRepoLocationSrc.localUrl().isEmpty())
*job << localOrRepoLocationSrc.localUrl().url();
return job;
}
VcsJob* GitPlugin::push(const QUrl& localRepositoryLocation, const KDevelop::VcsLocation& localOrRepoLocationDst)
{
DVcsJob* job = new DVcsJob(urlDir(localRepositoryLocation), this);
job->setCommunicationMode(KProcess::MergedChannels);
*job << "git" << "push";
if(!localOrRepoLocationDst.localUrl().isEmpty())
*job << localOrRepoLocationDst.localUrl().url();
return job;
}
VcsJob* GitPlugin::resolve(const QList& localLocations, IBasicVersionControl::RecursionMode recursion)
{
return add(localLocations, recursion);
}
VcsJob* GitPlugin::update(const QList& localLocations, const KDevelop::VcsRevision& rev, IBasicVersionControl::RecursionMode recursion)
{
if(rev.revisionType()==VcsRevision::Special && rev.revisionValue().value()==VcsRevision::Head) {
return pull(VcsLocation(), localLocations.first());
} else {
DVcsJob* job = new DVcsJob(urlDir(localLocations.first()), this);
{
//Probably we should check first if origin is the proper remote we have to use but as a first attempt it works
*job << "git" << "checkout" << rev.revisionValue().toString() << "--";
*job << (recursion == IBasicVersionControl::Recursive ? localLocations : preventRecursion(localLocations));
return job;
}
}
}
void GitPlugin::setupCommitMessageEditor(const QUrl& localLocation, KTextEdit* editor) const
{
new GitMessageHighlighter(editor);
QFile mergeMsgFile(dotGitDirectory(localLocation).filePath(QStringLiteral(".git/MERGE_MSG")));
// Some limit on the file size should be set since whole content is going to be read into
// the memory. 1Mb seems to be good value since it's rather strange to have so huge commit
// message.
static const qint64 maxMergeMsgFileSize = 1024*1024;
if (mergeMsgFile.size() > maxMergeMsgFileSize || !mergeMsgFile.open(QIODevice::ReadOnly))
return;
QString mergeMsg = QString::fromLocal8Bit(mergeMsgFile.read(maxMergeMsgFileSize));
editor->setPlainText(mergeMsg);
}
class GitVcsLocationWidget : public KDevelop::StandardVcsLocationWidget
{
Q_OBJECT
public:
explicit GitVcsLocationWidget(QWidget* parent = nullptr, Qt::WindowFlags f = nullptr)
: StandardVcsLocationWidget(parent, f) {}
bool isCorrect() const override
{
return !url().isEmpty();
}
};
KDevelop::VcsLocationWidget* GitPlugin::vcsLocation(QWidget* parent) const
{
return new GitVcsLocationWidget(parent);
}
void GitPlugin::registerRepositoryForCurrentBranchChanges(const QUrl& repository)
{
QDir dir = dotGitDirectory(repository);
QString headFile = dir.absoluteFilePath(QStringLiteral(".git/HEAD"));
m_watcher->addFile(headFile);
}
void GitPlugin::fileChanged(const QString& file)
{
Q_ASSERT(file.endsWith(QStringLiteral("HEAD")));
//SMTH/.git/HEAD -> SMTH/
const QUrl fileUrl = Path(file).parent().parent().toUrl();
//We need to delay the emitted signal, otherwise the branch hasn't change yet
//and the repository is not functional
m_branchesChange.append(fileUrl);
QTimer::singleShot(1000, this, SLOT(delayedBranchChanged()));
}
void GitPlugin::delayedBranchChanged()
{
emit repositoryBranchChanged(m_branchesChange.takeFirst());
}
CheckInRepositoryJob* GitPlugin::isInRepository(KTextEditor::Document* document)
{
CheckInRepositoryJob* job = new GitPluginCheckInRepositoryJob(document, repositoryRoot(document->url()).path());
job->start();
return job;
}
DVcsJob* GitPlugin::setConfigOption(const QUrl& repository, const QString& key, const QString& value, bool global)
{
auto job = new DVcsJob(urlDir(repository), this);
QStringList args;
args << "git" << "config";
if(global)
args << "--global";
args << key << value;
*job << args;
return job;
}
QString GitPlugin::readConfigOption(const QUrl& repository, const QString& key)
{
QProcess exec;
exec.setWorkingDirectory(urlDir(repository).absolutePath());
exec.start("git", QStringList() << "config" << "--get" << key);
exec.waitForFinished();
return exec.readAllStandardOutput().trimmed();
}
#include "gitplugin.moc"
diff --git a/plugins/git/gitplugin.h b/plugins/git/gitplugin.h
index bbf4ed055f..e8b3191a77 100644
--- a/plugins/git/gitplugin.h
+++ b/plugins/git/gitplugin.h
@@ -1,224 +1,225 @@
/***************************************************************************
* Copyright 2008 Evgeniy Ivanov *
* Copyright 2009 Hugo Parente Lima *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License or (at your option) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
#ifndef KDEVPLATFORM_PLUGIN_GIT_PLUGIN_H
#define KDEVPLATFORM_PLUGIN_GIT_PLUGIN_H
#include
#include
#include
#include
#include
#include
#include
#include
class KDirWatch;
class QDir;
namespace KDevelop
{
class VcsJob;
class VcsRevision;
}
class StandardJob : public KDevelop::VcsJob
{
Q_OBJECT
public:
StandardJob(KDevelop::IPlugin* parent, KJob* job, OutputJobVerbosity verbosity);
QVariant fetchResults() override { return QVariant(); }
void start() override;
JobStatus status() const override { return m_status; }
KDevelop::IPlugin* vcsPlugin() const override { return m_plugin; }
public slots:
void result(KJob*);
private:
KJob* m_job;
KDevelop::IPlugin* m_plugin;
JobStatus m_status;
};
/**
* This is the main class of KDevelop's Git plugin.
*
* It implements the DVCS dependent things not implemented in KDevelop::DistributedVersionControlPlugin
* @author Evgeniy Ivanov
*/
class GitPlugin: public KDevelop::DistributedVersionControlPlugin, public KDevelop::IContentAwareVersionControl
{
Q_OBJECT
Q_INTERFACES(KDevelop::IBasicVersionControl KDevelop::IDistributedVersionControl KDevelop::IContentAwareVersionControl)
friend class GitInitTest;
public:
explicit GitPlugin(QObject *parent, const QVariantList & args = QVariantList() );
~GitPlugin() override;
QString name() const override;
+ bool isValidRemoteRepositoryUrl(const QUrl& remoteLocation) override;
bool isVersionControlled(const QUrl &path) override;
KDevelop::VcsJob* copy(const QUrl& localLocationSrc, const QUrl& localLocationDstn) override;
KDevelop::VcsJob* move(const QUrl& localLocationSrc, const QUrl& localLocationDst) override;
//TODO
KDevelop::VcsJob* pull(const KDevelop::VcsLocation& localOrRepoLocationSrc, const QUrl& localRepositoryLocation) override;
KDevelop::VcsJob* push(const QUrl& localRepositoryLocation, const KDevelop::VcsLocation& localOrRepoLocationDst) override;
KDevelop::VcsJob* repositoryLocation(const QUrl& localLocation) override;
KDevelop::VcsJob* resolve(const QList& localLocations, RecursionMode recursion) override;
KDevelop::VcsJob* update(const QList& localLocations, const KDevelop::VcsRevision& rev, RecursionMode recursion) override;
KDevelop::VcsLocationWidget* vcsLocation(QWidget* parent) const override;
void setupCommitMessageEditor(const QUrl& localLocation, KTextEdit* editor) const override;
//End of
KDevelop::VcsJob* add(const QList& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive) override;
KDevelop::VcsJob* createWorkingCopy(const KDevelop::VcsLocation & localOrRepoLocationSrc,
const QUrl& localRepositoryRoot, KDevelop::IBasicVersionControl::RecursionMode) override;
KDevelop::VcsJob* remove(const QList& files) override;
KDevelop::VcsJob* status(const QList& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive) override;
KDevelop::VcsJob* commit(const QString& message,
const QList& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive) override;
KDevelop::VcsJob* diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision,
KDevelop::VcsDiff::Type, RecursionMode recursion) override;
KDevelop::VcsJob* log( const QUrl& localLocation, const KDevelop::VcsRevision& rev, unsigned long limit) override;
KDevelop::VcsJob* log(const QUrl& localLocation, const KDevelop::VcsRevision& rev, const KDevelop::VcsRevision& limit) override;
KDevelop::VcsJob* annotate(const QUrl &localLocation, const KDevelop::VcsRevision &rev) override;
KDevelop::VcsJob* revert(const QList& localLocations, RecursionMode recursion) override;
// Begin: KDevelop::IDistributedVersionControl
KDevelop::VcsJob* init(const QUrl & directory) override;
// Branch management
KDevelop::VcsJob* tag(const QUrl& repository, const QString& commitMessage, const KDevelop::VcsRevision& rev, const QString& tagName) override;
KDevelop::VcsJob* branch(const QUrl& repository, const KDevelop::VcsRevision& rev, const QString& branchName) override;
KDevelop::VcsJob* branches(const QUrl& repository) override;
KDevelop::VcsJob* currentBranch(const QUrl& repository) override;
KDevelop::VcsJob* deleteBranch(const QUrl& repository, const QString& branchName) override;
KDevelop::VcsJob* switchBranch(const QUrl& repository, const QString& branchName) override;
KDevelop::VcsJob* renameBranch(const QUrl& repository, const QString& oldBranchName, const QString& newBranchName) override;
KDevelop::VcsJob* mergeBranch(const QUrl& repository, const QString& branchName) override;
//graph helpers
QList getAllCommits(const QString &repo) override;
//used in log
void parseLogOutput(const KDevelop::DVcsJob * job,
QList& commits) const override;
void additionalMenuEntries(QMenu* menu, const QList& urls) override;
KDevelop::DVcsJob* gitStash(const QDir& repository, const QStringList& args, KDevelop::OutputJob::OutputJobVerbosity verbosity);
bool hasStashes(const QDir& repository);
bool hasModifications(const QDir& repository);
bool hasModifications(const QDir& repo, const QUrl& file);
void registerRepositoryForCurrentBranchChanges(const QUrl& repository) override;
KDevelop::CheckInRepositoryJob* isInRepository(KTextEditor::Document* document) override;
KDevelop::DVcsJob* setConfigOption(const QUrl& repository, const QString& key, const QString& value, bool global = false);
QString readConfigOption(const QUrl& repository, const QString& key);
// this indicates whether the diff() function will generate a diff (patch) which
// includes the working copy directory name or not (in which case git diff is called
// with --no-prefix).
bool usePrefix() const
{
return m_usePrefix;
}
void setUsePrefix(bool p)
{
m_usePrefix = p;
}
protected:
QUrl repositoryRoot(const QUrl& path);
bool isValidDirectory(const QUrl &dirPath) override;
KDevelop::DVcsJob* lsFiles(const QDir &repository,
const QStringList &args,
KDevelop::OutputJob::OutputJobVerbosity verbosity = KDevelop::OutputJob::Verbose);
KDevelop::DVcsJob* gitRevList(const QString &directory,
const QStringList &args);
KDevelop::DVcsJob* gitRevParse(const QString &repository,
const QStringList &args,
KDevelop::OutputJob::OutputJobVerbosity verbosity = KDevelop::OutputJob::Silent);
private slots:
void parseGitBlameOutput(KDevelop::DVcsJob *job);
void parseGitLogOutput(KDevelop::DVcsJob *job);
void parseGitDiffOutput(KDevelop::DVcsJob* job);
void parseGitRepoLocationOutput(KDevelop::DVcsJob* job);
void parseGitStatusOutput(KDevelop::DVcsJob* job);
void parseGitStatusOutput_old(KDevelop::DVcsJob* job);
void parseGitVersionOutput(KDevelop::DVcsJob* job);
void parseGitBranchOutput(KDevelop::DVcsJob* job);
void parseGitCurrentBranch(KDevelop::DVcsJob* job);
void ctxPushStash();
void ctxPopStash();
void ctxStashManager();
void fileChanged(const QString& file);
void delayedBranchChanged();
signals:
void repositoryBranchChanged(const QUrl& repository);
private:
bool ensureValidGitIdentity(const QDir& dir);
void addNotVersionedFiles(const QDir& dir, const QList& files);
//commit dialog "main" helper
QStringList getLsFiles(const QDir &directory, const QStringList &args,
KDevelop::OutputJob::OutputJobVerbosity verbosity);
KDevelop::DVcsJob* errorsFound(const QString& error, KDevelop::OutputJob::OutputJobVerbosity verbosity);
void initBranchHash(const QString &repo);
static KDevelop::VcsStatusInfo::State messageToState(const QStringRef& ch);
QList branchesShas;
QList m_urls;
/** Tells if it's older than 1.7.0 or not */
bool m_oldVersion;
KDirWatch* m_watcher;
QList m_branchesChange;
bool m_usePrefix;
};
QVariant runSynchronously(KDevelop::VcsJob* job);
#endif
diff --git a/plugins/perforce/perforceplugin.cpp b/plugins/perforce/perforceplugin.cpp
index 2b96de43ae..fb16f9daa6 100644
--- a/plugins/perforce/perforceplugin.cpp
+++ b/plugins/perforce/perforceplugin.cpp
@@ -1,692 +1,699 @@
/***************************************************************************
* Copyright 2010 Morten Danielsen Volden *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
#include "perforceplugin.h"
#include "debug.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace KDevelop;
namespace
{
QString toRevisionName(const KDevelop::VcsRevision& rev, QString currentRevision=QString())
{
bool ok;
int previous = currentRevision.toInt(&ok);
previous--;
QString tmp;
switch(rev.revisionType()) {
case VcsRevision::Special:
switch(rev.revisionValue().value()) {
case VcsRevision::Head:
return QStringLiteral("#head");
case VcsRevision::Base:
return QStringLiteral("#have");
case VcsRevision::Working:
return QStringLiteral("#have");
case VcsRevision::Previous:
Q_ASSERT(!currentRevision.isEmpty());
tmp.setNum(previous);
tmp.prepend("#");
return tmp;
case VcsRevision::Start:
return QString();
case VcsRevision::UserSpecialType: //Not used
Q_ASSERT(false && "i don't know how to do that");
}
break;
case VcsRevision::GlobalNumber:
tmp.append("#");
tmp.append(rev.revisionValue().toString());
return tmp;
case VcsRevision::Date:
case VcsRevision::FileNumber:
case VcsRevision::Invalid:
case VcsRevision::UserSpecialType:
Q_ASSERT(false);
}
return QString();
}
VcsItemEvent::Actions actionsFromString(QString const& changeDescription)
{
if(changeDescription == "add")
return VcsItemEvent::Added;
if(changeDescription == "delete")
return VcsItemEvent::Deleted;
return VcsItemEvent::Modified;
}
QDir urlDir(const QUrl& url)
{
QFileInfo f(url.toLocalFile());
if(f.isDir())
return QDir(url.toLocalFile());
else
return f.absoluteDir();
}
}
Q_LOGGING_CATEGORY(PLUGIN_PERFORCE, "kdevplatform.plugins.perforce")
PerforcePlugin::PerforcePlugin(QObject* parent, const QVariantList&):
KDevelop::IPlugin("kdevperforce", parent)
, m_common(new KDevelop::VcsPluginHelper(this, this))
, m_perforcemenu(nullptr)
, m_perforceConfigName("p4config.txt")
, m_perforceExecutable("p4")
, m_edit_action(nullptr)
{
QProcessEnvironment currentEviron(QProcessEnvironment::systemEnvironment());
QString tmp(currentEviron.value("P4CONFIG"));
if (tmp.isEmpty()) {
// We require the P4CONFIG variable to be set because the perforce command line client will need it
setErrorDescription(i18n("The variable P4CONFIG is not set. Is perforce installed on the system?"));
return;
} else {
m_perforceConfigName = tmp;
}
qCDebug(PLUGIN_PERFORCE) << "The value of P4CONFIG is : " << tmp;
}
PerforcePlugin::~PerforcePlugin()
{
}
QString PerforcePlugin::name() const
{
return i18n("Perforce");
}
KDevelop::VcsImportMetadataWidget* PerforcePlugin::createImportMetadataWidget(QWidget* /*parent*/)
{
return nullptr;
}
+bool PerforcePlugin::isValidRemoteRepositoryUrl(const QUrl& remoteLocation)
+{
+ Q_UNUSED(remoteLocation);
+ // TODO
+ return false;
+}
+
bool PerforcePlugin::isValidDirectory(const QUrl & dirPath)
{
const QFileInfo finfo(dirPath.toLocalFile());
QDir dir = finfo.isDir() ? QDir(dirPath.toLocalFile()) : finfo.absoluteDir();
do {
if (dir.exists(m_perforceConfigName)) {
return true;
}
} while (dir.cdUp());
return false;
}
bool PerforcePlugin::isVersionControlled(const QUrl& localLocation)
{
QFileInfo fsObject(localLocation.toLocalFile());
if (fsObject.isDir()) {
return isValidDirectory(localLocation);
}
return parseP4fstat(fsObject, KDevelop::OutputJob::Silent);
}
DVcsJob* PerforcePlugin::p4fstatJob(const QFileInfo& curFile, OutputJob::OutputJobVerbosity verbosity)
{
DVcsJob* job = new DVcsJob(curFile.absolutePath(), this, verbosity);
setEnvironmentForJob(job, curFile);
*job << m_perforceExecutable << "fstat" << curFile.fileName();
return job;
}
bool PerforcePlugin::parseP4fstat(const QFileInfo& curFile, OutputJob::OutputJobVerbosity verbosity)
{
QScopedPointer job(p4fstatJob(curFile, verbosity));
if (job->exec() && job->status() == KDevelop::VcsJob::JobSucceeded) {
qCDebug(PLUGIN_PERFORCE) << "Perforce returned: " << job->output();
if (!job->output().isEmpty())
return true;
}
return false;
}
QString PerforcePlugin::getRepositoryName(const QFileInfo& curFile)
{
static const QString DEPOT_FILE_STR("... depotFile ");
QString ret;
QScopedPointer job(p4fstatJob(curFile, KDevelop::OutputJob::Silent));
if (job->exec() && job->status() == KDevelop::VcsJob::JobSucceeded) {
if (!job->output().isEmpty()) {
QStringList outputLines = job->output().split('\n', QString::SkipEmptyParts);
foreach(const QString & line, outputLines) {
int idx(line.indexOf(DEPOT_FILE_STR));
if (idx != -1) {
ret = line.right(line.size() - DEPOT_FILE_STR.size());
return ret;
}
}
}
}
return ret;
}
KDevelop::VcsJob* PerforcePlugin::repositoryLocation(const QUrl& /*localLocation*/)
{
return nullptr;
}
KDevelop::VcsJob* PerforcePlugin::add(const QList& localLocations, KDevelop::IBasicVersionControl::RecursionMode /*recursion*/)
{
QFileInfo curFile(localLocations.front().toLocalFile());
DVcsJob* job = new DVcsJob(curFile.dir(), this, KDevelop::OutputJob::Verbose);
setEnvironmentForJob(job, curFile);
*job << m_perforceExecutable << "add" << localLocations;
return job;
}
KDevelop::VcsJob* PerforcePlugin::remove(const QList& /*localLocations*/)
{
return nullptr;
}
KDevelop::VcsJob* PerforcePlugin::copy(const QUrl& /*localLocationSrc*/, const QUrl& /*localLocationDstn*/)
{
return nullptr;
}
KDevelop::VcsJob* PerforcePlugin::move(const QUrl& /*localLocationSrc*/, const QUrl& /*localLocationDst*/)
{
return nullptr;
}
KDevelop::VcsJob* PerforcePlugin::status(const QList& localLocations, KDevelop::IBasicVersionControl::RecursionMode /*recursion*/)
{
if (localLocations.count() != 1) {
KMessageBox::error(nullptr, i18n("Please select only one item for this operation"));
return nullptr;
}
QFileInfo curFile(localLocations.front().toLocalFile());
DVcsJob* job = new DVcsJob(curFile.dir(), this, KDevelop::OutputJob::Verbose);
setEnvironmentForJob(job, curFile);
*job << m_perforceExecutable << "fstat" << curFile.fileName();
connect(job, &DVcsJob::readyForParsing, this, &PerforcePlugin::parseP4StatusOutput);
return job;
}
KDevelop::VcsJob* PerforcePlugin::revert(const QList& localLocations, KDevelop::IBasicVersionControl::RecursionMode /*recursion*/)
{
if (localLocations.count() != 1) {
KMessageBox::error(nullptr, i18n("Please select only one item for this operation"));
return nullptr;
}
QFileInfo curFile(localLocations.front().toLocalFile());
DVcsJob* job = new DVcsJob(curFile.dir(), this, KDevelop::OutputJob::Verbose);
setEnvironmentForJob(job, curFile);
*job << m_perforceExecutable << "revert" << curFile.fileName();
return job;
}
KDevelop::VcsJob* PerforcePlugin::update(const QList& localLocations, const KDevelop::VcsRevision& /*rev*/, KDevelop::IBasicVersionControl::RecursionMode /*recursion*/)
{
QFileInfo curFile(localLocations.front().toLocalFile());
DVcsJob* job = new DVcsJob(curFile.dir(), this, KDevelop::OutputJob::Verbose);
setEnvironmentForJob(job, curFile);
//*job << m_perforceExecutable << "-p" << "127.0.0.1:1666" << "info"; - Let's keep this for now it's very handy for debugging
QString fileOrDirectory;
if (curFile.isDir())
fileOrDirectory = curFile.absolutePath() + "/...";
else
fileOrDirectory = curFile.fileName();
*job << m_perforceExecutable << "sync" << fileOrDirectory;
return job;
}
KDevelop::VcsJob* PerforcePlugin::commit(const QString& message, const QList& localLocations, KDevelop::IBasicVersionControl::RecursionMode /*recursion*/)
{
if (localLocations.empty() || message.isEmpty())
return errorsFound(i18n("No files or message specified"));
QFileInfo curFile(localLocations.front().toLocalFile());
DVcsJob* job = new DVcsJob(curFile.dir(), this, KDevelop::OutputJob::Verbose);
setEnvironmentForJob(job, curFile);
*job << m_perforceExecutable << "submit" << "-d" << message << localLocations;
return job;
}
KDevelop::VcsJob* PerforcePlugin::diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, KDevelop::VcsDiff::Type , KDevelop::IBasicVersionControl::RecursionMode /*recursion*/)
{
QFileInfo curFile(fileOrDirectory.toLocalFile());
QString depotSrcFileName = getRepositoryName(curFile);
QString depotDstFileName = depotSrcFileName;
depotSrcFileName.append(toRevisionName(srcRevision, dstRevision.prettyValue())); // dstRevision acutally contains the number that we want to take previous of
DVcsJob* job = new DVcsJob(curFile.dir(), this, KDevelop::OutputJob::Verbose);
setEnvironmentForJob(job, curFile);
switch (dstRevision.revisionType()) {
case VcsRevision::FileNumber:
case VcsRevision::GlobalNumber:
depotDstFileName.append("#");
depotDstFileName.append(dstRevision.prettyValue());
*job << m_perforceExecutable << "diff2" << "-u" << depotSrcFileName << depotDstFileName;
break;
case VcsRevision::Special:
switch (dstRevision.revisionValue().value()) {
case VcsRevision::Working:
*job << m_perforceExecutable << "diff" << "-du" << depotSrcFileName;
break;
case VcsRevision::Start:
case VcsRevision::UserSpecialType:
default:
break;
}
default:
break;
}
connect(job, &DVcsJob::readyForParsing, this, &PerforcePlugin::parseP4DiffOutput);
return job;
}
KDevelop::VcsJob* PerforcePlugin::log(const QUrl& localLocation, const KDevelop::VcsRevision& rev, long unsigned int limit)
{
static QString lastSeenChangeList;
QFileInfo curFile(localLocation.toLocalFile());
QString localLocationAndRevStr = localLocation.toLocalFile();
DVcsJob* job = new DVcsJob(urlDir(localLocation), this, KDevelop::OutputJob::Verbose);
setEnvironmentForJob(job, curFile);
*job << m_perforceExecutable << "filelog" << "-lit";
if(limit > 0)
*job << QStringLiteral("-m %1").arg(limit);
if (curFile.isDir()) {
localLocationAndRevStr.append("/...");
}
QString revStr = toRevisionName(rev, QString());
if(!revStr.isEmpty()) {
// This is not too nice, but perforce argument for restricting output from filelog does not Work :-(
// So putting this in so we do not end up in infinite loop calling log,
if(revStr == lastSeenChangeList) {
localLocationAndRevStr.append("#none");
lastSeenChangeList.clear();
} else {
localLocationAndRevStr.append(revStr);
lastSeenChangeList = revStr;
}
}
*job << localLocationAndRevStr;
qCDebug(PLUGIN_PERFORCE) << "Issuing the following command to p4: " << job->dvcsCommand();
connect(job, &DVcsJob::readyForParsing, this, &PerforcePlugin::parseP4LogOutput);
return job;
}
KDevelop::VcsJob* PerforcePlugin::log(const QUrl& localLocation, const KDevelop::VcsRevision& /*rev*/, const KDevelop::VcsRevision& /*limit*/)
{
QFileInfo curFile(localLocation.toLocalFile());
if (curFile.isDir()) {
KMessageBox::error(nullptr, i18n("Please select a file for this operation"));
return errorsFound(i18n("Directory not supported for this operation"));
}
DVcsJob* job = new DVcsJob(curFile.dir(), this, KDevelop::OutputJob::Verbose);
setEnvironmentForJob(job, curFile);
*job << m_perforceExecutable << "filelog" << "-lit" << localLocation;
connect(job, &DVcsJob::readyForParsing, this , &PerforcePlugin::parseP4LogOutput);
return job;
}
KDevelop::VcsJob* PerforcePlugin::annotate(const QUrl& localLocation, const KDevelop::VcsRevision& /*rev*/)
{
QFileInfo curFile(localLocation.toLocalFile());
if (curFile.isDir()) {
KMessageBox::error(nullptr, i18n("Please select a file for this operation"));
return errorsFound(i18n("Directory not supported for this operation"));
}
DVcsJob* job = new DVcsJob(curFile.dir(), this, KDevelop::OutputJob::Verbose);
setEnvironmentForJob(job, curFile);
*job << m_perforceExecutable << "annotate" << "-qi" << localLocation;
connect(job, &DVcsJob::readyForParsing, this , &PerforcePlugin::parseP4AnnotateOutput);
return job;
}
KDevelop::VcsJob* PerforcePlugin::resolve(const QList& /*localLocations*/, KDevelop::IBasicVersionControl::RecursionMode /*recursion*/)
{
return nullptr;
}
KDevelop::VcsJob* PerforcePlugin::createWorkingCopy(const KDevelop::VcsLocation& /*sourceRepository*/, const QUrl& /*destinationDirectory*/, KDevelop::IBasicVersionControl::RecursionMode /*recursion*/)
{
return nullptr;
}
KDevelop::VcsLocationWidget* PerforcePlugin::vcsLocation(QWidget* parent) const
{
return new StandardVcsLocationWidget(parent);
}
KDevelop::VcsJob* PerforcePlugin::edit(const QList& localLocations)
{
QFileInfo curFile(localLocations.front().toLocalFile());
DVcsJob* job = new DVcsJob(curFile.dir(), this, KDevelop::OutputJob::Verbose);
setEnvironmentForJob(job, curFile);
*job << m_perforceExecutable << "edit" << localLocations;
return job;
}
KDevelop::VcsJob* PerforcePlugin::edit(const QUrl& /*localLocation*/)
{
return nullptr;
}
KDevelop::VcsJob* PerforcePlugin::unedit(const QUrl& /*localLocation*/)
{
return nullptr;
}
KDevelop::VcsJob* PerforcePlugin::localRevision(const QUrl& /*localLocation*/, KDevelop::VcsRevision::RevisionType)
{
return nullptr;
}
KDevelop::VcsJob* PerforcePlugin::import(const QString& /*commitMessage*/, const QUrl& /*sourceDirectory*/, const KDevelop::VcsLocation& /*destinationRepository*/)
{
return nullptr;
}
KDevelop::ContextMenuExtension PerforcePlugin::contextMenuExtension(KDevelop::Context* context)
{
m_common->setupFromContext(context);
const QList & ctxUrlList = m_common->contextUrlList();
bool hasVersionControlledEntries = false;
for( const QUrl& url : ctxUrlList) {
if (isValidDirectory(url)) {
hasVersionControlledEntries = true;
break;
}
}
if (!hasVersionControlledEntries)
return IPlugin::contextMenuExtension(context);
QMenu * perforceMenu = m_common->commonActions();
perforceMenu->addSeparator();
perforceMenu->addSeparator();
if (!m_edit_action) {
m_edit_action = new QAction(i18n("Edit"), this);
connect(m_edit_action, &QAction::triggered, this, & PerforcePlugin::ctxEdit);
}
perforceMenu->addAction(m_edit_action);
ContextMenuExtension menuExt;
menuExt.addAction(ContextMenuExtension::VcsGroup, perforceMenu->menuAction());
return menuExt;
}
void PerforcePlugin::ctxEdit()
{
QList const & ctxUrlList = m_common->contextUrlList();
KDevelop::ICore::self()->runController()->registerJob(edit(ctxUrlList));
}
void PerforcePlugin::setEnvironmentForJob(DVcsJob* job, const QFileInfo& curFile)
{
KProcess* jobproc = job->process();
jobproc->setEnv("P4CONFIG", m_perforceConfigName);
if (curFile.isDir()) {
jobproc->setEnv("PWD", curFile.filePath());
} else {
jobproc->setEnv("PWD", curFile.absolutePath());
}
}
QList PerforcePlugin::getQvariantFromLogOutput(QStringList const& outputLines)
{
static const QString LOGENTRY_START("... #");
static const QString DEPOTMESSAGE_START("... .");
QMap changes;
QList commits;
QString currentFileName;
QString changeNumberStr, author,changeDescription, commitMessage;
VcsEvent currentVcsEvent;
VcsItemEvent currentRepoFile;
VcsRevision rev;
int indexofAt;
int changeNumber = 0;
foreach(const QString & line, outputLines) {
if (!line.startsWith(LOGENTRY_START) && !line.startsWith(DEPOTMESSAGE_START) && !line.startsWith('\t')) {
currentFileName = line;
}
if(line.indexOf(LOGENTRY_START) != -1)
{
// expecting the Logentry line to be of the form:
//... #5 change 10 edit on 2010/12/06 12:07:31 by mvo@testbed (text)
changeNumberStr = line.section(' ', 3, 3 ); // We use global change number
changeNumber = changeNumberStr.toInt();
author = line.section(' ', 9, 9);
changeDescription = line.section(' ' , 4, 4 );
indexofAt = author.indexOf('@');
author.remove(indexofAt, author.size()); // Only keep the username itself
rev.setRevisionValue(changeNumberStr, KDevelop::VcsRevision::GlobalNumber);
changes[changeNumber].setRevision(rev);
changes[changeNumber].setAuthor(author);
changes[changeNumber].setDate(QDateTime::fromString(line.section(' ', 6, 7), "yyyy/MM/dd hh:mm:ss"));
currentRepoFile.setRepositoryLocation(currentFileName);
currentRepoFile.setActions( actionsFromString(changeDescription) );
changes[changeNumber].addItem(currentRepoFile);
commitMessage.clear(); // We have a new entry, clear message
}
if (line.startsWith('\t') || line.startsWith(DEPOTMESSAGE_START)) {
commitMessage += line.trimmed() + '\n';
changes[changeNumber].setMessage(commitMessage);
}
}
for(auto item : changes) {
commits.prepend(QVariant::fromValue(item));
}
return commits;
}
void PerforcePlugin::parseP4StatusOutput(DVcsJob* job)
{
QStringList outputLines = job->output().split('\n', QString::SkipEmptyParts);
QVariantList statuses;
QList processedFiles;
static const QString ACTION_STR("... action ");
static const QString CLIENT_FILE_STR("... clientFile ");
VcsStatusInfo status;
status.setState(VcsStatusInfo::ItemUserState);
foreach(const QString & line, outputLines) {
int idx(line.indexOf(ACTION_STR));
if (idx != -1) {
QString curr = line.right(line.size() - ACTION_STR.size());
if (curr == "edit") {
status.setState(VcsStatusInfo::ItemModified);
} else if (curr == "add") {
status.setState(VcsStatusInfo::ItemAdded);
} else {
status.setState(VcsStatusInfo::ItemUserState);
}
continue;
}
idx = line.indexOf(CLIENT_FILE_STR);
if (idx != -1) {
QUrl fileUrl = QUrl::fromLocalFile(line.right(line.size() - CLIENT_FILE_STR.size()));
status.setUrl(fileUrl);
}
}
statuses.append(qVariantFromValue(status));
job->setResults(statuses);
}
void PerforcePlugin::parseP4LogOutput(KDevelop::DVcsJob* job)
{
QList commits(getQvariantFromLogOutput(job->output().split('\n', QString::SkipEmptyParts)));
job->setResults(commits);
}
void PerforcePlugin::parseP4DiffOutput(DVcsJob* job)
{
VcsDiff diff;
diff.setDiff(job->output());
QDir dir(job->directory());
do {
if (dir.exists(m_perforceConfigName)) {
break;
}
} while (dir.cdUp());
diff.setBaseDiff(QUrl::fromLocalFile(dir.absolutePath()));
job->setResults(qVariantFromValue(diff));
}
void PerforcePlugin::parseP4AnnotateOutput(DVcsJob *job)
{
QVariantList results;
/// First get the changelists for this file
QStringList strList(job->dvcsCommand());
QString localLocation(strList.last()); /// ASSUMPTION WARNING - localLocation is the last in the annotate command
KDevelop::VcsRevision dummyRev;
QScopedPointer logJob(new DVcsJob(job->directory(), this, OutputJob::Silent));
QFileInfo curFile(localLocation);
setEnvironmentForJob(logJob.data(), curFile);
*logJob << m_perforceExecutable << "filelog" << "-lit" << localLocation;
QList commits;
if (logJob->exec() && logJob->status() == KDevelop::VcsJob::JobSucceeded) {
if (!job->output().isEmpty()) {
commits = getQvariantFromLogOutput(logJob->output().split('\n', QString::SkipEmptyParts));
}
}
VcsEvent item;
QMap globalCommits;
/// Move the VcsEvents to a more suitable data strucure
for (QList::const_iterator commitsIt = commits.constBegin(), commitsEnd = commits.constEnd();
commitsIt != commitsEnd; ++commitsIt) {
if(commitsIt->canConvert())
{
item = commitsIt->value();
}
globalCommits.insert(item.revision().revisionValue().toLongLong(), item);
}
VcsAnnotationLine* annotation;
QStringList lines = job->output().split('\n');
size_t lineNumber(0);
QMap definedRevisions;
QMap::iterator currentEvent;
bool convertToIntOk(false);
int globalRevisionInt(0);
QString globalRevision;
for (QStringList::const_iterator it = lines.constBegin(), itEnd = lines.constEnd();
it != itEnd; ++it) {
if (it->isEmpty()) {
continue;
}
globalRevision = it->left(it->indexOf(':'));
annotation = new VcsAnnotationLine;
annotation->setLineNumber(lineNumber);
VcsRevision rev;
rev.setRevisionValue(globalRevision, KDevelop::VcsRevision::GlobalNumber);
annotation->setRevision(rev);
// Find the other info in the commits list
globalRevisionInt = globalRevision.toLongLong(&convertToIntOk);
if(convertToIntOk)
{
currentEvent = globalCommits.find(globalRevisionInt);
annotation->setAuthor(currentEvent->author());
annotation->setCommitMessage(currentEvent->message());
annotation->setDate(currentEvent->date());
}
results += qVariantFromValue(*annotation);
++lineNumber;
}
job->setResults(results);
}
KDevelop::VcsJob* PerforcePlugin::errorsFound(const QString& error, KDevelop::OutputJob::OutputJobVerbosity verbosity)
{
DVcsJob* j = new DVcsJob(QDir::temp(), this, verbosity);
*j << "echo" << i18n("error: %1", error) << "-n";
return j;
}
diff --git a/plugins/perforce/perforceplugin.h b/plugins/perforce/perforceplugin.h
index ef9bb7b837..dcb2560ec7 100644
--- a/plugins/perforce/perforceplugin.h
+++ b/plugins/perforce/perforceplugin.h
@@ -1,176 +1,177 @@
/***************************************************************************
* Copyright 2010 Morten Danielsen Volden *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
#ifndef KDEVPERFORCEPLUGIN_H
#define KDEVPERFORCEPLUGIN_H
#include
#include
#include
#include