1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
/***************************************************************************
* This file is part of KDevelop *
* Copyright 2007 Andreas Pakulat <apaku@gmx.de> *
* *
* This program 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 program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "svnblamejob.h"
#include "svnblamejob_p.h"
#include <QMutexLocker>
#include <KLocalizedString>
#include "svnclient.h"
#include <QDateTime>
SvnInternalBlameJob::SvnInternalBlameJob( SvnJobBase* parent )
: SvnInternalJobBase( parent )
{
m_startRevision.setRevisionValue(QVariant::fromValue(KDevelop::VcsRevision::Start),
KDevelop::VcsRevision::Special );
m_endRevision.setRevisionValue(QVariant::fromValue(KDevelop::VcsRevision::Head),
KDevelop::VcsRevision::Special );
}
void SvnInternalBlameJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*thread*/)
{
initBeforeRun();
QByteArray ba = location().toString( QUrl::PreferLocalFile | QUrl::StripTrailingSlash ).toUtf8();
svn::Client cli(m_ctxt);
svn::AnnotatedFile* file;
try
{
file = cli.annotate( ba.data(),
createSvnCppRevisionFromVcsRevision( startRevision() ),
createSvnCppRevisionFromVcsRevision( endRevision() ) );
}catch( const svn::ClientException& ce )
{
qCDebug(PLUGIN_SVN) << "Exception while blaming file: "
<< location()
<< QString::fromUtf8( ce.message() );
setErrorMessage( QString::fromUtf8( ce.message() ) );
m_success = false;
return;
}
svn_revnum_t minrev = -1, maxrev = -1;
for (const auto& line : *file) {
const svn_revnum_t lineRevision = line.revision();
if (lineRevision < minrev || minrev == -1) {
minrev = lineRevision;
}
if (lineRevision > maxrev || maxrev == -1 ) {
maxrev = lineRevision;
}
}
QHash<svn_revnum_t,QString> commitMessages;
try
{
const svn::LogEntries* entries = cli.log( ba.data(), svn::Revision(minrev), svn::Revision(maxrev), false, false );
for (const auto& entry : *entries) {
commitMessages[entry.revision] = QString::fromUtf8(entry.message.c_str() );
}
}catch( const svn::ClientException& ce )
{
qCDebug(PLUGIN_SVN) << "Exception while fetching log messages for blame: "
<< location()
<< QString::fromUtf8( ce.message() );
setErrorMessage( QString::fromUtf8( ce.message() ) );
m_success = false;
}
for (const auto& svnLine : *file) {
KDevelop::VcsAnnotationLine line;
line.setAuthor(QString::fromUtf8(svnLine.author().c_str()));
line.setDate(QDateTime::fromString(QString::fromUtf8(svnLine.date().c_str()), Qt::ISODate));
line.setText(QString::fromUtf8(svnLine.line().c_str()));
KDevelop::VcsRevision rev;
rev.setRevisionValue(QVariant(qlonglong(svnLine.revision())), KDevelop::VcsRevision::GlobalNumber);
line.setRevision( rev );
line.setLineNumber(svnLine.lineNumber());
line.setCommitMessage(commitMessages[svnLine.revision()]);
emit blameLine( line );
}
}
void SvnInternalBlameJob::setLocation( const QUrl &url )
{
QMutexLocker l( &m_mutex );
m_location = url;
}
QUrl SvnInternalBlameJob::location() const
{
QMutexLocker l( &m_mutex );
return m_location;
}
KDevelop::VcsRevision SvnInternalBlameJob::startRevision() const
{
QMutexLocker l( &m_mutex );
return m_startRevision;
}
KDevelop::VcsRevision SvnInternalBlameJob::endRevision() const
{
QMutexLocker l( &m_mutex );
return m_endRevision;
}
void SvnInternalBlameJob::setStartRevision( const KDevelop::VcsRevision& rev )
{
QMutexLocker l( &m_mutex );
m_startRevision = rev;
}
void SvnInternalBlameJob::setEndRevision( const KDevelop::VcsRevision& rev )
{
QMutexLocker l( &m_mutex );
m_endRevision = rev;
}
SvnBlameJob::SvnBlameJob( KDevSvnPlugin* parent )
: SvnJobBaseImpl( parent, KDevelop::OutputJob::Silent )
{
setType( KDevelop::VcsJob::Annotate );
connect(m_job.data(), &SvnInternalBlameJob::blameLine,
this, &SvnBlameJob::blameLineReceived);
setObjectName(i18n("Subversion Annotate"));
}
QVariant SvnBlameJob::fetchResults()
{
QList<QVariant> results = m_annotations;
m_annotations.clear();
return results;
}
void SvnBlameJob::start()
{
if ( !m_job->location().isValid() ) {
internalJobFailed();
setErrorText( i18n( "Not enough information to blame location" ) );
} else {
qCDebug(PLUGIN_SVN) << "blaming url:" << m_job->location();
startInternalJob();
}
}
void SvnBlameJob::setLocation( const QUrl &url )
{
if( status() == KDevelop::VcsJob::JobNotStarted )
m_job->setLocation( url );
}
void SvnBlameJob::setStartRevision( const KDevelop::VcsRevision& rev )
{
if( status() == KDevelop::VcsJob::JobNotStarted )
m_job->setStartRevision( rev );
}
void SvnBlameJob::setEndRevision( const KDevelop::VcsRevision& rev )
{
if( status() == KDevelop::VcsJob::JobNotStarted )
m_job->setEndRevision( rev );
}
void SvnBlameJob::blameLineReceived( const KDevelop::VcsAnnotationLine& line )
{
m_annotations.append(QVariant::fromValue(line));
emit resultsReady( this );
}
|