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

Add diff feature to the git plugin hoping it makes it a little more useful.

PatchReview can't cope with the format I think, though...

There are some code style changes too
parent f4ea3cf7
......@@ -106,15 +106,15 @@ bool GitPlugin::isValidDirectory(const KUrl & dirPath)
return false;
}
job->exec();
job->exec();
if (job->status() == KDevelop::VcsJob::JobSucceeded) {
kDebug() << "Dir:" << dirPath << " is inside work tree of git (" << possibleRepoRoot << ')';
m_lastRepoRoot = possibleRepoRoot;
return true;
return true;
} else if (m_lastRepoRoot == possibleRepoRoot) { // Not a repository anymore
m_lastRepoRoot = KUrl(); // Restart from scratch
m_lastRepoRoot.clear(); // Restart from scratch
return isValidDirectory(dirPath);
}
}
return false;
}
......@@ -122,7 +122,7 @@ bool GitPlugin::isValidDirectory(const KUrl & dirPath)
bool GitPlugin::isVersionControlled(const KUrl &path)
{
QFileInfo fsObject(path.toLocalFile());
if (!fsObject.isFile()) {
if (fsObject.isDir()) {
return isValidDirectory(path);
}
......@@ -197,6 +197,38 @@ KDevelop::VcsJob* GitPlugin::status(const KUrl::List& localLocations,
return noOp;
}
VcsJob* GitPlugin::diff(const KUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision,
VcsDiff::Type type, IBasicVersionControl::RecursionMode recursion)
{
DVcsJob* job = new DVcsJob(this);
if (prepareJob(job, fileOrDirectory.toLocalFile()) ) {
KUrl::List files;
if(QFileInfo(fileOrDirectory.path()).isDir() && recursion==IBasicVersionControl::NonRecursive)
files = getLsFiles(fileOrDirectory.path());
else
files = fileOrDirectory;
*job << "git";
*job << "diff";
if(srcRevision.revisionType()==VcsRevision::GlobalNumber && dstRevision.revisionType()==VcsRevision::GlobalNumber)
*job << srcRevision.revisionValue().toString()+".."+dstRevision.revisionValue().toString();
else if(srcRevision.revisionType()==VcsRevision::GlobalNumber)
*job << srcRevision.revisionValue().toString()+"..HEAD";
else if(dstRevision.revisionType()==VcsRevision::GlobalNumber)
*job << "HEAD.."+dstRevision.revisionValue().toString();
*job << "--";
addFileList(job, files);
connect(job, SIGNAL(readyForParsing(DVcsJob*)), this, SLOT(parseGitDiffOutput(DVcsJob*)));
return job;
}
if (job)
delete job;
return 0;
}
//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,
......@@ -837,6 +869,11 @@ void GitPlugin::parseGitLogOutput(DVcsJob * job)
job->setResults(commits);
}
void GitPlugin::parseGitDiffOutput(DVcsJob* job)
{
job->setResults(job->output());
}
QStringList GitPlugin::getLsFiles(const QString &directory, const QStringList &args,
KDevelop::OutputJob::OutputJobVerbosity verbosity)
{
......
......@@ -68,6 +68,8 @@ public:
const KUrl::List& localLocations,
KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive);
virtual KDevelop::VcsJob* diff(const KUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision,
KDevelop::VcsDiff::Type, RecursionMode recursion);
using KDevelop::DistributedVersionControlPlugin::log;
KDevelop::VcsJob* log(const KUrl& localLocation,
......@@ -123,6 +125,7 @@ protected:
protected slots:
void parseGitBlameOutput(DVcsJob *job);
void parseGitLogOutput(DVcsJob *job);
void parseGitDiffOutput(DVcsJob* job);
private:
//commit dialog "main" helper
......
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