Commit 0908d795 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Improve the IBranchingVersionControl interface.

Adapt nowadays branching solutions to the new interface, including git plugin and the
branching module.
parent b10df1c3
......@@ -506,9 +506,34 @@ void GitPlugin::parseGitBlameOutput(DVcsJob *job)
job->setResults(results);
}
DVcsJob* GitPlugin::switchBranch(const QString &repository, const QString &branch)
DVcsJob* GitPlugin::lsFiles(const QDir &repository, const QStringList &args,
OutputJob::OutputJobVerbosity verbosity)
{
QDir d(repository);
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 KUrl& 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 KUrl &repository, const QString &branch)
{
QDir d=urlDir(repository);
if(hasModifications(d) && KMessageBox::questionYesNo(0, i18n("There are pending changes, do you want to stash them first?"))==KMessageBox::Yes) {
QScopedPointer<DVcsJob> stash(gitStash(d, QStringList(), KDevelop::OutputJob::Verbose));
......@@ -520,77 +545,70 @@ DVcsJob* GitPlugin::switchBranch(const QString &repository, const QString &branc
return job;
}
DVcsJob* GitPlugin::branch(const QString &repository, const QString &basebranch, const QString &branch,
const QStringList &args)
VcsJob* GitPlugin::branch(const KUrl& repository, const KDevelop::VcsRevision& rev, const QString& branchName)
{
DVcsJob* job = new DVcsJob(QDir(repository), this, KDevelop::OutputJob::Silent);
*job << "git" << "branch" << args;
Q_ASSERT(!branchName.isEmpty());
DVcsJob* job = new DVcsJob(urlDir(repository), this);
*job << "git" << "branch" << "--" << branchName;
*job << "--";
if (!branch.isEmpty())
*job << branch;
if (!basebranch.isEmpty())
*job << basebranch;
if(!rev.prettyValue().isEmpty())
*job << rev.revisionValue().toString();
return job;
}
DVcsJob* GitPlugin::lsFiles(const QDir &repository, const QStringList &args,
OutputJob::OutputJobVerbosity verbosity)
VcsJob* GitPlugin::deleteBranch(const KUrl& repository, const QString& branchName)
{
DVcsJob* job = new DVcsJob(repository, this, verbosity);
*job << "git" << "ls-files" << args;
DVcsJob* job = new DVcsJob(urlDir(repository), this, OutputJob::Silent);
*job << "git" << "branch" << "-D" << branchName;
connect(job, SIGNAL(readyForParsing(KDevelop::DVcsJob*)), SLOT(parseGitCurrentBranch(KDevelop::DVcsJob*)));
return job;
}
DVcsJob* GitPlugin::gitStash(const QDir& repository, const QStringList& args, OutputJob::OutputJobVerbosity verbosity)
VcsJob* GitPlugin::renameBranch(const KUrl& repository, const QString& oldBranchName, const QString& newBranchName)
{
DVcsJob* job = new DVcsJob(repository, this, verbosity);
*job << "git" << "stash" << args;
DVcsJob* job = new DVcsJob(urlDir(repository), this, OutputJob::Silent);
*job << "git" << "branch" << "-m" << newBranchName << oldBranchName;
connect(job, SIGNAL(readyForParsing(KDevelop::DVcsJob*)), SLOT(parseGitCurrentBranch(KDevelop::DVcsJob*)));
return job;
}
QString GitPlugin::curBranch(const QString &repository)
VcsJob* GitPlugin::currentBranch(const KUrl& repository)
{
kDebug() << "Getting branch list";
QScopedPointer<DVcsJob> job(new DVcsJob(QDir(repository), this, OutputJob::Silent));
DVcsJob* job = new DVcsJob(urlDir(repository), this, OutputJob::Silent);
*job << "git" << "symbolic-ref" << "HEAD";
if (job->exec() && job->status() == KDevelop::VcsJob::JobSucceeded) {
QString out = job->output().trimmed();
kDebug() << "Getting branch list" << out.right(out.size()-11);
return out.right(out.size()-11);
}
return QString();
connect(job, SIGNAL(readyForParsing(KDevelop::DVcsJob*)), SLOT(parseGitCurrentBranch(KDevelop::DVcsJob*)));
return job;
}
QStringList GitPlugin::branches(const QString &repository)
void GitPlugin::parseGitCurrentBranch(DVcsJob* job)
{
QStringList branchListDirty;
QScopedPointer<DVcsJob> job(branch(repository));
kDebug() << "Getting branch list";
if (job->exec() && job->status() == KDevelop::VcsJob::JobSucceeded)
branchListDirty = job->output().split('\n', QString::SkipEmptyParts);
else
return QStringList();
QString out = job->output().trimmed();
job->setResults(out.right(out.size()-11));
}
VcsJob* GitPlugin::branches(const KUrl &repository)
{
DVcsJob* job=new DVcsJob(urlDir(repository));
*job << "git" << "branch" << "-a";
connect(job, SIGNAL(readyForParsing(KDevelop::DVcsJob*)), SLOT(parseGitBranchOutput(KDevelop::DVcsJob*)));
return job;
}
void GitPlugin::parseGitBranchOutput(DVcsJob* job)
{
QStringList branchListDirty = job->output().split('\n', QString::SkipEmptyParts);
QStringList branchList;
foreach(QString branch, branchListDirty)
{
if (branch.contains('*'))
{
branch = branch.prepend('\n').section("\n*", 1);
}
else
{
branch = branch.prepend('\n').section('\n', 1);
}
if (branch.startsWith('*'))
branch = branch.right(branch.size()-2);
branch = branch.trimmed();
branchList<<branch;
branchList<<branch.trimmed();
}
return branchList;
job->setResults(branchList);
}
/* Few words about how this hardcore works:
......@@ -779,7 +797,7 @@ QList<DVcsEvent> GitPlugin::getAllCommits(const QString &repo)
void GitPlugin::initBranchHash(const QString &repo)
{
QStringList branches = GitPlugin::branches(repo);
QStringList branches = listBranches(KUrl(repo));
kDebug() << "BRANCHES: " << branches;
//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
......
......@@ -114,16 +114,13 @@ public:
KDevelop::VcsJob* init(const KUrl & directory);
// Branch management
KDevelop::DVcsJob* switchBranch(const QString &repository,
const QString &branch);
KDevelop::DVcsJob* branch(const QString &repository,
const QString &basebranch = QString(),
const QString &branch = QString(),
const QStringList &args = QStringList());
QString curBranch(const QString &repository);
QStringList branches(const QString &repository);
KDevelop::VcsJob* tag(const KUrl& repository, const QString& commitMessage, const KDevelop::VcsRevision& rev, const QString& tagName);
KDevelop::VcsJob* branch(const KUrl& repository, const KDevelop::VcsRevision& rev, const QString& branchName);
KDevelop::VcsJob* branches(const KUrl& repository);
KDevelop::VcsJob* currentBranch(const KUrl& repository);
KDevelop::VcsJob* deleteBranch(const KUrl& repository, const QString& branchName);
KDevelop::VcsJob* switchBranch(const KUrl& repository, const QString& branchName);
KDevelop::VcsJob* renameBranch(const KUrl& repository, const QString& oldBranchName, const QString& newBranchName);
//graph helpers
QList<DVcsEvent> getAllCommits(const QString &repo);
......@@ -164,6 +161,7 @@ private slots:
void parseGitStatusOutput(KDevelop::DVcsJob* job);
void parseGitStatusOutput_old(KDevelop::DVcsJob* job);
void parseGitVersionOutput(KDevelop::DVcsJob* job);
void parseGitBranchOutput(KDevelop::DVcsJob* job);
void ctxPushStash();
void ctxPopStash();
......@@ -189,6 +187,8 @@ private:
bool m_hasError;
QString m_errorDescription;
public slots:
void parseGitCurrentBranch(KDevelop::DVcsJob*);
};
#endif
......@@ -277,24 +277,26 @@ void GitInitTest::testCommit()
void GitInitTest::testBranching()
{
DVcsJob* j = m_plugin->branch(gitTest_BaseDir);
VcsJob* j = m_plugin->branches(KUrl(gitTest_BaseDir));
VERIFYJOB(j);
QString curBranch = m_plugin->curBranch(gitTest_BaseDir);
QCOMPARE(curBranch, QString("master"));
QString newBranch("new");
j = m_plugin->branch(gitTest_BaseDir, QString("master"), newBranch);
VcsRevision rev;
rev.setRevisionValue("master", KDevelop::VcsRevision::GlobalNumber);
j = m_plugin->branch(KUrl(gitTest_BaseDir), rev, newBranch);
VERIFYJOB(j);
QVERIFY(m_plugin->branches(gitTest_BaseDir).contains(newBranch));
QVERIFY(m_plugin->listBranches(KUrl(gitTest_BaseDir)).contains(newBranch));
j = m_plugin->switchBranch(gitTest_BaseDir, newBranch);
j = m_plugin->switchBranch(KUrl(gitTest_BaseDir), newBranch);
VERIFYJOB(j);
QCOMPARE(m_plugin->curBranch(gitTest_BaseDir), newBranch);
QCOMPARE(m_plugin->curBranch(KUrl(gitTest_BaseDir)), newBranch);
j = m_plugin->branch(gitTest_BaseDir, QString("master"), QString(), QStringList("-D"));
j = m_plugin->deleteBranch(KUrl(gitTest_BaseDir), "master");
VERIFYJOB(j);
QVERIFY(!m_plugin->branches(gitTest_BaseDir).contains(QString("master")));
QVERIFY(!m_plugin->listBranches(KUrl(gitTest_BaseDir)).contains("master"));
}
void GitInitTest::revHistory()
......
......@@ -219,6 +219,26 @@ KDevelop::DVcsJob* DistributedVersionControlPlugin::empty_cmd(KDevelop::OutputJo
return j;
}
QString DistributedVersionControlPlugin::curBranch(const KUrl& repo)
{
QString name;
QScopedPointer<VcsJob> job(currentBranch(repo));
if(job->exec() && job->status()==VcsJob::JobSucceeded) {
name = job->fetchResults().toString();
}
return name;
}
QStringList DistributedVersionControlPlugin::listBranches(const KUrl& repo)
{
QStringList branchlist;
QScopedPointer<VcsJob> job(branches(repo));
if(job->exec() && job->status()==VcsJob::JobSucceeded) {
branchlist = job->fetchResults().toStringList();
}
return branchlist;
}
}
//-----------------------------------------------------------------------------------
......
......@@ -27,14 +27,15 @@
#include <QtCore/QObject>
#include <vcs/interfaces/idistributedversioncontrol.h>
#include <interfaces/iuicontroller.h>
#include <interfaces/iplugin.h>
#include "dvcsevent.h"
#include <vcs/vcsexport.h>
#include <vcs/vcsstatusinfo.h>
#include <vcs/interfaces/idistributedversioncontrol.h>
#include <outputview/outputjob.h>
#include <vcs/interfaces/ibranchingversioncontrol.h>
class QMenu;
class QString;
......@@ -54,7 +55,7 @@ struct DistributedVersionControlPluginPrivate;
* from real DVCS plugins like Git. It is based on KDevelop's CVS plugin (also looks like svn plugin is it's relative too).
* @note Create only special items in contextMenuExtension, all standard menu items are created in vcscommon plugin!
*/
class KDEVPLATFORMVCS_EXPORT DistributedVersionControlPlugin : public IPlugin, public IDistributedVersionControl
class KDEVPLATFORMVCS_EXPORT DistributedVersionControlPlugin : public IPlugin, public IDistributedVersionControl, public IBranchingVersionControl
{
Q_OBJECT
Q_INTERFACES(KDevelop::IBasicVersionControl KDevelop::IDistributedVersionControl)
......@@ -83,22 +84,6 @@ public:
*/
virtual void parseLogOutput(const DVcsJob * job,
QList<DVcsEvent>& revisions) const = 0;
// In tree branch-management
virtual DVcsJob* switchBranch(const QString &repository, const QString &branch) = 0;
/** Branch. */
virtual DVcsJob* branch(const QString &repository, const QString &basebranch = QString(),
const QString &branch = QString(), const QStringList &args = QStringList()) = 0;
//parsers for branch:
/** Returns current branch. */
virtual QString curBranch(const QString &repository) = 0;
/** Returns the list of branches. */
virtual QStringList branches(const QString &repository) = 0;
// End: In tree branch-management
/** Returns the list of all commits (in all branches).
* @see CommitView and CommitViewDelegate to see how this list is used.
......@@ -119,6 +104,12 @@ public Q_SLOTS:
// slots for menu
void slotInit();
///synchronous currentBranch call
QString curBranch(const KUrl& repo);
///synchronous listBranches call
QStringList listBranches(const KUrl& repo);
Q_SIGNALS:
/**
......
......@@ -155,7 +155,7 @@ class BranchItem : public QStandardItem
i18n("Are you sure you want to rename \"%1\" to \"%2\"?", text(), newBranch));
if (ret == KMessageBox::Yes ) {
KDevelop::VcsJob *branchJob = bmodel->dvcsPlugin()->branch(bmodel->repository(), newBranch, text(), QStringList("-m"));
KDevelop::VcsJob *branchJob = bmodel->dvcsPlugin()->renameBranch(bmodel->repository(), newBranch, text());
bool ret = branchJob->exec();
kDebug() << "Renaming " << text() << " to " << newBranch << ':' << ret;
......@@ -168,10 +168,10 @@ class BranchItem : public QStandardItem
}
};
BranchesListModel::BranchesListModel(DistributedVersionControlPlugin* dvcsplugin, const QString& repo, QObject* parent)
BranchesListModel::BranchesListModel(DistributedVersionControlPlugin* dvcsplugin, const KUrl& repo, QObject* parent)
: QStandardItemModel(parent), dvcsplugin(dvcsplugin), repo(repo)
{
QStringList branches = dvcsplugin->branches(repo);
QStringList branches = dvcsplugin->listBranches(repo);
QString curBranch = dvcsplugin->curBranch(repo);
foreach(const QString& branch, branches)
......@@ -181,7 +181,9 @@ BranchesListModel::BranchesListModel(DistributedVersionControlPlugin* dvcsplugin
void BranchesListModel::createBranch(const QString& baseBranch, const QString& newBranch)
{
kDebug() << "Creating " << baseBranch << " based on " << newBranch;
KDevelop::VcsJob* branchJob = dvcsplugin->branch(repo, baseBranch, newBranch);
VcsRevision rev;
rev.setRevisionValue(baseBranch, KDevelop::VcsRevision::GlobalNumber);
KDevelop::VcsJob* branchJob = dvcsplugin->branch(repo, rev, newBranch);
kDebug() << "Adding new branch";
if (branchJob->exec())
......@@ -190,7 +192,7 @@ void BranchesListModel::createBranch(const QString& baseBranch, const QString& n
void BranchesListModel::removeBranch(const QString& branch)
{
KDevelop::VcsJob *branchJob = dvcsplugin->branch(repo, branch, QString(), QStringList("-D"));
KDevelop::VcsJob *branchJob = dvcsplugin->deleteBranch(KUrl(repo), branch);
kDebug() << "Removing branch:" << branch;
if (branchJob->exec()) {
......
......@@ -65,20 +65,20 @@ class BranchesListModel : public QStandardItemModel
{
Q_OBJECT
public:
BranchesListModel(KDevelop::DistributedVersionControlPlugin* dvcsplugin, const QString& repo, QObject* parent = 0);
BranchesListModel(KDevelop::DistributedVersionControlPlugin* dvcsplugin, const KUrl& repo, QObject* parent = 0);
void createBranch(const QString& baseBranch, const QString& newBranch);
void removeBranch(const QString& branch);
KDevelop::DistributedVersionControlPlugin* dvcsPlugin() const { return dvcsplugin; }
QString repository() const { return repo; }
KUrl repository() const { return repo; }
public slots:
void resetCurrent();
private:
KDevelop::DistributedVersionControlPlugin* dvcsplugin;
QString repo;
KUrl repo;
};
......
......@@ -22,31 +22,29 @@
#ifndef IBRANCHINGVERSIONCONTROL_H
#define IBRANCHINGVERSIONCONTROL_H
class KUrl;
class QString;
class VcsMapping;
class VcsRevision;
namespace KDevelop
{
class VcsRevision;
class VcsJob;
class IBranchingVersionControl
{
public:
virtual ~IBranchingVersionControl() {}
/**
* Creates a branch from the given mapping information
*
* @param mapping List of source/destination pairs of repository paths
* specifying what should end up where. Some VCS's may not support
* destination paths and will ignore them. The source paths always specify
* what is to be branched.
* @param repository repository directory on which we're going to branch
* @param rev What revision of the requested items should be branched.
* @param branchName Short, descriptive name for the branch used for VCS's
* that take branch names instead of destination paths, or store metadata
* about the branch. Not all VCS's will use this parameter.
*/
virtual VcsJob* branch( const QString& commitMessage,
const VcsMapping& mapping,
virtual VcsJob* branch( const KUrl& repository,
const VcsRevision& rev,
const QString& branchName ) = 0;
......@@ -54,19 +52,54 @@ public:
/**
* Creates a new tag from the given mapping information
*
* @param mapping List of source/destination pairs of repository paths
* specifying what should end up where. Some VCS's may not support
* destination paths and will ignore them. The source paths always specify
* what is to be tagged.
* @param rev What revision of the requested items should be tagged.
* @param tagName Short, descriptive name for the tag used for VCS's that
* take tag names instead of destination paths, or store metadata about the
* tag. Not all VCS's will use this parameter.
*/
virtual VcsJob* tag( const QString& commitMessage,
const VcsMapping& mapping,
virtual VcsJob* tag( const KUrl& repository,
const QString& commitMessage,
const VcsRevision& rev,
const QString& tagName ) = 0;
/**
* Switches to the desired branch inside the specified repository
*
* @param repository The repository path where the branch will be switched
* @param branchName The branch name that will be switched to inside the specified repostory
*/
virtual VcsJob* switchBranch(const KUrl &repository, const QString &branchName) = 0;
/**
* Returns the branches inside the specified repository in a QStringList
*
* @param repository The repository path where the branches will be returned from
*/
virtual VcsJob* branches(const KUrl &repository) = 0;
/**
* Returns the current branch name inside the specified repository
*
* @param repository The repository path where the current branch will be returned from
*/
virtual VcsJob* currentBranch(const KUrl &repository) = 0;
/**
* Deletes the desired branch inside the specified repository
*
* @param repository The repository path where the current branch will be deleted from
* @param branchName The branch name that will be deleted inside the specified repository
*/
virtual VcsJob* deleteBranch(const KUrl &repository, const QString &branchName) = 0;
/**
* Deletes the desired branch inside the specified repository
*
* @param repository The repository path where the current branch will be deleted from
* @param oldBranchName The branch name that will be renamed
* @param newBranchName The new branch name
*/
virtual VcsJob* renameBranch(const KUrl &repository, const QString &oldBranchName, const QString &newBranchName) = 0;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment