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

0001 /*
0002     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "svnimportjob.h"
0008 #include "svnimportjob_p.h"
0009 
0010 #include <QMutexLocker>
0011 #include <QFileInfo>
0012 
0013 #include <KLocalizedString>
0014 
0015 #include "kdevsvncpp/client.hpp"
0016 #include "kdevsvncpp/path.hpp"
0017 
0018 #include <vcs/vcslocation.h>
0019 
0020 SvnImportInternalJob::SvnImportInternalJob(SvnJobBase* parent)
0021     : SvnInternalJobBase(parent)
0022 {
0023 }
0024 
0025 void SvnImportInternalJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*thread*/)
0026 {
0027     initBeforeRun();
0028 
0029     svn::Client cli(m_ctxt);
0030     try
0031     {
0032         QMutexLocker l( &m_mutex );
0033         QString srcdir = QFileInfo( m_sourceDirectory.toLocalFile() ).canonicalFilePath();
0034         QByteArray srcba = srcdir.toUtf8();
0035         QUrl dest = QUrl::fromUserInput( m_destinationRepository.repositoryServer() );
0036         QByteArray destba = dest.url(QUrl::NormalizePathSegments).toUtf8();
0037         QByteArray msg = m_message.toUtf8();
0038         qCDebug(PLUGIN_SVN) << "Importing" << srcba << "into" << destba;
0039         cli.import( svn::Path( srcba.data() ), destba.data(), msg.data(), true );
0040     }catch( const svn::ClientException& ce )
0041     {
0042         qCWarning(PLUGIN_SVN) << "Exception while importing: "
0043                 << m_sourceDirectory
0044                 << ce.message();
0045         setErrorMessage( QString::fromUtf8( ce.message() ) );
0046         m_success = false;
0047     }
0048 
0049     qDebug() << "finished";
0050 }
0051 
0052 bool SvnImportInternalJob::isValid() const
0053 {
0054     return !m_message.isEmpty() && m_sourceDirectory.isLocalFile() && QFileInfo::exists( m_sourceDirectory.toLocalFile() ) && !m_destinationRepository.repositoryServer().isEmpty();
0055 }
0056 
0057 QUrl SvnImportInternalJob::source() const
0058 {
0059     QMutexLocker l( &m_mutex );
0060     return m_sourceDirectory;
0061 }
0062 
0063 void SvnImportInternalJob::setMessage( const QString& message )
0064 {
0065     QMutexLocker l( &m_mutex );
0066     m_message = message;
0067 }
0068 
0069 void SvnImportInternalJob::setMapping( const QUrl &sourceDirectory, const KDevelop::VcsLocation & destinationRepository)
0070 {
0071     QMutexLocker l( &m_mutex );
0072     m_sourceDirectory = sourceDirectory;
0073     m_destinationRepository = destinationRepository;
0074 }
0075 
0076 QString SvnImportInternalJob::message() const
0077 {
0078     QMutexLocker l( &m_mutex );
0079     return m_message;
0080 }
0081 
0082 SvnImportJob::SvnImportJob( KDevSvnPlugin* parent )
0083     : SvnJobBaseImpl( parent, KDevelop::OutputJob::Silent )
0084 {
0085     setType( KDevelop::VcsJob::Import );
0086     setObjectName(i18n("Subversion Import"));
0087 }
0088 
0089 QVariant SvnImportJob::fetchResults()
0090 {
0091     return QVariant();
0092 }
0093 
0094 void SvnImportJob::start()
0095 {
0096     if( !m_job->isValid() )
0097     {
0098         internalJobFailed();
0099         setErrorText( i18n( "Not enough information to import" ) );
0100     }else
0101     {
0102         qCDebug(PLUGIN_SVN) << "importing:" << m_job->source();
0103         startInternalJob();
0104     }
0105 }
0106 
0107 void SvnImportJob::setMapping( const QUrl &sourceDirectory, const KDevelop::VcsLocation & destinationRepository)
0108 {
0109     if( status() == KDevelop::VcsJob::JobNotStarted )
0110         m_job->setMapping( sourceDirectory, destinationRepository);
0111 }
0112 
0113 void SvnImportJob::setMessage( const QString& msg )
0114 {
0115     if( status() == KDevelop::VcsJob::JobNotStarted )
0116         m_job->setMessage( msg );
0117 }
0118 
0119 #include "moc_svnimportjob.cpp"
0120 #include "moc_svnimportjob_p.cpp"