Commit 0b4d926c authored by Hugo Parente Lima's avatar Hugo Parente Lima
Browse files

Added History command to the git plugin.

parent e2474c13
......@@ -35,6 +35,7 @@
#include <vcs/vcsjob.h>
#include <vcs/vcsrevision.h>
#include <vcs/vcsevent.h>
#include <vcs/dvcs/dvcsjob.h>
#include <shell/core.h>
#include <vcs/vcsannotation.h>
......@@ -248,22 +249,16 @@ VcsJob* GitPlugin::log(const KUrl& localLocation,
if (prepareJob(job, localLocation.toLocalFile()) ) {
*job << "git";
*job << "log";
*job << "--date=raw";
*job << "--";
addFileList(job, localLocation);
connect(job, SIGNAL(readyForParsing(DVcsJob*)), this, SLOT(parseGitLogOutput(DVcsJob*)));
return job;
}
if (job) delete job;
return NULL;
}
VcsJob* GitPlugin::log(const KUrl& localLocation,
const KDevelop::VcsRevision& rev,
const KDevelop::VcsRevision& limit)
{
Q_UNUSED(limit)
return log(localLocation, rev, 0);
}
KDevelop::VcsJob* GitPlugin::annotate(const KUrl &localLocation, const KDevelop::VcsRevision&) {
DVcsJob* job = new DVcsJob(this);
if (prepareJob(job, localLocation.toLocalFile()) ) {
......@@ -271,6 +266,7 @@ KDevelop::VcsJob* GitPlugin::annotate(const KUrl &localLocation, const KDevelop:
*job << "blame";
*job << "--root";
*job << "-t";
*job << "--";
addFileList(job, localLocation);
connect(job, SIGNAL(readyForParsing(DVcsJob*)), this, SLOT(parseGitBlameOutput(DVcsJob*)));
} else {
......@@ -793,6 +789,48 @@ void GitPlugin::parseLogOutput(const DVcsJob * job, QList<DVcsEvent>& commits) c
}
}
void GitPlugin::parseGitLogOutput(DVcsJob * job)
{
QList<QVariant> commits;
static QRegExp commitRegex( "^commit (\\w{8})\\w{32}" );
static QRegExp infoRegex( "^(\\w+):(.*)" );
QString contents = job->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));
} 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 == "Author") {
item.setAuthor(infoRegex.cap(2).trimmed());
} else if (cap1 == "Date") {
item.setDate(QDateTime::fromTime_t(infoRegex.cap(2).trimmed().split(' ')[0].toUInt()));
}
} else if (line.startsWith(" ")) {
message += line.remove(0, 4);
message += '\n';
}
}
item.setMessage(message.trimmed());
commits.append(QVariant::fromValue(item));
job->setResults(commits);
}
QStringList GitPlugin::getLsFiles(const QString &directory, const QStringList &args)
{
DVcsJob* job = lsFiles(directory, args);
......
......@@ -64,12 +64,12 @@ public:
KDevelop::VcsJob* commit(const QString& message,
const KUrl::List& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive);
using KDevelop::DistributedVersionControlPlugin::log;
KDevelop::VcsJob* log(const KUrl& localLocation,
const KDevelop::VcsRevision& rev,
unsigned long limit);
KDevelop::VcsJob* log(const KUrl& localLocation,
const KDevelop::VcsRevision& rev,
const KDevelop::VcsRevision& limit);
KDevelop::VcsJob* annotate(const KUrl &localLocation, const KDevelop::VcsRevision &rev);
// Begin: KDevelop::IDistributedVersionControl
......@@ -117,6 +117,8 @@ protected:
protected slots:
void parseGitBlameOutput(DVcsJob *job);
void parseGitLogOutput(DVcsJob *job);
private:
//commit dialog "main" helper
QStringList getLsFiles(const QString &directory, const QStringList &args = QStringList());
......
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