Commit 320ba6bc authored by Evgeniy Ivanov's avatar Evgeniy Ivanov
Browse files

Commit Manager implementation (instead of simple commit dialog) for DVCS (+ git code)

Some minor fixes (dvcs:commit, dvcs:add/remove)
parent f4652711
......@@ -35,6 +35,8 @@
#include <vcs/dvcs/dvcsjob.h>
#include <interfaces/iplugin.h>
using KDevelop::VcsStatusInfo;
GitExecutor::GitExecutor(KDevelop::IPlugin* parent)
: QObject(parent), vcsplugin(parent)
{
......@@ -221,7 +223,7 @@ DVCSjob* GitExecutor::branch(const QString &repository, const QString &basebranc
*job << "git-branch";
//Empty branch has 'something' so it breaks the command
if (!args.isEmpty())
*job << args.join(" ");
*job << args;
if (!branch.isEmpty())
*job << branch;
if (!basebranch.isEmpty())
......@@ -232,6 +234,35 @@ DVCSjob* GitExecutor::branch(const QString &repository, const QString &basebranc
return NULL;
}
DVCSjob* GitExecutor::reset(const QString &repository, const QStringList &args, const QStringList files)
{
DVCSjob* job = new DVCSjob(vcsplugin);
if (prepareJob(job, repository) ) {
*job << "git-reset";
//Empty branch has 'something' so it breaks the command
if (!args.isEmpty())
*job << args;
addFileList(job, files);
return job;
}
if (job) delete job;
return NULL;
}
DVCSjob* GitExecutor::lsFiles(const QString &repository, const QStringList &args)
{
DVCSjob* job = new DVCSjob(vcsplugin);
if (prepareJob(job, repository) ) {
*job << "git-ls-files";
//Empty branch has 'something' so it breaks the command
if (!args.isEmpty())
*job << args;
return job;
}
if (job) delete job;
return NULL;
}
QString GitExecutor::curBranch(const QString &repository)
{
DVCSjob* job = branch(repository);
......@@ -239,8 +270,6 @@ QString GitExecutor::curBranch(const QString &repository)
{
kDebug() << "Getting branch list";
job->exec();
while (job->status() == KDevelop::VcsJob::JobRunning)
;
}
QString branch;
if (job->status() == KDevelop::VcsJob::JobSucceeded)
......@@ -259,11 +288,8 @@ QStringList GitExecutor::branches(const QString &repository)
{
kDebug() << "Getting branch list";
job->exec();
while (job->status() == KDevelop::VcsJob::JobRunning)
;
}
QStringList branchListDirty;
// branches<< "master" << "test" << "brrr" << "br2";
if (job->status() == KDevelop::VcsJob::JobSucceeded)
branchListDirty = job->output().split('\n');
else
......@@ -287,6 +313,76 @@ QStringList GitExecutor::branches(const QString &repository)
return branchList;
}
QStringList GitExecutor::getOtherFiles(const QString &directory)
{
return getLsFiles(directory, QStringList(QString("--others")) );
}
QList<VcsStatusInfo> GitExecutor::getModifiedFiles(const QString &directory)
{
DVCSjob* job = new DVCSjob(vcsplugin);
if (prepareJob(job, directory) )
*job << "git-diff-files";
if (job)
job->exec();
QStringList output;
if (job->status() == KDevelop::VcsJob::JobSucceeded)
output = job->output().split('\n');
else
return QList<VcsStatusInfo>();
QList<VcsStatusInfo> modifiedFiles;
foreach(QString line, output)
{
QChar stCh = line[97];
KUrl file(line.section('\t', 1).trimmed());
VcsStatusInfo status;
status.setUrl(file);
status.setState(charToState(stCh.toAscii() ) );
kDebug() << line[97] << " " << file.path();
modifiedFiles.append(status);
}
return modifiedFiles;
}
QList<VcsStatusInfo> GitExecutor::getCachedFiles(const QString &directory)
{
DVCSjob* job = new DVCSjob(vcsplugin);
if (prepareJob(job, directory) )
*job << "git-diff-index" << "--cached" << "HEAD";
if (job)
job->exec();
QStringList output;
if (job->status() == KDevelop::VcsJob::JobSucceeded)
output = job->output().split('\n');
else
return QList<VcsStatusInfo>();
QList<VcsStatusInfo> cachedFiles;
foreach(QString line, output)
{
QChar stCh = line[97];
KUrl file(line.section('\t', 1).trimmed());
VcsStatusInfo status;
status.setUrl(file);
status.setState(charToState(stCh.toAscii() ) );
kDebug() << line[97] << " " << file.path();
cachedFiles.append(status);
}
return cachedFiles;
}
//Actually we can just copy the outpuc without parsing. So it's a kind of draft for future
void GitExecutor::parseOutput(const QString& jobOutput, QList<DVCScommit>& commits) const
{
......@@ -319,4 +415,47 @@ void GitExecutor::parseOutput(const QString& jobOutput, QList<DVCScommit>& commi
}
}
QStringList GitExecutor::getLsFiles(const QString &directory, const QStringList &args)
{
DVCSjob* job = lsFiles(directory, args);
if (job)
{
job->exec();
if (job->status() == KDevelop::VcsJob::JobSucceeded)
return job->output().split('\n');
else
return QStringList();
}
return QStringList();
}
KDevelop::VcsStatusInfo::State GitExecutor::charToState(const char ch)
{
switch (ch)
{
case 'M':
{
return VcsStatusInfo::ItemModified;
break;
}
case 'A':
{
return VcsStatusInfo::ItemAdded;
break;
}
case 'D':
{
return VcsStatusInfo::ItemDeleted;
break;
}
//ToDo: hasConflicts
default:
{
return VcsStatusInfo::ItemUnknown;
break;
}
}
return VcsStatusInfo::ItemUnknown;
}
// #include "gitexetor.moc"
......@@ -37,6 +37,7 @@ class DVCSjob;
namespace KDevelop
{
class IPlugin;
class VcsStatusInfo;
}
/**
......@@ -89,13 +90,28 @@ public:
DVCSjob* checkout(const QString &repository, const QString &branch);
DVCSjob* branch(const QString &repository, const QString &basebranch = QString(), const QString &branch = QString(),
const QStringList &args = QStringList());
DVCSjob* reset(const QString &repository, const QStringList &args, const QStringList files);
private:
//it can be public, but it isn't required now
DVCSjob* lsFiles(const QString &repository, const QStringList &args);
public:
//parsers for branch:
QString curBranch(const QString &repository);
QStringList branches(const QString &repository);
//commit dialog helpers, send to main helper the arg for git-ls-files:
QList<KDevelop::VcsStatusInfo> getModifiedFiles(const QString &directory);
QList<KDevelop::VcsStatusInfo> getCachedFiles(const QString &directory);
QStringList getOtherFiles(const QString &directory);
void parseOutput(const QString& jobOutput, QList<DVCScommit>& commits) const;
private:
//commit dialog "main" helper
QStringList getLsFiles(const QString &directory, const QStringList &args);
KDevelop::VcsStatusInfo::State charToState(const char ch);
KDevelop::IPlugin* vcsplugin;
};
......
......@@ -121,9 +121,6 @@ void GitInitTest::addFiles()
if (j)
QVERIFY(j->exec() );
//Wait the job will be finished
while(j->status() == KDevelop::VcsJob::JobRunning)
;
// /tmp/kdevGit_testdir/ and testfile
j = m_proxy->add(QString(GITTEST_BASEDIR), KUrl::List(QStringList(QString(GIT_TESTFILE_NAME))));
......@@ -131,8 +128,6 @@ void GitInitTest::addFiles()
if (j)
QVERIFY(j->exec() );
while(j->status() == KDevelop::VcsJob::JobRunning)
;
//repository path without trailing slash
j = m_proxy->add(QString(GITTEST_BASEDIR_NO_TR_SLASH), KUrl::List(QStringList(QString(GIT_TESTFILE_NAME))));
......@@ -140,8 +135,6 @@ void GitInitTest::addFiles()
if (j)
QVERIFY(j->exec() );
while(j->status() == KDevelop::VcsJob::JobRunning)
;
f.setFileName(GIT_SRC_DIR""GIT_TESTFILE_NAME3);
if(f.open(QIODevice::WriteOnly)) {
......@@ -158,15 +151,33 @@ void GitInitTest::addFiles()
if (j)
QVERIFY(j->exec() );
while(j->status() == KDevelop::VcsJob::JobRunning)
;
//let's use absolute path, because it's used in ContextMenus
j = m_proxy->add(QString(GITTEST_BASEDIR), KUrl::List(QStringList(QString(GITTEST_BASEDIR""GIT_TESTFILE_NAME2))));
if (j)
QVERIFY(j->exec() );
while(j->status() == KDevelop::VcsJob::JobRunning)
;
//Now let's create several files and try "git add file1 file2 file3"
f.setFileName(GITTEST_BASEDIR"file1");
if(f.open(QIODevice::WriteOnly)) {
QTextStream input( &f );
input << "file1";
}
f.flush();
f.close();
f.setFileName(GITTEST_BASEDIR"file2");
if(f.open(QIODevice::WriteOnly)) {
QTextStream input( &f );
input << "file2";
}
f.flush();
f.close();
QStringList multipleFiles;
multipleFiles<<"file1";
multipleFiles<<"file2";
j = m_proxy->add(QString(GITTEST_BASEDIR), KUrl::List(multipleFiles));
if (j)
QVERIFY(j->exec() );
}
void GitInitTest::commitFiles()
......@@ -196,7 +207,7 @@ void GitInitTest::commitFiles()
*jobLs<<"git-ls-tree"<<"--name-only"<<"-r"<<"HEAD";
if (jobLs) {
QVERIFY(jobLs->exec() );
while(jobLs->status() == KDevelop::VcsJob::JobRunning) ;
QStringList files = jobLs->output().split("\n");
QVERIFY(files.contains(QString(GIT_TESTFILE_NAME)));
QVERIFY(files.contains(QString(GIT_TESTFILE_NAME2)));
......
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