diff --git a/plasmate/plugins/savesystemview/git.cpp b/plasmate/plugins/savesystemview/git.cpp index 924a733..90ab58e 100644 --- a/plasmate/plugins/savesystemview/git.cpp +++ b/plasmate/plugins/savesystemview/git.cpp @@ -1,223 +1,228 @@ /* Copyright 2014 Giorgos Tsiapaliokas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "git.h" #include "commitsmodel.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include #include #include #include #include #include #include Git::Git(QObject *parent) : QObject(parent), m_project(nullptr), m_dvcs(nullptr), m_branching(nullptr), m_branchesModel(nullptr) { m_branchesModel = new KDevelop::BranchesListModel(this); m_commitsModel = new CommitsModel(this); connect(m_branchesModel, &KDevelop::BranchesListModel::currentBranchChanged, this, &Git::commitsModelChanged); } Git::~Git() { } void Git::setProject(KDevelop::IProject *project) { m_project = project; m_repositoryPath = m_project->path().toUrl(); } KDevelop::IProject *Git::project() const { return m_project; } bool Git::initGit() { if (!m_project) { return false; } KDevelop::IPlugin* plugin = nullptr; if (!m_project->versionControlPlugin()) { plugin = KDevelop::ICore::self()->pluginController()->loadPlugin(QStringLiteral("kdevgit")); } else { plugin = m_project->versionControlPlugin(); } if (!plugin) { // the git plugin doesn't exist // there is nothing more for us to do then return false; } m_dvcs = plugin->extension(); m_branching = plugin->extension(); KDevelop::IBasicVersionControl *basicVersionControl = plugin->extension(); if (!m_dvcs || !m_branching || !basicVersionControl) { // something went wrong return false; } m_branchesModel->initialize(m_branching, m_repositoryPath); KDevelop::VcsRevision rev = KDevelop::VcsRevision::createSpecialRevision(KDevelop::VcsRevision::Base); +#if KDEVPLATFORM_VERSION >= QT_VERSION_CHECK(5, 1, 40) + KDevelop::VcsEventLogModel *vcsEventModel = new KDevelop::VcsEventLogModel(basicVersionControl, rev, m_repositoryPath, this); +#else KDevelop::VcsEventModel *vcsEventModel = new KDevelop::VcsEventModel(basicVersionControl, rev, m_repositoryPath, this); +#endif m_commitsModel->setSourceModel(vcsEventModel); return true; } bool Git::isRepository() { bool ok = m_dvcs->isVersionControlled(m_repositoryPath); if (ok) { // reset the model emit commitsModelChanged(); } return ok; } bool Git::initializeRepository() { if (!m_dvcs) { return false; } KDevelop::VcsJob *job = m_dvcs->init(m_repositoryPath); if (!handleJob(job)) { return false; } return newSavePoint(QStringLiteral("Initial Commit")); } bool Git::renameBranch(const QString &oldName, const QString &newName) { QList branchItems = m_branchesModel->findItems(oldName); if (branchItems.size() != 1) { // its not 1, so either we don't have a branch // or we have more than 1 return false; } QStandardItem *branchItem = branchItems.at(0); branchItem->setData(newName, Qt::EditRole); emit commitsModelChanged(); return true; } bool Git::handleJob(KDevelop::VcsJob *job) { if (!job) { return false; } bool success = true; if (!job->exec()) { if (job->status() != KDevelop::VcsJob::JobSucceeded) { KMessageBox::error(0, i18n(qPrintable(job->errorString()))); qDebug() << "Job output" << qobject_cast(job)->directory() << qobject_cast(job)->output() << job; qDebug() << "Job status" << job->status(); success = false; } } job->deleteLater(); return success; } QAbstractItemModel* Git::commitsModel() const { return m_commitsModel; } QAbstractItemModel* Git::branchesModel() const { return m_branchesModel; } bool Git::newSavePoint(const QString &commitMessage, bool saveDocuments) { if (saveDocuments && !KDevelop::ICore::self()->documentController()->saveAllDocuments()) { return false; } QList filesAndDirs; QDirIterator it(m_repositoryPath.toLocalFile(), QDirIterator::Subdirectories); while (it.hasNext()) { const QString entry = it.next(); const QString excludedFile = m_project->name() + ".plasmate"; if (it.fileInfo().isFile() && it.fileName() != excludedFile) { filesAndDirs << QUrl::fromLocalFile(it.filePath()); } } KDevelop::VcsJob *job = m_dvcs->add(filesAndDirs, KDevelop::IBasicVersionControl::Recursive); if (!handleJob(job)) { return false; } job = m_dvcs->commit(commitMessage, filesAndDirs, KDevelop::IBasicVersionControl::Recursive); if (!handleJob(job)) { return false; } emit commitsModelChanged(); return true; }