2009-02-25 09:15:00 +01:00
/**************************************************************************
2008-12-02 12:01:29 +01:00
* *
* * This file is part of Qt Creator
* *
2009-02-25 09:15:00 +01:00
* * Copyright ( c ) 2009 Nokia Corporation and / or its subsidiary ( - ies ) .
2008-12-02 12:01:29 +01:00
* *
2009-06-17 00:01:27 +10:00
* * Contact : Nokia Corporation ( qt - info @ nokia . com )
2008-12-02 12:01:29 +01:00
* *
2009-02-25 09:15:00 +01:00
* * Commercial Usage
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01:00
* * Licensees holding valid Qt Commercial licenses may use this file in
* * accordance with the Qt Commercial License Agreement provided with the
* * Software or , alternatively , in accordance with the terms contained in
* * a written agreement between you and Nokia .
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01:00
* * GNU Lesser General Public License Usage
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01:00
* * Alternatively , this file may be used under the terms of the GNU Lesser
* * General Public License version 2.1 as published by the Free Software
* * Foundation and appearing in the file LICENSE . LGPL included in the
* * packaging of this file . Please review the following information to
* * ensure the GNU Lesser General Public License version 2.1 requirements
* * will be met : http : //www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01:00
* * If you are unsure which license is appropriate for your use , please
2009-08-14 09:30:56 +02:00
* * contact the sales department at http : //qt.nokia.com/contact.
2008-12-02 12:01:29 +01:00
* *
2009-02-25 09:15:00 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
# include "subversionplugin.h"
# include "settingspage.h"
# include "subversioneditor.h"
# include "subversionsubmiteditor.h"
# include "subversionconstants.h"
# include "subversioncontrol.h"
2009-07-17 17:19:23 +02:00
# include "checkoutwizard.h"
2008-12-02 12:01:29 +01:00
# include <vcsbase/basevcseditorfactory.h>
# include <vcsbase/vcsbaseeditor.h>
# include <vcsbase/basevcssubmiteditorfactory.h>
2009-08-10 15:46:45 +02:00
# include <vcsbase/vcsbaseoutputwindow.h>
2008-12-02 12:01:29 +01:00
# include <utils/synchronousprocess.h>
2009-05-15 15:41:00 +02:00
# include <utils/parameteraction.h>
2008-12-02 12:01:29 +01:00
# include <coreplugin/icore.h>
# include <coreplugin/coreconstants.h>
# include <coreplugin/filemanager.h>
# include <coreplugin/messagemanager.h>
# include <coreplugin/mimedatabase.h>
# include <coreplugin/uniqueidmanager.h>
2009-01-13 13:39:31 +01:00
# include <coreplugin/actionmanager/actionmanager.h>
2008-12-02 12:01:29 +01:00
# include <coreplugin/editormanager/editormanager.h>
2008-12-09 15:25:01 +01:00
# include <utils/qtcassert.h>
2008-12-02 12:01:29 +01:00
# include <QtCore/QDebug>
2009-01-19 12:39:20 +01:00
# include <QtCore/QDir>
2008-12-02 12:01:29 +01:00
# include <QtCore/QFileInfo>
# include <QtCore/QTemporaryFile>
2009-01-19 12:39:20 +01:00
# include <QtCore/QTextCodec>
# include <QtCore/QtPlugin>
2008-12-02 12:01:29 +01:00
# include <QtGui/QAction>
2009-01-19 12:39:20 +01:00
# include <QtGui/QFileDialog>
# include <QtGui/QMainWindow>
2008-12-02 12:01:29 +01:00
# include <QtGui/QMenu>
# include <QtGui/QMessageBox>
2009-02-09 17:33:31 +01:00
# include <QtGui/QInputDialog>
# include <limits.h>
2008-12-02 12:01:29 +01:00
using namespace Subversion : : Internal ;
2009-07-14 17:20:20 +02:00
static const char * const CMD_ID_SUBVERSION_MENU = " Subversion.Menu " ;
static const char * const CMD_ID_ADD = " Subversion.Add " ;
static const char * const CMD_ID_DELETE_FILE = " Subversion.Delete " ;
static const char * const CMD_ID_REVERT = " Subversion.Revert " ;
static const char * const CMD_ID_SEPARATOR0 = " Subversion.Separator0 " ;
static const char * const CMD_ID_DIFF_PROJECT = " Subversion.DiffAll " ;
static const char * const CMD_ID_DIFF_CURRENT = " Subversion.DiffCurrent " ;
static const char * const CMD_ID_SEPARATOR1 = " Subversion.Separator1 " ;
static const char * const CMD_ID_COMMIT_ALL = " Subversion.CommitAll " ;
static const char * const CMD_ID_COMMIT_CURRENT = " Subversion.CommitCurrent " ;
static const char * const CMD_ID_SEPARATOR2 = " Subversion.Separator2 " ;
static const char * const CMD_ID_FILELOG_CURRENT = " Subversion.FilelogCurrent " ;
static const char * const CMD_ID_ANNOTATE_CURRENT = " Subversion.AnnotateCurrent " ;
static const char * const CMD_ID_SEPARATOR3 = " Subversion.Separator3 " ;
2010-01-07 11:33:30 +01:00
static const char * const CMD_ID_SEPARATOR4 = " Subversion.Separator4 " ;
2009-07-14 17:20:20 +02:00
static const char * const CMD_ID_STATUS = " Subversion.Status " ;
2010-01-07 11:33:30 +01:00
static const char * const CMD_ID_PROJECTLOG = " Subversion.ProjectLog " ;
static const char * const CMD_ID_REPOSITORYLOG = " Subversion.RepositoryLog " ;
2009-07-14 17:20:20 +02:00
static const char * const CMD_ID_UPDATE = " Subversion.Update " ;
static const char * const CMD_ID_DESCRIBE = " Subversion.Describe " ;
2008-12-02 12:01:29 +01:00
2009-05-05 10:16:09 +02:00
static const char * nonInteractiveOptionC = " --non-interactive " ;
2008-12-02 12:01:29 +01:00
static const VCSBase : : VCSBaseEditorParameters editorParameters [ ] = {
{
VCSBase : : RegularCommandOutput ,
2010-01-08 09:48:54 +01:00
" Subversion Command Log Editor " , // id
QT_TRANSLATE_NOOP ( " VCS " , " Subversion Command Log Editor " ) , // display name
2009-02-16 12:50:15 +01:00
" Subversion Command Log Editor " , // context
2008-12-02 12:01:29 +01:00
" application/vnd.nokia.text.scs_svn_commandlog " ,
" scslog " } ,
{ VCSBase : : LogOutput ,
2010-01-08 09:48:54 +01:00
" Subversion File Log Editor " , // id
QT_TRANSLATE_NOOP ( " VCS " , " Subversion File Log Editor " ) , // display_name
2009-02-16 12:50:15 +01:00
" Subversion File Log Editor " , // context
2008-12-02 12:01:29 +01:00
" application/vnd.nokia.text.scs_svn_filelog " ,
" scsfilelog " } ,
{ VCSBase : : AnnotateOutput ,
2010-01-08 09:48:54 +01:00
" Subversion Annotation Editor " , // id
QT_TRANSLATE_NOOP ( " VCS " , " Subversion Annotation Editor " ) , // display_name
2009-02-16 12:50:15 +01:00
" Subversion Annotation Editor " , // context
2008-12-02 12:01:29 +01:00
" application/vnd.nokia.text.scs_svn_annotation " ,
" scsannotate " } ,
{ VCSBase : : DiffOutput ,
2010-01-08 09:48:54 +01:00
" Subversion Diff Editor " , // id
QT_TRANSLATE_NOOP ( " VCS " , " Subversion Diff Editor " ) , // display_name
2009-02-16 12:50:15 +01:00
" Subversion Diff Editor " , // context
2008-12-02 12:01:29 +01:00
" text/x-patch " , " diff " }
} ;
// Utility to find a parameter set by type
static inline const VCSBase : : VCSBaseEditorParameters * findType ( int ie )
{
const VCSBase : : EditorContentType et = static_cast < VCSBase : : EditorContentType > ( ie ) ;
return VCSBase : : VCSBaseEditor : : findType ( editorParameters , sizeof ( editorParameters ) / sizeof ( VCSBase : : VCSBaseEditorParameters ) , et ) ;
}
static inline QString debugCodec ( const QTextCodec * c )
{
return c ? QString : : fromAscii ( c - > name ( ) ) : QString : : fromAscii ( " Null codec " ) ;
}
2009-01-20 17:14:00 +01:00
Core : : IEditor * locateEditor ( const char * property , const QString & entry )
2008-12-02 12:01:29 +01:00
{
2009-01-21 15:52:34 +01:00
foreach ( Core : : IEditor * ed , Core : : EditorManager : : instance ( ) - > openedEditors ( ) )
2008-12-02 12:01:29 +01:00
if ( ed - > property ( property ) . toString ( ) = = entry )
return ed ;
return 0 ;
}
2009-01-12 17:44:04 +01:00
// Parse "svn status" output for added/modified/deleted files
// "M<7blanks>file"
typedef QList < SubversionSubmitEditor : : StatusFilePair > StatusList ;
StatusList parseStatusOutput ( const QString & output )
{
StatusList changeSet ;
const QString newLine = QString ( QLatin1Char ( ' \n ' ) ) ;
const QStringList list = output . split ( newLine , QString : : SkipEmptyParts ) ;
foreach ( const QString & l , list ) {
const QString line = l . trimmed ( ) ;
if ( line . size ( ) > 8 ) {
const QChar state = line . at ( 0 ) ;
if ( state = = QLatin1Char ( ' A ' ) | | state = = QLatin1Char ( ' D ' ) | | state = = QLatin1Char ( ' M ' ) ) {
2009-04-03 12:17:33 +02:00
const QString fileName = line . mid ( 7 ) ; // Column 8 starting from svn 1.6
changeSet . push_back ( SubversionSubmitEditor : : StatusFilePair ( QString ( state ) , fileName . trimmed ( ) ) ) ;
2009-01-12 17:44:04 +01:00
}
}
}
return changeSet ;
}
2009-05-26 12:25:32 +02:00
// Return a list of names for the internal svn directories
static inline QStringList svnDirectories ( )
{
QStringList rc ( QLatin1String ( " .svn " ) ) ;
# ifdef Q_OS_WIN
// Option on Windows systems to avoid hassle with some IDEs
rc . push_back ( QLatin1String ( " _svn " ) ) ;
# endif
return rc ;
}
2008-12-02 12:01:29 +01:00
// ------------- SubversionPlugin
SubversionPlugin * SubversionPlugin : : m_subversionPluginInstance = 0 ;
SubversionPlugin : : SubversionPlugin ( ) :
2010-01-08 09:48:54 +01:00
VCSBase : : VCSBasePlugin ( QLatin1String ( Subversion : : Constants : : SUBVERSIONCOMMITEDITOR_ID ) ) ,
2009-05-26 12:25:32 +02:00
m_svnDirectories ( svnDirectories ( ) ) ,
2008-12-02 12:01:29 +01:00
m_addAction ( 0 ) ,
m_deleteAction ( 0 ) ,
m_revertAction ( 0 ) ,
m_diffProjectAction ( 0 ) ,
m_diffCurrentAction ( 0 ) ,
2010-01-07 11:33:30 +01:00
m_logProjectAction ( 0 ) ,
m_logRepositoryAction ( 0 ) ,
2008-12-02 12:01:29 +01:00
m_commitAllAction ( 0 ) ,
m_commitCurrentAction ( 0 ) ,
m_filelogCurrentAction ( 0 ) ,
m_annotateCurrentAction ( 0 ) ,
2009-12-08 16:50:27 +01:00
m_statusProjectAction ( 0 ) ,
2008-12-02 12:01:29 +01:00
m_updateProjectAction ( 0 ) ,
2009-02-09 17:33:31 +01:00
m_describeAction ( 0 ) ,
2008-12-02 12:01:29 +01:00
m_submitCurrentLogAction ( 0 ) ,
m_submitDiffAction ( 0 ) ,
m_submitUndoAction ( 0 ) ,
2009-03-20 10:16:18 +01:00
m_submitRedoAction ( 0 ) ,
2009-12-08 14:26:41 +01:00
m_menuAction ( 0 ) ,
2009-03-20 10:16:18 +01:00
m_submitActionTriggered ( false )
2008-12-02 12:01:29 +01:00
{
}
SubversionPlugin : : ~ SubversionPlugin ( )
{
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2008-12-02 12:01:29 +01:00
}
2009-09-22 12:23:44 +02:00
void SubversionPlugin : : cleanCommitMessageFile ( )
2008-12-02 12:01:29 +01:00
{
2009-09-22 12:23:44 +02:00
if ( ! m_commitMessageFileName . isEmpty ( ) ) {
QFile : : remove ( m_commitMessageFileName ) ;
m_commitMessageFileName . clear ( ) ;
2009-12-08 16:50:27 +01:00
m_commitRepository . clear ( ) ;
2008-12-02 12:01:29 +01:00
}
}
2009-09-22 12:23:44 +02:00
bool SubversionPlugin : : isCommitEditorOpen ( ) const
{
return ! m_commitMessageFileName . isEmpty ( ) ;
}
2008-12-02 12:01:29 +01:00
static const VCSBase : : VCSBaseSubmitEditorParameters submitParameters = {
Subversion : : Constants : : SUBVERSION_SUBMIT_MIMETYPE ,
2010-01-08 09:48:54 +01:00
Subversion : : Constants : : SUBVERSIONCOMMITEDITOR_ID ,
Subversion : : Constants : : SUBVERSIONCOMMITEDITOR_DISPLAY_NAME ,
2009-01-13 14:06:42 +01:00
Subversion : : Constants : : SUBVERSIONCOMMITEDITOR
2008-12-02 12:01:29 +01:00
} ;
2009-02-09 17:33:31 +01:00
static inline Core : : Command * createSeparator ( QObject * parent ,
Core : : ActionManager * ami ,
const char * id ,
const QList < int > & globalcontext )
{
QAction * tmpaction = new QAction ( parent ) ;
tmpaction - > setSeparator ( true ) ;
return ami - > registerAction ( tmpaction , id , globalcontext ) ;
}
2009-12-08 14:26:41 +01:00
bool SubversionPlugin : : initialize ( const QStringList & /*arguments */ , QString * errorMessage )
2008-12-02 12:01:29 +01:00
{
typedef VCSBase : : VCSSubmitEditorFactory < SubversionSubmitEditor > SubversionSubmitEditorFactory ;
typedef VCSBase : : VCSEditorFactory < SubversionEditor > SubversionEditorFactory ;
using namespace Constants ;
using namespace Core : : Constants ;
using namespace ExtensionSystem ;
2009-12-08 14:26:41 +01:00
VCSBase : : VCSBasePlugin : : initialize ( new SubversionControl ( this ) ) ;
2008-12-02 12:01:29 +01:00
m_subversionPluginInstance = this ;
2009-01-20 17:14:00 +01:00
Core : : ICore * core = Core : : ICore : : instance ( ) ;
2008-12-02 12:01:29 +01:00
2009-01-20 17:14:00 +01:00
if ( ! core - > mimeDatabase ( ) - > addMimeTypes ( QLatin1String ( " :/trolltech.subversion/Subversion.mimetypes.xml " ) , errorMessage ) )
2008-12-02 12:01:29 +01:00
return false ;
2009-01-20 17:14:00 +01:00
if ( QSettings * settings = core - > settings ( ) )
2008-12-02 12:01:29 +01:00
m_settings . fromSettings ( settings ) ;
2009-07-14 17:20:20 +02:00
addAutoReleasedObject ( new SettingsPage ) ;
2008-12-02 12:01:29 +01:00
2009-07-14 17:20:20 +02:00
addAutoReleasedObject ( new SubversionSubmitEditorFactory ( & submitParameters ) ) ;
2008-12-02 12:01:29 +01:00
static const char * describeSlot = SLOT ( describe ( QString , QString ) ) ;
const int editorCount = sizeof ( editorParameters ) / sizeof ( VCSBase : : VCSBaseEditorParameters ) ;
2009-07-14 17:20:20 +02:00
for ( int i = 0 ; i < editorCount ; i + + )
addAutoReleasedObject ( new SubversionEditorFactory ( editorParameters + i , this , describeSlot ) ) ;
2008-12-02 12:01:29 +01:00
2009-07-17 17:19:23 +02:00
addAutoReleasedObject ( new CheckoutWizard ) ;
2008-12-02 12:01:29 +01:00
//register actions
2009-01-20 17:14:00 +01:00
Core : : ActionManager * ami = core - > actionManager ( ) ;
2009-01-14 12:39:59 +01:00
Core : : ActionContainer * toolsContainer = ami - > actionContainer ( M_TOOLS ) ;
2008-12-02 12:01:29 +01:00
2009-01-14 12:39:59 +01:00
Core : : ActionContainer * subversionMenu =
2009-07-14 17:20:20 +02:00
ami - > createMenu ( QLatin1String ( CMD_ID_SUBVERSION_MENU ) ) ;
2008-12-02 12:01:29 +01:00
subversionMenu - > menu ( ) - > setTitle ( tr ( " &Subversion " ) ) ;
toolsContainer - > addMenu ( subversionMenu ) ;
2009-12-08 14:26:41 +01:00
m_menuAction = subversionMenu - > menu ( ) - > menuAction ( ) ;
2008-12-02 12:01:29 +01:00
QList < int > globalcontext ;
2009-01-20 17:14:00 +01:00
globalcontext < < core - > uniqueIDManager ( ) - > uniqueIdentifier ( C_GLOBAL ) ;
2008-12-02 12:01:29 +01:00
2009-01-14 13:17:53 +01:00
Core : : Command * command ;
2009-10-05 11:06:05 +02:00
m_addAction = new Utils : : ParameterAction ( tr ( " Add " ) , tr ( " Add \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-14 17:20:20 +02:00
command = ami - > registerAction ( m_addAction , CMD_ID_ADD ,
2008-12-02 12:01:29 +01:00
globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+S,Alt+A " ) ) ) ;
connect ( m_addAction , SIGNAL ( triggered ( ) ) , this , SLOT ( addCurrentFile ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2010-01-11 15:22:17 +01:00
m_deleteAction = new Utils : : ParameterAction ( tr ( " Delete... " ) , tr ( " Delete \" %1 \" ... " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-14 17:20:20 +02:00
command = ami - > registerAction ( m_deleteAction , CMD_ID_DELETE_FILE ,
2008-12-02 12:01:29 +01:00
globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2010-01-11 15:22:17 +01:00
connect ( m_deleteAction , SIGNAL ( triggered ( ) ) , this , SLOT ( promptToDeleteCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
subversionMenu - > addAction ( command ) ;
2010-01-11 15:22:17 +01:00
m_revertAction = new Utils : : ParameterAction ( tr ( " Revert... " ) , tr ( " Revert \" %1 \" ... " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-14 17:20:20 +02:00
command = ami - > registerAction ( m_revertAction , CMD_ID_REVERT ,
2008-12-02 12:01:29 +01:00
globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
connect ( m_revertAction , SIGNAL ( triggered ( ) ) , this , SLOT ( revertCurrentFile ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2009-07-14 17:20:20 +02:00
subversionMenu - > addAction ( createSeparator ( this , ami , CMD_ID_SEPARATOR0 , globalcontext ) ) ;
2008-12-02 12:01:29 +01:00
2009-12-08 16:50:27 +01:00
m_diffProjectAction = new Utils : : ParameterAction ( tr ( " Diff Project " ) , tr ( " Diff Project \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-14 17:20:20 +02:00
command = ami - > registerAction ( m_diffProjectAction , CMD_ID_DIFF_PROJECT ,
2008-12-02 12:01:29 +01:00
globalcontext ) ;
2009-12-08 16:50:27 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
connect ( m_diffProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffProject ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2009-10-05 11:06:05 +02:00
m_diffCurrentAction = new Utils : : ParameterAction ( tr ( " Diff Current File " ) , tr ( " Diff \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2008-12-02 12:01:29 +01:00
command = ami - > registerAction ( m_diffCurrentAction ,
2009-07-14 17:20:20 +02:00
CMD_ID_DIFF_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+S,Alt+D " ) ) ) ;
connect ( m_diffCurrentAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffCurrentFile ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2009-07-14 17:20:20 +02:00
subversionMenu - > addAction ( createSeparator ( this , ami , CMD_ID_SEPARATOR1 , globalcontext ) ) ;
2008-12-02 12:01:29 +01:00
m_commitAllAction = new QAction ( tr ( " Commit All Files " ) , this ) ;
2009-07-14 17:20:20 +02:00
command = ami - > registerAction ( m_commitAllAction , CMD_ID_COMMIT_ALL ,
2008-12-02 12:01:29 +01:00
globalcontext ) ;
connect ( m_commitAllAction , SIGNAL ( triggered ( ) ) , this , SLOT ( startCommitAll ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2009-10-05 11:06:05 +02:00
m_commitCurrentAction = new Utils : : ParameterAction ( tr ( " Commit Current File " ) , tr ( " Commit \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2008-12-02 12:01:29 +01:00
command = ami - > registerAction ( m_commitCurrentAction ,
2009-07-14 17:20:20 +02:00
CMD_ID_COMMIT_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+S,Alt+C " ) ) ) ;
connect ( m_commitCurrentAction , SIGNAL ( triggered ( ) ) , this , SLOT ( startCommitCurrentFile ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2009-07-14 17:20:20 +02:00
subversionMenu - > addAction ( createSeparator ( this , ami , CMD_ID_SEPARATOR2 , globalcontext ) ) ;
2008-12-02 12:01:29 +01:00
2009-10-05 11:06:05 +02:00
m_filelogCurrentAction = new Utils : : ParameterAction ( tr ( " Filelog Current File " ) , tr ( " Filelog \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2008-12-02 12:01:29 +01:00
command = ami - > registerAction ( m_filelogCurrentAction ,
2009-07-14 17:20:20 +02:00
CMD_ID_FILELOG_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
connect ( m_filelogCurrentAction , SIGNAL ( triggered ( ) ) , this ,
SLOT ( filelogCurrentFile ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2009-10-05 11:06:05 +02:00
m_annotateCurrentAction = new Utils : : ParameterAction ( tr ( " Annotate Current File " ) , tr ( " Annotate \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2008-12-02 12:01:29 +01:00
command = ami - > registerAction ( m_annotateCurrentAction ,
2009-07-14 17:20:20 +02:00
CMD_ID_ANNOTATE_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
connect ( m_annotateCurrentAction , SIGNAL ( triggered ( ) ) , this ,
SLOT ( annotateCurrentFile ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2009-02-09 17:33:31 +01:00
m_describeAction = new QAction ( tr ( " Describe... " ) , this ) ;
2009-07-14 17:20:20 +02:00
command = ami - > registerAction ( m_describeAction , CMD_ID_DESCRIBE , globalcontext ) ;
2009-02-09 17:33:31 +01:00
connect ( m_describeAction , SIGNAL ( triggered ( ) ) , this , SLOT ( slotDescribe ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2009-07-14 17:20:20 +02:00
subversionMenu - > addAction ( createSeparator ( this , ami , CMD_ID_SEPARATOR3 , globalcontext ) ) ;
2008-12-02 12:01:29 +01:00
2009-12-08 16:50:27 +01:00
m_statusProjectAction = new Utils : : ParameterAction ( tr ( " Project Status " ) , tr ( " Status of Project \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_statusProjectAction , CMD_ID_STATUS ,
2008-12-02 12:01:29 +01:00
globalcontext ) ;
2009-12-08 16:50:27 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
connect ( m_statusProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( projectStatus ( ) ) ) ;
2008-12-02 12:01:29 +01:00
subversionMenu - > addAction ( command ) ;
2010-01-07 11:33:30 +01:00
m_logProjectAction = new Utils : : ParameterAction ( tr ( " Log Project Log " ) , tr ( " Log Project \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_logProjectAction , CMD_ID_PROJECTLOG , globalcontext ) ;
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
connect ( m_logProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( logProject ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2009-12-08 16:50:27 +01:00
m_updateProjectAction = new Utils : : ParameterAction ( tr ( " Update Project " ) , tr ( " Update Project \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2009-07-14 17:20:20 +02:00
command = ami - > registerAction ( m_updateProjectAction , CMD_ID_UPDATE , globalcontext ) ;
2008-12-02 12:01:29 +01:00
connect ( m_updateProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( updateProject ( ) ) ) ;
2009-12-08 16:50:27 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
subversionMenu - > addAction ( command ) ;
2010-01-07 11:33:30 +01:00
subversionMenu - > addAction ( createSeparator ( this , ami , CMD_ID_SEPARATOR4 , globalcontext ) ) ;
m_logRepositoryAction = new QAction ( tr ( " Repository Log " ) , this ) ;
command = ami - > registerAction ( m_logRepositoryAction , CMD_ID_REPOSITORYLOG , globalcontext ) ;
connect ( m_logRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( logRepository ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2008-12-02 12:01:29 +01:00
// Actions of the submit editor
QList < int > svncommitcontext ;
2009-01-21 15:52:34 +01:00
svncommitcontext < < Core : : UniqueIDManager : : instance ( ) - > uniqueIdentifier ( Constants : : SUBVERSIONCOMMITEDITOR ) ;
2008-12-02 12:01:29 +01:00
2008-12-02 17:05:53 +01:00
m_submitCurrentLogAction = new QAction ( VCSBase : : VCSBaseSubmitEditor : : submitIcon ( ) , tr ( " Commit " ) , this ) ;
2008-12-02 12:01:29 +01:00
command = ami - > registerAction ( m_submitCurrentLogAction , Constants : : SUBMIT_CURRENT , svncommitcontext ) ;
connect ( m_submitCurrentLogAction , SIGNAL ( triggered ( ) ) , this , SLOT ( submitCurrentLog ( ) ) ) ;
2008-12-02 17:05:53 +01:00
m_submitDiffAction = new QAction ( VCSBase : : VCSBaseSubmitEditor : : diffIcon ( ) , tr ( " Diff Selected Files " ) , this ) ;
2008-12-02 12:01:29 +01:00
command = ami - > registerAction ( m_submitDiffAction , Constants : : DIFF_SELECTED , svncommitcontext ) ;
m_submitUndoAction = new QAction ( tr ( " &Undo " ) , this ) ;
command = ami - > registerAction ( m_submitUndoAction , Core : : Constants : : UNDO , svncommitcontext ) ;
m_submitRedoAction = new QAction ( tr ( " &Redo " ) , this ) ;
command = ami - > registerAction ( m_submitRedoAction , Core : : Constants : : REDO , svncommitcontext ) ;
return true ;
}
void SubversionPlugin : : extensionsInitialized ( )
{
}
2009-12-08 14:26:41 +01:00
bool SubversionPlugin : : submitEditorAboutToClose ( VCSBase : : VCSBaseSubmitEditor * submitEditor )
2008-12-02 12:01:29 +01:00
{
2009-12-08 14:26:41 +01:00
if ( ! isCommitEditorOpen ( ) )
2008-12-02 12:01:29 +01:00
return true ;
2009-12-08 14:26:41 +01:00
Core : : IFile * fileIFace = submitEditor - > file ( ) ;
const SubversionSubmitEditor * editor = qobject_cast < SubversionSubmitEditor * > ( submitEditor ) ;
2008-12-02 12:01:29 +01:00
if ( ! fileIFace | | ! editor )
return true ;
// Submit editor closing. Make it write out the commit message
// and retrieve files
const QFileInfo editorFile ( fileIFace - > fileName ( ) ) ;
2009-09-22 12:23:44 +02:00
const QFileInfo changeFile ( m_commitMessageFileName ) ;
2008-12-02 12:01:29 +01:00
if ( editorFile . absoluteFilePath ( ) ! = changeFile . absoluteFilePath ( ) )
return true ; // Oops?!
2009-03-20 10:16:18 +01:00
// Prompt user. Force a prompt unless submit was actually invoked (that
// is, the editor was closed or shutdown).
2009-06-19 16:34:38 +02:00
SubversionSettings newSettings = m_settings ;
2009-03-19 17:40:01 +01:00
const VCSBase : : VCSBaseSubmitEditor : : PromptSubmitResult answer =
editor - > promptSubmit ( tr ( " Closing Subversion Editor " ) ,
tr ( " Do you want to commit the change? " ) ,
2009-03-20 10:16:18 +01:00
tr ( " The commit message check failed. Do you want to commit the change? " ) ,
2009-06-19 16:34:38 +02:00
& newSettings . promptToSubmit , ! m_submitActionTriggered ) ;
2009-03-20 10:16:18 +01:00
m_submitActionTriggered = false ;
2008-12-02 12:01:29 +01:00
switch ( answer ) {
2009-03-19 17:40:01 +01:00
case VCSBase : : VCSBaseSubmitEditor : : SubmitCanceled :
2008-12-02 12:01:29 +01:00
return false ; // Keep editing and change file
2009-03-19 17:40:01 +01:00
case VCSBase : : VCSBaseSubmitEditor : : SubmitDiscarded :
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2008-12-02 12:01:29 +01:00
return true ; // Cancel all
default :
break ;
}
2009-06-19 16:34:38 +02:00
setSettings ( newSettings ) ; // in case someone turned prompting off
2008-12-02 12:01:29 +01:00
const QStringList fileList = editor - > checkedFiles ( ) ;
2009-03-20 16:52:22 +01:00
bool closeEditor = true ;
2008-12-02 12:01:29 +01:00
if ( ! fileList . empty ( ) ) {
// get message & commit
2009-01-20 17:14:00 +01:00
Core : : ICore : : instance ( ) - > fileManager ( ) - > blockFileChange ( fileIFace ) ;
2008-12-02 12:01:29 +01:00
fileIFace - > save ( ) ;
2009-01-20 17:14:00 +01:00
Core : : ICore : : instance ( ) - > fileManager ( ) - > unblockFileChange ( fileIFace ) ;
2009-09-22 12:23:44 +02:00
closeEditor = commit ( m_commitMessageFileName , fileList ) ;
2008-12-02 12:01:29 +01:00
}
2009-03-20 16:52:22 +01:00
if ( closeEditor )
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2009-03-20 16:52:22 +01:00
return closeEditor ;
2008-12-02 12:01:29 +01:00
}
2009-12-08 16:50:27 +01:00
void SubversionPlugin : : diffCommitFiles ( const QStringList & files )
2008-12-02 12:01:29 +01:00
{
2009-12-08 16:50:27 +01:00
svnDiff ( m_commitRepository , files ) ;
2008-12-02 12:01:29 +01:00
}
2009-12-09 12:41:10 +01:00
static inline void setDiffBaseDirectory ( Core : : IEditor * editor , const QString & db )
{
if ( VCSBase : : VCSBaseEditor * ve = qobject_cast < VCSBase : : VCSBaseEditor * > ( editor - > widget ( ) ) )
ve - > setDiffBaseDirectory ( db ) ;
}
2009-12-08 16:50:27 +01:00
void SubversionPlugin : : svnDiff ( const QString & workingDir , const QStringList & files , QString diffname )
2008-12-02 12:01:29 +01:00
{
if ( Subversion : : Constants : : debug )
qDebug ( ) < < Q_FUNC_INFO < < files < < diffname ;
2009-12-08 16:50:27 +01:00
const QString source = VCSBase : : VCSBaseEditor : : getSource ( workingDir , files ) ;
2009-01-20 11:52:04 +01:00
QTextCodec * codec = source . isEmpty ( ) ? static_cast < QTextCodec * > ( 0 ) : VCSBase : : VCSBaseEditor : : getCodec ( source ) ;
2008-12-02 12:01:29 +01:00
if ( files . count ( ) = = 1 & & diffname . isEmpty ( ) )
diffname = QFileInfo ( files . front ( ) ) . fileName ( ) ;
QStringList args ( QLatin1String ( " diff " ) ) ;
args < < files ;
2009-12-14 12:45:45 +01:00
const SubversionResponse response = runSvn ( workingDir , args , m_settings . timeOutMS ( ) , false , codec ) ;
2008-12-02 12:01:29 +01:00
if ( response . error )
return ;
// diff of a single file? re-use an existing view if possible to support
// the common usage pattern of continuously changing and diffing a file
if ( files . count ( ) = = 1 ) {
// Show in the same editor if diff has been executed before
2009-01-20 17:14:00 +01:00
if ( Core : : IEditor * editor = locateEditor ( " originalFileName " , files . front ( ) ) ) {
2008-12-02 12:01:29 +01:00
editor - > createNew ( response . stdOut ) ;
2009-01-26 16:36:02 +01:00
Core : : EditorManager : : instance ( ) - > activateEditor ( editor ) ;
2009-12-09 12:41:10 +01:00
setDiffBaseDirectory ( editor , workingDir ) ;
2008-12-02 12:01:29 +01:00
return ;
}
}
2009-04-17 21:00:10 +02:00
const QString title = QString : : fromLatin1 ( " svn diff %1 " ) . arg ( diffname ) ;
2008-12-02 12:01:29 +01:00
Core : : IEditor * editor = showOutputInEditor ( title , response . stdOut , VCSBase : : DiffOutput , source , codec ) ;
2009-12-09 12:41:10 +01:00
setDiffBaseDirectory ( editor , workingDir ) ;
2008-12-02 12:01:29 +01:00
if ( files . count ( ) = = 1 )
editor - > setProperty ( " originalFileName " , files . front ( ) ) ;
}
SubversionSubmitEditor * SubversionPlugin : : openSubversionSubmitEditor ( const QString & fileName )
{
2010-01-08 09:48:54 +01:00
Core : : IEditor * editor = Core : : EditorManager : : instance ( ) - > openEditor ( fileName , QLatin1String ( Constants : : SUBVERSIONCOMMITEDITOR_ID ) ) ;
2008-12-02 12:01:29 +01:00
SubversionSubmitEditor * submitEditor = qobject_cast < SubversionSubmitEditor * > ( editor ) ;
2008-12-09 15:25:01 +01:00
QTC_ASSERT ( submitEditor , /**/ ) ;
2009-01-13 14:06:42 +01:00
submitEditor - > registerActions ( m_submitUndoAction , m_submitRedoAction , m_submitCurrentLogAction , m_submitDiffAction ) ;
2009-12-08 16:50:27 +01:00
connect ( submitEditor , SIGNAL ( diffSelectedFiles ( QStringList ) ) , this , SLOT ( diffCommitFiles ( QStringList ) ) ) ;
2009-12-14 10:56:50 +01:00
submitEditor - > setCheckScriptWorkingDirectory ( m_commitRepository ) ;
2008-12-02 12:01:29 +01:00
return submitEditor ;
}
2009-12-08 14:26:41 +01:00
void SubversionPlugin : : updateActions ( VCSBase : : VCSBasePlugin : : ActionState as )
2008-12-02 12:01:29 +01:00
{
2009-12-08 14:26:41 +01:00
if ( ! VCSBase : : VCSBasePlugin : : enableMenuAction ( as , m_menuAction ) )
return ;
2010-01-07 11:33:30 +01:00
m_logRepositoryAction - > setEnabled ( currentState ( ) . hasTopLevel ( ) ) ;
2009-12-08 16:50:27 +01:00
const QString projectName = currentState ( ) . currentProjectName ( ) ;
m_diffProjectAction - > setParameter ( projectName ) ;
m_statusProjectAction - > setParameter ( projectName ) ;
m_updateProjectAction - > setParameter ( projectName ) ;
2010-01-07 11:33:30 +01:00
m_logProjectAction - > setParameter ( projectName ) ;
2009-12-08 16:50:27 +01:00
const bool repoEnabled = currentState ( ) . hasTopLevel ( ) ;
m_commitAllAction - > setEnabled ( repoEnabled ) ;
m_describeAction - > setEnabled ( repoEnabled ) ;
const QString fileName = currentState ( ) . currentFileName ( ) ;
m_addAction - > setParameter ( fileName ) ;
m_deleteAction - > setParameter ( fileName ) ;
m_revertAction - > setParameter ( fileName ) ;
m_diffCurrentAction - > setParameter ( fileName ) ;
m_commitCurrentAction - > setParameter ( fileName ) ;
m_filelogCurrentAction - > setParameter ( fileName ) ;
m_annotateCurrentAction - > setParameter ( fileName ) ;
2008-12-02 12:01:29 +01:00
}
void SubversionPlugin : : addCurrentFile ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
vcsAdd ( state . currentFileTopLevel ( ) , state . relativeCurrentFile ( ) ) ;
2008-12-02 12:01:29 +01:00
}
void SubversionPlugin : : revertCurrentFile ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
2008-12-02 12:01:29 +01:00
QStringList args ( QLatin1String ( " diff " ) ) ;
2009-12-08 16:50:27 +01:00
args . push_back ( state . relativeCurrentFile ( ) ) ;
2008-12-02 12:01:29 +01:00
2009-12-14 12:45:45 +01:00
const SubversionResponse diffResponse = runSvn ( state . currentFileTopLevel ( ) , args , m_settings . timeOutMS ( ) , false ) ;
2008-12-02 12:01:29 +01:00
if ( diffResponse . error )
return ;
if ( diffResponse . stdOut . isEmpty ( ) )
return ;
2009-04-17 21:00:10 +02:00
if ( QMessageBox : : warning ( 0 , QLatin1String ( " svn revert " ) , tr ( " The file has been changed. Do you want to revert it? " ) ,
2008-12-02 12:01:29 +01:00
QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : No )
return ;
2009-06-18 14:30:04 +02:00
2009-12-08 16:50:27 +01:00
Core : : FileChangeBlocker fcb ( state . currentFile ( ) ) ;
2008-12-02 12:01:29 +01:00
// revert
args . clear ( ) ;
2009-12-08 16:50:27 +01:00
args < < QLatin1String ( " revert " ) < < state . relativeCurrentFile ( ) ;
2008-12-02 12:01:29 +01:00
2009-12-14 12:45:45 +01:00
const SubversionResponse revertResponse = runSvn ( state . currentFileTopLevel ( ) , args , m_settings . timeOutMS ( ) , true ) ;
2009-06-18 14:30:04 +02:00
if ( ! revertResponse . error ) {
fcb . setModifiedReload ( true ) ;
2009-12-08 16:50:27 +01:00
subVersionControl ( ) - > emitFilesChanged ( QStringList ( state . currentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
}
}
void SubversionPlugin : : diffProject ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasProject ( ) , return )
svnDiff ( state . currentProjectTopLevel ( ) , state . relativeCurrentProject ( ) , state . currentProjectName ( ) ) ;
2008-12-02 12:01:29 +01:00
}
void SubversionPlugin : : diffCurrentFile ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
svnDiff ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
}
void SubversionPlugin : : startCommitCurrentFile ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
startCommit ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
}
void SubversionPlugin : : startCommitAll ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
startCommit ( state . topLevel ( ) ) ;
2008-12-02 12:01:29 +01:00
}
/* Start commit of files of a single repository by displaying
* template and files in a submit editor . On closing , the real
* commit will start . */
2009-12-08 16:50:27 +01:00
void SubversionPlugin : : startCommit ( const QString & workingDir , const QStringList & files )
2008-12-02 12:01:29 +01:00
{
2009-05-27 16:17:24 +02:00
if ( VCSBase : : VCSBaseSubmitEditor : : raiseSubmitEditor ( ) )
return ;
2009-09-22 12:23:44 +02:00
if ( isCommitEditorOpen ( ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendWarning ( tr ( " Another commit is currently being executed. " ) ) ;
2008-12-02 12:01:29 +01:00
return ;
}
QStringList args ( QLatin1String ( " status " ) ) ;
args + = files ;
2009-12-14 12:45:45 +01:00
const SubversionResponse response = runSvn ( workingDir , args , m_settings . timeOutMS ( ) , false ) ;
2008-12-02 12:01:29 +01:00
if ( response . error )
return ;
2009-12-08 16:50:27 +01:00
2008-12-02 12:01:29 +01:00
// Get list of added/modified/deleted files
2009-01-12 17:44:04 +01:00
const StatusList statusOutput = parseStatusOutput ( response . stdOut ) ;
2008-12-02 12:01:29 +01:00
if ( statusOutput . empty ( ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendWarning ( tr ( " There are no modified files. " ) ) ;
2008-12-02 12:01:29 +01:00
return ;
}
2009-12-08 16:50:27 +01:00
m_commitRepository = workingDir ;
2008-12-02 12:01:29 +01:00
// Create a new submit change file containing the submit template
2009-09-22 12:23:44 +02:00
QTemporaryFile changeTmpFile ;
changeTmpFile . setAutoRemove ( false ) ;
if ( ! changeTmpFile . open ( ) ) {
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( tr ( " Cannot create temporary file: %1 " ) . arg ( changeTmpFile . errorString ( ) ) ) ;
2008-12-02 12:01:29 +01:00
return ;
}
2009-09-22 12:23:44 +02:00
m_commitMessageFileName = changeTmpFile . fileName ( ) ;
2009-10-01 17:32:26 +02:00
// TODO: Regitctrieve submit template from
2008-12-02 12:01:29 +01:00
const QString submitTemplate ;
// Create a submit
2009-09-22 12:23:44 +02:00
changeTmpFile . write ( submitTemplate . toUtf8 ( ) ) ;
changeTmpFile . flush ( ) ;
changeTmpFile . close ( ) ;
2008-12-02 12:01:29 +01:00
// Create a submit editor and set file list
2009-09-22 12:23:44 +02:00
SubversionSubmitEditor * editor = openSubversionSubmitEditor ( m_commitMessageFileName ) ;
2009-01-12 17:44:04 +01:00
editor - > setStatusList ( statusOutput ) ;
2008-12-02 12:01:29 +01:00
}
bool SubversionPlugin : : commit ( const QString & messageFile ,
const QStringList & subVersionFileList )
{
if ( Subversion : : Constants : : debug )
qDebug ( ) < < Q_FUNC_INFO < < messageFile < < subVersionFileList ;
// Transform the status list which is sth
// "[ADM]<blanks>file" into an args list. The files of the status log
// can be relative or absolute depending on where the command was run.
QStringList args = QStringList ( QLatin1String ( " commit " ) ) ;
2009-05-05 10:16:09 +02:00
args < < QLatin1String ( nonInteractiveOptionC ) < < QLatin1String ( " --file " ) < < messageFile ;
2008-12-02 12:01:29 +01:00
args . append ( subVersionFileList ) ;
2009-12-14 12:45:45 +01:00
const SubversionResponse response = runSvn ( m_commitRepository , args , m_settings . longTimeOutMS ( ) , true ) ;
2008-12-02 12:01:29 +01:00
return ! response . error ;
}
void SubversionPlugin : : filelogCurrentFile ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
2010-01-07 11:33:30 +01:00
filelog ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) , true ) ;
}
void SubversionPlugin : : logProject ( )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasProject ( ) , return )
filelog ( state . currentProjectTopLevel ( ) , state . relativeCurrentProject ( ) ) ;
}
void SubversionPlugin : : logRepository ( )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return )
filelog ( state . topLevel ( ) ) ;
2008-12-02 12:01:29 +01:00
}
2010-01-07 11:33:30 +01:00
void SubversionPlugin : : filelog ( const QString & workingDir ,
const QStringList & files ,
bool enableAnnotationContextMenu )
2008-12-02 12:01:29 +01:00
{
2009-12-08 16:50:27 +01:00
QTextCodec * codec = VCSBase : : VCSBaseEditor : : getCodec ( workingDir , files ) ;
2008-12-02 12:01:29 +01:00
// no need for temp file
QStringList args ( QLatin1String ( " log " ) ) ;
2010-01-07 11:33:30 +01:00
if ( m_settings . logCount > 0 )
args < < QLatin1String ( " -l " ) < < QString : : number ( m_settings . logCount ) ;
2009-12-08 16:50:27 +01:00
foreach ( const QString & file , files )
args . append ( QDir : : toNativeSeparators ( file ) ) ;
2008-12-02 12:01:29 +01:00
2009-12-14 12:45:45 +01:00
const SubversionResponse response = runSvn ( workingDir , args , m_settings . timeOutMS ( ) , false , codec ) ;
2008-12-02 12:01:29 +01:00
if ( response . error )
return ;
// Re-use an existing view if possible to support
// the common usage pattern of continuously changing and diffing a file
2009-12-08 16:50:27 +01:00
const QString id = VCSBase : : VCSBaseEditor : : getTitleId ( workingDir , files ) ;
if ( Core : : IEditor * editor = locateEditor ( " logFileName " , id ) ) {
2008-12-02 12:01:29 +01:00
editor - > createNew ( response . stdOut ) ;
2009-01-26 16:36:02 +01:00
Core : : EditorManager : : instance ( ) - > activateEditor ( editor ) ;
2008-12-02 12:01:29 +01:00
} else {
2009-12-08 16:50:27 +01:00
const QString title = QString : : fromLatin1 ( " svn log %1 " ) . arg ( id ) ;
const QString source = VCSBase : : VCSBaseEditor : : getSource ( workingDir , files ) ;
Core : : IEditor * newEditor = showOutputInEditor ( title , response . stdOut , VCSBase : : LogOutput , source , codec ) ;
newEditor - > setProperty ( " logFileName " , id ) ;
2010-01-07 11:33:30 +01:00
if ( enableAnnotationContextMenu )
VCSBase : : VCSBaseEditor : : getVcsBaseEditor ( newEditor ) - > setFileLogAnnotateEnabled ( true ) ;
2008-12-02 12:01:29 +01:00
}
}
void SubversionPlugin : : updateProject ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasProject ( ) , return ) ;
2008-12-02 12:01:29 +01:00
QStringList args ( QLatin1String ( " update " ) ) ;
2009-05-05 10:16:09 +02:00
args . push_back ( QLatin1String ( nonInteractiveOptionC ) ) ;
2009-12-08 16:50:27 +01:00
args . append ( state . relativeCurrentProject ( ) ) ;
2009-12-14 12:45:45 +01:00
const SubversionResponse response = runSvn ( state . currentProjectTopLevel ( ) , args , m_settings . longTimeOutMS ( ) , true ) ;
2009-12-08 16:50:27 +01:00
if ( ! response . error )
subVersionControl ( ) - > emitRepositoryChanged ( state . currentProjectTopLevel ( ) ) ;
2008-12-02 12:01:29 +01:00
}
void SubversionPlugin : : annotateCurrentFile ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return ) ;
annotate ( state . currentFileTopLevel ( ) , state . relativeCurrentFile ( ) ) ;
2008-12-02 12:01:29 +01:00
}
2010-01-06 17:24:40 +01:00
void SubversionPlugin : : annotateVersion ( const QString & file ,
const QString & revision ,
int lineNr )
{
const QFileInfo fi ( file ) ;
annotate ( fi . absolutePath ( ) , fi . fileName ( ) , revision , lineNr ) ;
}
void SubversionPlugin : : annotate ( const QString & workingDir , const QString & file ,
const QString & revision /* = QString() */ ,
int lineNumber /* = -1 */ )
2008-12-02 12:01:29 +01:00
{
2009-01-20 11:52:04 +01:00
QTextCodec * codec = VCSBase : : VCSBaseEditor : : getCodec ( file ) ;
2008-12-02 12:01:29 +01:00
QStringList args ( QLatin1String ( " annotate " ) ) ;
2010-01-05 15:45:41 +01:00
if ( m_settings . spaceIgnorantAnnotation )
args < < QLatin1String ( " -x " ) < < QLatin1String ( " -uw " ) ;
2010-01-06 17:24:40 +01:00
if ( ! revision . isEmpty ( ) )
args < < QLatin1String ( " -r " ) < < revision ;
2008-12-02 12:01:29 +01:00
args . push_back ( QLatin1String ( " -v " ) ) ;
args . append ( QDir : : toNativeSeparators ( file ) ) ;
2009-12-14 12:45:45 +01:00
const SubversionResponse response = runSvn ( workingDir , args , m_settings . timeOutMS ( ) , false , codec ) ;
2008-12-02 12:01:29 +01:00
if ( response . error )
return ;
// Re-use an existing view if possible to support
// the common usage pattern of continuously changing and diffing a file
2009-12-08 16:50:27 +01:00
const QString source = workingDir + QLatin1Char ( ' / ' ) + file ;
2010-01-06 17:24:40 +01:00
if ( lineNumber < = 0 )
lineNumber = VCSBase : : VCSBaseEditor : : lineNumberOfCurrentEditor ( source ) ;
// Determine id
const QString id = VCSBase : : VCSBaseEditor : : getTitleId ( workingDir , QStringList ( file ) , revision ) ;
2008-12-02 12:01:29 +01:00
2009-12-08 16:50:27 +01:00
if ( Core : : IEditor * editor = locateEditor ( " annotateFileName " , id ) ) {
2008-12-02 12:01:29 +01:00
editor - > createNew ( response . stdOut ) ;
2009-10-01 17:32:26 +02:00
VCSBase : : VCSBaseEditor : : gotoLineOfEditor ( editor , lineNumber ) ;
Core : : EditorManager : : instance ( ) - > activateEditor ( editor ) ;
2008-12-02 12:01:29 +01:00
} else {
2009-12-08 16:50:27 +01:00
const QString title = QString : : fromLatin1 ( " svn annotate %1 " ) . arg ( id ) ;
Core : : IEditor * newEditor = showOutputInEditor ( title , response . stdOut , VCSBase : : AnnotateOutput , source , codec ) ;
newEditor - > setProperty ( " annotateFileName " , id ) ;
2009-10-01 17:32:26 +02:00
VCSBase : : VCSBaseEditor : : gotoLineOfEditor ( newEditor , lineNumber ) ;
2008-12-02 12:01:29 +01:00
}
}
void SubversionPlugin : : projectStatus ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasProject ( ) , return ) ;
2008-12-02 12:01:29 +01:00
QStringList args ( QLatin1String ( " status " ) ) ;
2009-12-08 16:50:27 +01:00
args + = state . relativeCurrentProject ( ) ;
2009-12-15 14:20:06 +01:00
VCSBase : : VCSBaseOutputWindow * outwin = VCSBase : : VCSBaseOutputWindow : : instance ( ) ;
outwin - > setRepository ( state . currentProjectTopLevel ( ) ) ;
2009-12-14 12:45:45 +01:00
runSvn ( state . currentProjectTopLevel ( ) , args , m_settings . timeOutMS ( ) , true ) ;
2009-12-15 14:20:06 +01:00
outwin - > clearRepository ( ) ;
2008-12-02 12:01:29 +01:00
}
void SubversionPlugin : : describe ( const QString & source , const QString & changeNr )
{
// To describe a complete change, find the top level and then do
//svn diff -r 472958:472959 <top level>
const QFileInfo fi ( source ) ;
const QString topLevel = findTopLevelForDirectory ( fi . isDir ( ) ? source : fi . absolutePath ( ) ) ;
if ( topLevel . isEmpty ( ) )
return ;
if ( Subversion : : Constants : : debug )
qDebug ( ) < < Q_FUNC_INFO < < source < < topLevel < < changeNr ;
// Number must be > 1
bool ok ;
const int number = changeNr . toInt ( & ok ) ;
if ( ! ok | | number < 2 )
return ;
2009-02-10 08:38:12 +01:00
// Run log to obtain message (local utf8)
QString description ;
QStringList args ( QLatin1String ( " log " ) ) ;
args . push_back ( QLatin1String ( " -r " ) ) ;
args . push_back ( changeNr ) ;
2009-12-14 12:45:45 +01:00
const SubversionResponse logResponse = runSvn ( topLevel , args , m_settings . timeOutMS ( ) , false ) ;
2009-02-10 08:38:12 +01:00
if ( logResponse . error )
return ;
description = logResponse . stdOut ;
// Run diff (encoding via source codec)
args . clear ( ) ;
args . push_back ( QLatin1String ( " diff " ) ) ;
2008-12-02 12:01:29 +01:00
args . push_back ( QLatin1String ( " -r " ) ) ;
QString diffArg ;
QTextStream ( & diffArg ) < < ( number - 1 ) < < ' : ' < < number ;
args . push_back ( diffArg ) ;
2009-01-20 11:52:04 +01:00
QTextCodec * codec = VCSBase : : VCSBaseEditor : : getCodec ( source ) ;
2009-12-14 12:45:45 +01:00
const SubversionResponse response = runSvn ( topLevel , args , m_settings . timeOutMS ( ) , false , codec ) ;
2008-12-02 12:01:29 +01:00
if ( response . error )
return ;
2009-02-10 08:38:12 +01:00
description + = response . stdOut ;
2008-12-02 12:01:29 +01:00
// Re-use an existing view if possible to support
// the common usage pattern of continuously changing and diffing a file
const QString id = diffArg + source ;
2009-01-20 17:14:00 +01:00
if ( Core : : IEditor * editor = locateEditor ( " describeChange " , id ) ) {
2009-02-10 08:38:12 +01:00
editor - > createNew ( description ) ;
2009-02-10 13:51:59 +01:00
Core : : EditorManager : : instance ( ) - > activateEditor ( editor ) ;
2008-12-02 12:01:29 +01:00
} else {
2009-12-08 16:50:27 +01:00
const QString title = QString : : fromLatin1 ( " svn describe %1#%2 " ) . arg ( fi . fileName ( ) , changeNr ) ;
2009-02-10 08:38:12 +01:00
Core : : IEditor * newEditor = showOutputInEditor ( title , description , VCSBase : : DiffOutput , source , codec ) ;
2008-12-02 12:01:29 +01:00
newEditor - > setProperty ( " describeChange " , id ) ;
}
}
2009-02-09 17:33:31 +01:00
void SubversionPlugin : : slotDescribe ( )
{
2009-12-08 16:50:27 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2009-02-09 17:33:31 +01:00
QInputDialog inputDialog ( Core : : ICore : : instance ( ) - > mainWindow ( ) ) ;
inputDialog . setWindowFlags ( inputDialog . windowFlags ( ) & ~ Qt : : WindowContextHelpButtonHint ) ;
inputDialog . setInputMode ( QInputDialog : : IntInput ) ;
inputDialog . setIntRange ( 2 , INT_MAX ) ;
inputDialog . setWindowTitle ( tr ( " Describe " ) ) ;
inputDialog . setLabelText ( tr ( " Revision number: " ) ) ;
if ( inputDialog . exec ( ) ! = QDialog : : Accepted )
return ;
const int revision = inputDialog . intValue ( ) ;
2009-12-08 16:50:27 +01:00
describe ( state . topLevel ( ) , QString : : number ( revision ) ) ;
2009-02-09 17:33:31 +01:00
}
2008-12-02 12:01:29 +01:00
void SubversionPlugin : : submitCurrentLog ( )
{
2009-03-20 10:16:18 +01:00
m_submitActionTriggered = true ;
2009-01-21 15:52:34 +01:00
Core : : EditorManager : : instance ( ) - > closeEditors ( QList < Core : : IEditor * > ( )
< < Core : : EditorManager : : instance ( ) - > currentEditor ( ) ) ;
2008-12-02 12:01:29 +01:00
}
static inline QString processStdErr ( QProcess & proc )
{
return QString : : fromLocal8Bit ( proc . readAllStandardError ( ) ) . remove ( QLatin1Char ( ' \r ' ) ) ;
}
static inline QString processStdOut ( QProcess & proc , QTextCodec * outputCodec = 0 )
{
const QByteArray stdOutData = proc . readAllStandardOutput ( ) ;
QString stdOut = outputCodec ? outputCodec - > toUnicode ( stdOutData ) : QString : : fromLocal8Bit ( stdOutData ) ;
return stdOut . remove ( QLatin1Char ( ' \r ' ) ) ;
}
2009-12-08 16:50:27 +01:00
SubversionResponse SubversionPlugin : : runSvn ( const QString & workingDir ,
const QStringList & arguments ,
2008-12-02 12:01:29 +01:00
int timeOut ,
bool showStdOutInOutputWindow ,
QTextCodec * outputCodec )
{
const QString executable = m_settings . svnCommand ;
SubversionResponse response ;
if ( executable . isEmpty ( ) ) {
response . error = true ;
response . message = tr ( " No subversion executable specified! " ) ;
return response ;
}
const QStringList allArgs = m_settings . addOptions ( arguments ) ;
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow * outputWindow = VCSBase : : VCSBaseOutputWindow : : instance ( ) ;
2008-12-02 12:01:29 +01:00
// Hide passwords, etc in the log window
2009-08-10 15:46:45 +02:00
//: Executing: <executable> <arguments>
const QString outputText = tr ( " Executing: %1 %2 \n " ) . arg ( executable , SubversionSettings : : formatArguments ( allArgs ) ) ;
outputWindow - > appendCommand ( outputText ) ;
2008-12-02 12:01:29 +01:00
if ( Subversion : : Constants : : debug )
qDebug ( ) < < " runSvn " < < timeOut < < outputText ;
// Run, connect stderr to the output window
2009-10-05 11:06:05 +02:00
Utils : : SynchronousProcess process ;
2009-12-08 16:50:27 +01:00
if ( ! workingDir . isEmpty ( ) )
process . setWorkingDirectory ( workingDir ) ;
2008-12-02 12:01:29 +01:00
process . setTimeout ( timeOut ) ;
process . setStdOutCodec ( outputCodec ) ;
process . setStdErrBufferedSignalsEnabled ( true ) ;
2009-08-10 15:46:45 +02:00
connect ( & process , SIGNAL ( stdErrBuffered ( QString , bool ) ) , outputWindow , SLOT ( append ( QString ) ) ) ;
2008-12-02 12:01:29 +01:00
// connect stdout to the output window if desired
if ( showStdOutInOutputWindow ) {
process . setStdOutBufferedSignalsEnabled ( true ) ;
2009-08-10 15:46:45 +02:00
connect ( & process , SIGNAL ( stdOutBuffered ( QString , bool ) ) , outputWindow , SLOT ( append ( QString ) ) ) ;
2008-12-02 12:01:29 +01:00
}
2009-10-05 11:06:05 +02:00
const Utils : : SynchronousProcessResponse sp_resp = process . run ( executable , allArgs ) ;
2008-12-02 12:01:29 +01:00
response . error = true ;
response . stdErr = sp_resp . stdErr ;
response . stdOut = sp_resp . stdOut ;
switch ( sp_resp . result ) {
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : Finished :
2008-12-02 12:01:29 +01:00
response . error = false ;
break ;
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : FinishedError :
2008-12-02 12:01:29 +01:00
response . message = tr ( " The process terminated with exit code %1. " ) . arg ( sp_resp . exitCode ) ;
break ;
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : TerminatedAbnormally :
2008-12-02 12:01:29 +01:00
response . message = tr ( " The process terminated abnormally. " ) ;
break ;
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : StartFailed :
2008-12-02 12:01:29 +01:00
response . message = tr ( " Could not start subversion '%1'. Please check your settings in the preferences. " ) . arg ( executable ) ;
break ;
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : Hang :
2008-12-02 12:01:29 +01:00
response . message = tr ( " Subversion did not respond within timeout limit (%1 ms). " ) . arg ( timeOut ) ;
break ;
}
if ( response . error )
2009-08-10 15:46:45 +02:00
outputWindow - > appendError ( response . message ) ;
2008-12-02 12:01:29 +01:00
return response ;
}
Core : : IEditor * SubversionPlugin : : showOutputInEditor ( const QString & title , const QString & output ,
int editorType , const QString & source ,
QTextCodec * codec )
{
const VCSBase : : VCSBaseEditorParameters * params = findType ( editorType ) ;
2008-12-09 15:25:01 +01:00
QTC_ASSERT ( params , return 0 ) ;
2010-01-07 18:17:24 +01:00
const QString id = params - > id ;
2008-12-02 12:01:29 +01:00
if ( Subversion : : Constants : : debug )
2010-01-07 18:17:24 +01:00
qDebug ( ) < < " SubversionPlugin::showOutputInEditor " < < title < < id < < " Size= " < < output . size ( ) < < " Type= " < < editorType < < debugCodec ( codec ) ;
2008-12-02 12:01:29 +01:00
QString s = title ;
2010-01-07 18:17:24 +01:00
Core : : IEditor * editor = Core : : EditorManager : : instance ( ) - > openEditorWithContents ( id , & s , output ) ;
2010-01-07 11:33:30 +01:00
connect ( editor , SIGNAL ( annotateRevisionRequested ( QString , QString , int ) ) ,
this , SLOT ( annotateVersion ( QString , QString , int ) ) ) ;
2009-01-21 15:52:34 +01:00
SubversionEditor * e = qobject_cast < SubversionEditor * > ( editor - > widget ( ) ) ;
2008-12-02 12:01:29 +01:00
if ( ! e )
return 0 ;
s . replace ( QLatin1Char ( ' ' ) , QLatin1Char ( ' _ ' ) ) ;
e - > setSuggestedFileName ( s ) ;
if ( ! source . isEmpty ( ) )
e - > setSource ( source ) ;
if ( codec )
e - > setCodec ( codec ) ;
2009-03-10 11:02:12 +01:00
Core : : IEditor * ie = e - > editableInterface ( ) ;
Core : : EditorManager : : instance ( ) - > activateEditor ( ie ) ;
return ie ;
2008-12-02 12:01:29 +01:00
}
SubversionSettings SubversionPlugin : : settings ( ) const
{
return m_settings ;
}
void SubversionPlugin : : setSettings ( const SubversionSettings & s )
{
if ( s ! = m_settings ) {
m_settings = s ;
2009-01-20 17:14:00 +01:00
if ( QSettings * settings = Core : : ICore : : instance ( ) - > settings ( ) )
2008-12-02 12:01:29 +01:00
m_settings . toSettings ( settings ) ;
}
}
SubversionPlugin * SubversionPlugin : : subversionPluginInstance ( )
{
2008-12-12 17:02:55 +01:00
QTC_ASSERT ( m_subversionPluginInstance , return m_subversionPluginInstance ) ;
2008-12-02 12:01:29 +01:00
return m_subversionPluginInstance ;
}
2009-12-08 16:50:27 +01:00
bool SubversionPlugin : : vcsAdd ( const QString & workingDir , const QString & rawFileName )
2010-01-08 12:55:30 +01:00
{
# ifdef Q_OS_MAC // See below.
return vcsAdd14 ( workingDir , rawFileName ) ;
# else
return vcsAdd15 ( workingDir , rawFileName ) ;
# endif
}
// Post 1.4 add: Use "--parents" to add directories
bool SubversionPlugin : : vcsAdd15 ( const QString & workingDir , const QString & rawFileName )
2008-12-02 12:01:29 +01:00
{
const QString file = QDir : : toNativeSeparators ( rawFileName ) ;
2010-01-06 10:57:07 +01:00
QStringList args ;
args < < QLatin1String ( " add " ) < < QLatin1String ( " --parents " ) < < file ;
2009-12-14 12:45:45 +01:00
const SubversionResponse response = runSvn ( workingDir , args , m_settings . timeOutMS ( ) , true ) ;
2008-12-02 12:01:29 +01:00
return ! response . error ;
}
2010-01-08 12:55:30 +01:00
// Pre 1.5 add: Add directories in a loop. To be deprecated
// once Mac ships newer svn-versions
bool SubversionPlugin : : vcsAdd14 ( const QString & workingDir , const QString & rawFileName )
{
const QChar slash = QLatin1Char ( ' / ' ) ;
const QStringList relativePath = rawFileName . split ( slash ) ;
// Add directories (dir1/dir2/file.cpp) in a loop.
if ( relativePath . size ( ) > 1 ) {
QString path ;
const int lastDir = relativePath . size ( ) - 1 ;
for ( int p = 0 ; p < lastDir ; p + + ) {
if ( ! path . isEmpty ( ) )
path + = slash ;
path + = relativePath . at ( p ) ;
if ( ! managesDirectory ( QDir ( path ) ) ) {
QStringList addDirArgs ;
addDirArgs < < QLatin1String ( " add " ) < < QLatin1String ( " --non-recursive " ) < < QDir : : toNativeSeparators ( path ) ;
const SubversionResponse addDirResponse = runSvn ( workingDir , addDirArgs , m_settings . timeOutMS ( ) , true ) ;
if ( addDirResponse . error )
return false ;
}
}
}
// Add file
QStringList args ;
args < < QLatin1String ( " add " ) < < QDir : : toNativeSeparators ( rawFileName ) ;
const SubversionResponse response = runSvn ( workingDir , args , m_settings . timeOutMS ( ) , true ) ;
return ! response . error ;
}
2009-12-08 16:50:27 +01:00
bool SubversionPlugin : : vcsDelete ( const QString & workingDir , const QString & rawFileName )
2008-12-02 12:01:29 +01:00
{
const QString file = QDir : : toNativeSeparators ( rawFileName ) ;
QStringList args ( QLatin1String ( " delete " ) ) ;
args . push_back ( file ) ;
2009-12-14 12:45:45 +01:00
const SubversionResponse response = runSvn ( workingDir , args , m_settings . timeOutMS ( ) , true ) ;
2008-12-02 12:01:29 +01:00
return ! response . error ;
}
/* Subversion has ".svn" directory in each directory
* it manages . The top level is the first directory
* under the directory that does not have a " .svn " . */
bool SubversionPlugin : : managesDirectory ( const QString & directory ) const
{
const QDir dir ( directory ) ;
const bool rc = dir . exists ( ) & & managesDirectory ( dir ) ;
if ( Subversion : : Constants : : debug )
qDebug ( ) < < " SubversionPlugin::managesDirectory " < < directory < < rc ;
return rc ;
}
bool SubversionPlugin : : managesDirectory ( const QDir & directory ) const
{
2009-05-26 12:25:32 +02:00
const int dirCount = m_svnDirectories . size ( ) ;
for ( int i = 0 ; i < dirCount ; i + + ) {
const QString svnDir = directory . absoluteFilePath ( m_svnDirectories . at ( i ) ) ;
if ( QFileInfo ( svnDir ) . isDir ( ) )
return true ;
}
return false ;
2008-12-02 12:01:29 +01:00
}
QString SubversionPlugin : : findTopLevelForDirectory ( const QString & directory ) const
{
// Debug wrapper
const QString rc = findTopLevelForDirectoryI ( directory ) ;
if ( Subversion : : Constants : : debug )
qDebug ( ) < < " SubversionPlugin::findTopLevelForDirectory " < < directory < < rc ;
return rc ;
}
QString SubversionPlugin : : findTopLevelForDirectoryI ( const QString & directory ) const
{
/* Recursing up, the top level is a child of the first directory that does
* not have a " .svn " directory . The starting directory must be a managed
* one . Go up and try to find the first unmanaged parent dir . */
QDir lastDirectory = QDir ( directory ) ;
if ( ! lastDirectory . exists ( ) | | ! managesDirectory ( lastDirectory ) )
return QString ( ) ;
for ( QDir parentDir = lastDirectory ; parentDir . cdUp ( ) ; lastDirectory = parentDir ) {
if ( ! managesDirectory ( parentDir ) )
return QDir : : toNativeSeparators ( lastDirectory . absolutePath ( ) ) ;
}
return QString ( ) ;
}
2009-12-08 14:26:41 +01:00
SubversionControl * SubversionPlugin : : subVersionControl ( ) const
{
return static_cast < SubversionControl * > ( versionControl ( ) ) ;
}
2008-12-02 12:01:29 +01:00
Q_EXPORT_PLUGIN ( SubversionPlugin )