File indexing completed on 2024-05-05 04:41:00
0001 /* 0002 SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de> 0003 SPDX-FileCopyrightText: 2007 Dukju Ahn <dukjuahn@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "svncommitjob.h" 0009 #include "svncommitjob_p.h" 0010 0011 #include <QMutexLocker> 0012 0013 #include <ThreadWeaver/ThreadWeaver> 0014 #include <ThreadWeaver/Weaver> 0015 #include <QStandardItemModel> 0016 #include <KLocalizedString> 0017 0018 #include <vector> 0019 0020 #include "kdevsvncpp/client.hpp" 0021 #include "kdevsvncpp/path.hpp" 0022 #include "kdevsvncpp/targets.hpp" 0023 0024 #include <iostream> 0025 0026 #include "svninternaljobbase.h" 0027 #include "kdevsvnplugin.h" 0028 0029 SvnInternalCommitJob::SvnInternalCommitJob( SvnJobBase* parent ) 0030 : SvnInternalJobBase( parent ) 0031 { 0032 } 0033 0034 void SvnInternalCommitJob::setRecursive( bool recursive ) 0035 { 0036 QMutexLocker l( &m_mutex ); 0037 m_recursive = recursive; 0038 } 0039 0040 void SvnInternalCommitJob::setCommitMessage( const QString& msg ) 0041 { 0042 QMutexLocker l( &m_mutex ); 0043 m_commitMessage = msg; 0044 } 0045 0046 void SvnInternalCommitJob::setUrls( const QList<QUrl>& urls ) 0047 { 0048 QMutexLocker l( &m_mutex ); 0049 m_urls = urls; 0050 } 0051 0052 void SvnInternalCommitJob::setKeepLock( bool lock ) 0053 { 0054 QMutexLocker l( &m_mutex ); 0055 m_keepLock = lock; 0056 } 0057 0058 QList<QUrl> SvnInternalCommitJob::urls() const 0059 { 0060 QMutexLocker l( &m_mutex ); 0061 return m_urls; 0062 } 0063 0064 QString SvnInternalCommitJob::commitMessage() const 0065 { 0066 QMutexLocker l( &m_mutex ); 0067 return m_commitMessage; 0068 } 0069 0070 bool SvnInternalCommitJob::recursive() const 0071 { 0072 QMutexLocker l( &m_mutex ); 0073 return m_recursive; 0074 } 0075 0076 bool SvnInternalCommitJob::keepLock() const 0077 { 0078 QMutexLocker l( &m_mutex ); 0079 return m_keepLock; 0080 } 0081 0082 0083 void SvnInternalCommitJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*thread*/) 0084 { 0085 initBeforeRun(); 0086 svn::Client cli(m_ctxt); 0087 std::vector<svn::Path> targets; 0088 const QList<QUrl> l = urls(); 0089 for (const QUrl& u : l) { 0090 QByteArray path = u.toString( QUrl::PreferLocalFile | QUrl::StripTrailingSlash ).toUtf8(); 0091 targets.push_back( svn::Path( path.data() ) ); 0092 } 0093 QByteArray ba = commitMessage().toUtf8(); 0094 try 0095 { 0096 cli.commit( svn::Targets(targets), ba.data(), recursive(), keepLock() ); 0097 }catch( const svn::ClientException& ce ) 0098 { 0099 qCDebug(PLUGIN_SVN) << "Couldn't commit:" << QString::fromUtf8( ce.message() ); 0100 setErrorMessage( QString::fromUtf8( ce.message() ) ); 0101 m_success = false; 0102 } 0103 } 0104 0105 SvnCommitJob::SvnCommitJob( KDevSvnPlugin* parent ) 0106 : SvnJobBaseImpl(parent, KDevelop::OutputJob::Verbose ) 0107 { 0108 setType( KDevelop::VcsJob::Commit ); 0109 setObjectName(i18n("Subversion Commit")); 0110 } 0111 0112 QVariant SvnCommitJob::fetchResults() 0113 { 0114 return QVariant(); 0115 } 0116 0117 void SvnCommitJob::start() 0118 { 0119 setTitle(QStringLiteral("commit")); 0120 setBehaviours( KDevelop::IOutputView::AllowUserClose | KDevelop::IOutputView::AutoScroll ); 0121 startOutput(); 0122 0123 auto *m = qobject_cast<QStandardItemModel*>(model()); 0124 m->setColumnCount(1); 0125 m->appendRow(new QStandardItem(i18n("Committing..."))); 0126 0127 if( m_job->urls().isEmpty() ) { 0128 internalJobFailed(); 0129 setErrorText( i18n( "Not enough information to execute commit" ) ); 0130 m->appendRow(new QStandardItem(errorText())); 0131 } else { 0132 startInternalJob(); 0133 } 0134 } 0135 0136 void SvnCommitJob::setCommitMessage( const QString& msg ) 0137 { 0138 if( status() == KDevelop::VcsJob::JobNotStarted ) 0139 m_job->setCommitMessage( msg ); 0140 } 0141 0142 void SvnCommitJob::setKeepLock( bool keepLock ) 0143 { 0144 if( status() == KDevelop::VcsJob::JobNotStarted ) 0145 m_job->setKeepLock( keepLock ); 0146 } 0147 0148 void SvnCommitJob::setUrls( const QList<QUrl>& urls ) 0149 { 0150 qCDebug(PLUGIN_SVN) << "Setting urls?" << status() << urls; 0151 if( status() == KDevelop::VcsJob::JobNotStarted ) 0152 m_job->setUrls( urls ); 0153 } 0154 0155 void SvnCommitJob::setRecursive( bool recursive ) 0156 { 0157 if( status() == KDevelop::VcsJob::JobNotStarted ) 0158 m_job->setRecursive( recursive ); 0159 } 0160 0161 #include "moc_svncommitjob_p.cpp" 0162 #include "moc_svncommitjob.cpp"