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 "svnstatusjob.h" 0008 #include "svnstatusjob_p.h" 0009 0010 #include <QMutexLocker> 0011 #include <QUrl> 0012 0013 #include <KLocalizedString> 0014 0015 extern "C" 0016 { 0017 #include <svn_wc.h> 0018 } 0019 0020 #include <iostream> 0021 0022 #include "kdevsvncpp/client.hpp" 0023 #include "kdevsvncpp/status.hpp" 0024 0025 KDevelop::VcsStatusInfo::State getState( const svn::Status& st ) 0026 { 0027 KDevelop::VcsStatusInfo::State state; 0028 if( st.isVersioned() ) 0029 { 0030 if( st.textStatus() == svn_wc_status_added ) 0031 { 0032 state = KDevelop::VcsStatusInfo::ItemAdded; 0033 }else if( st.textStatus() == svn_wc_status_modified 0034 || st.propStatus() == svn_wc_status_modified ) 0035 { 0036 state = KDevelop::VcsStatusInfo::ItemModified; 0037 }else if( st.textStatus() == svn_wc_status_deleted ) 0038 { 0039 state = KDevelop::VcsStatusInfo::ItemDeleted; 0040 }else if( st.textStatus() == svn_wc_status_conflicted 0041 || st.propStatus() == svn_wc_status_conflicted ) 0042 { 0043 state = KDevelop::VcsStatusInfo::ItemHasConflicts; 0044 }else 0045 { 0046 state = KDevelop::VcsStatusInfo::ItemUpToDate; 0047 } 0048 }else 0049 { 0050 state = KDevelop::VcsStatusInfo::ItemUnknown; 0051 } 0052 return state; 0053 } 0054 0055 SvnInternalStatusJob::SvnInternalStatusJob( SvnJobBase* parent ) 0056 : SvnInternalJobBase( parent ) 0057 { 0058 } 0059 0060 void SvnInternalStatusJob::setRecursive( bool recursive ) 0061 { 0062 QMutexLocker l( &m_mutex ); 0063 m_recursive = recursive; 0064 } 0065 0066 void SvnInternalStatusJob::setLocations( const QList<QUrl>& urls ) 0067 { 0068 QMutexLocker l( &m_mutex ); 0069 m_locations = urls; 0070 } 0071 0072 QList<QUrl> SvnInternalStatusJob::locations() const 0073 { 0074 QMutexLocker l( &m_mutex ); 0075 return m_locations; 0076 } 0077 bool SvnInternalStatusJob::recursive() const 0078 { 0079 QMutexLocker l( &m_mutex ); 0080 return m_recursive; 0081 } 0082 0083 void SvnInternalStatusJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*thread*/) 0084 { 0085 qCDebug(PLUGIN_SVN) << "Running internal status job with urls:" << m_locations; 0086 initBeforeRun(); 0087 0088 svn::Client cli(m_ctxt); 0089 const QList<QUrl> l = locations(); 0090 for (const QUrl& url : l) { 0091 //qCDebug(PLUGIN_SVN) << "Fetching status info for:" << url; 0092 try 0093 { 0094 QByteArray ba = url.toString( QUrl::PreferLocalFile | QUrl::StripTrailingSlash ).toUtf8(); 0095 const svn::StatusEntries se = cli.status(ba.data(), recursive()); 0096 for (auto& statusEntry : se) { 0097 KDevelop::VcsStatusInfo info; 0098 info.setUrl(QUrl::fromLocalFile(QString::fromUtf8(statusEntry.path()))); 0099 info.setState(getState(statusEntry)); 0100 emit gotNewStatus( info ); 0101 } 0102 }catch( const svn::ClientException& ce ) 0103 { 0104 qCDebug(PLUGIN_SVN) << "Couldn't get status: " << url << QString::fromUtf8( ce.message() ); 0105 setErrorMessage( QString::fromUtf8( ce.message() ) ); 0106 m_success = false; 0107 } 0108 } 0109 } 0110 0111 SvnStatusJob::SvnStatusJob( KDevSvnPlugin* parent ) 0112 : SvnJobBaseImpl( parent, KDevelop::OutputJob::Silent ) 0113 { 0114 setType( KDevelop::VcsJob::Status ); 0115 connect(m_job.data(), &SvnInternalStatusJob::gotNewStatus, 0116 this, &SvnStatusJob::addToStats, Qt::QueuedConnection); 0117 setObjectName(i18n("Subversion Status")); 0118 } 0119 0120 QVariant SvnStatusJob::fetchResults() 0121 { 0122 QList<QVariant> temp = m_stats; 0123 m_stats.clear(); 0124 return QVariant(temp); 0125 } 0126 0127 void SvnStatusJob::start() 0128 { 0129 if( m_job->locations().isEmpty() ) { 0130 internalJobFailed(); 0131 setErrorText( i18n( "Not enough information to execute status job" ) ); 0132 } else { 0133 qCDebug(PLUGIN_SVN) << "Starting status job"; 0134 startInternalJob(); 0135 } 0136 } 0137 0138 void SvnStatusJob::setLocations( const QList<QUrl>& urls ) 0139 { 0140 if( status() == KDevelop::VcsJob::JobNotStarted ) 0141 m_job->setLocations( urls ); 0142 } 0143 0144 void SvnStatusJob::setRecursive( bool recursive ) 0145 { 0146 if( status() == KDevelop::VcsJob::JobNotStarted ) 0147 m_job->setRecursive( recursive ); 0148 } 0149 0150 void SvnStatusJob::addToStats( const KDevelop::VcsStatusInfo& info ) 0151 { 0152 //qCDebug(PLUGIN_SVN) << "new status info:" << info.url() << info.state(); 0153 if (!m_stats.contains(QVariant::fromValue(info))) { 0154 m_stats << QVariant::fromValue(info); 0155 emit resultsReady( this ); 0156 }else 0157 { 0158 qCDebug(PLUGIN_SVN) << "Already have this info:"; 0159 } 0160 } 0161 0162 #include "moc_svnstatusjob_p.cpp" 0163 #include "moc_svnstatusjob.cpp"