File indexing completed on 2024-05-05 04:41:02

0001 /*
0002     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "svnrevertjob.h"
0008 #include "svnrevertjob_p.h"
0009 
0010 #include <QMutexLocker>
0011 
0012 #include <KLocalizedString>
0013 
0014 #include "kdevsvncpp/client.hpp"
0015 #include "kdevsvncpp/path.hpp"
0016 #include "kdevsvncpp/targets.hpp"
0017 
0018 SvnInternalRevertJob::SvnInternalRevertJob( SvnJobBase* parent )
0019     : SvnInternalJobBase( parent )
0020 {
0021 }
0022 
0023 void SvnInternalRevertJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*thread*/)
0024 {
0025     initBeforeRun();
0026 
0027     svn::Client cli(m_ctxt);
0028     std::vector<svn::Path> targets;
0029     const QList<QUrl> l = locations();
0030     for (const QUrl& url : l) {
0031         QByteArray ba = url.toString( QUrl::PreferLocalFile | QUrl::StripTrailingSlash ).toUtf8();
0032         targets.push_back( svn::Path( ba.data() ) );
0033     }
0034     try
0035     {
0036         cli.revert( svn::Targets( targets ), recursive() );
0037     }catch( const svn::ClientException& ce )
0038     {
0039         qCDebug(PLUGIN_SVN) << "Exception while reverting files: "
0040                 << m_locations
0041                 << QString::fromUtf8( ce.message() );
0042         setErrorMessage( QString::fromUtf8( ce.message() ) );
0043         m_success = false;
0044     }
0045 }
0046 
0047 void SvnInternalRevertJob::setRecursive( bool recursive )
0048 {
0049     QMutexLocker l( &m_mutex );
0050     m_recursive = recursive;
0051 }
0052 
0053 void SvnInternalRevertJob::setLocations( const QList<QUrl>& urls )
0054 {
0055     QMutexLocker l( &m_mutex );
0056     m_locations = urls;
0057 }
0058 
0059 QList<QUrl> SvnInternalRevertJob::locations() const
0060 {
0061     QMutexLocker l( &m_mutex );
0062     return m_locations;
0063 }
0064 bool SvnInternalRevertJob::recursive() const
0065 {
0066     QMutexLocker l( &m_mutex );
0067     return m_recursive;
0068 }
0069 
0070 SvnRevertJob::SvnRevertJob( KDevSvnPlugin* parent )
0071     : SvnJobBaseImpl( parent, KDevelop::OutputJob::Silent )
0072 {
0073     setType( KDevelop::VcsJob::Add );
0074     setObjectName(i18n("Subversion Revert"));
0075 }
0076 
0077 QVariant SvnRevertJob::fetchResults()
0078 {
0079     return QVariant();
0080 }
0081 
0082 void SvnRevertJob::start()
0083 {
0084     if (m_job->locations().isEmpty()) {
0085         internalJobFailed();
0086         setErrorText( i18n( "Not enough information to execute revert" ) );
0087     } else {
0088         startInternalJob();
0089     }
0090 }
0091 
0092 void SvnRevertJob::setLocations( const QList<QUrl>& urls )
0093 {
0094     if( status() == KDevelop::VcsJob::JobNotStarted )
0095         m_job->setLocations( urls );
0096 }
0097 
0098 void SvnRevertJob::setRecursive( bool recursive )
0099 {
0100     if( status() == KDevelop::VcsJob::JobNotStarted )
0101         m_job->setRecursive( recursive );
0102 }
0103 
0104 #include "moc_svnrevertjob.cpp"
0105 #include "moc_svnrevertjob_p.cpp"