2009-02-25 09:15:00 +01:00
/**************************************************************************
2008-12-02 12:01:29 +01:00
* *
* * This file is part of Qt Creator
* *
2011-01-11 16:28:15 +01:00
* * Copyright ( c ) 2011 Nokia Corporation and / or its subsidiary ( - ies ) .
2008-12-02 12:01:29 +01:00
* *
2011-04-13 08:42:33 +02:00
* * Contact : Nokia Corporation ( info @ qt . nokia . com )
2008-12-02 12:01:29 +01:00
* *
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
* *
2011-04-13 08:42:33 +02:00
* * 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
* *
2010-12-17 16:01:08 +01:00
* * In addition , as a special exception , Nokia gives you certain additional
2011-04-13 08:42:33 +02:00
* * rights . These rights are described in the Nokia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
* * version 1.1 , included in the file LGPL_EXCEPTION . txt in this package .
* *
2011-04-13 08:42:33 +02:00
* * Other Usage
* *
* * Alternatively , this file may be used in accordance with the terms and
* * conditions contained in a signed written agreement between you and Nokia .
* *
2010-12-17 16:01:08 +01:00
* * If you have questions regarding the use of this file , please contact
* * Nokia at qt - info @ nokia . com .
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>
2011-03-25 16:39:33 +01:00
# include <vcsbase/vcsbaseeditorparameterwidget.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>
2009-01-13 13:39:31 +01:00
# include <coreplugin/actionmanager/actionmanager.h>
2010-03-18 10:59:06 +01:00
# include <coreplugin/actionmanager/actioncontainer.h>
# include <coreplugin/actionmanager/command.h>
2010-11-02 16:53:56 +01:00
# include <coreplugin/uniqueidmanager.h>
2008-12-02 12:01:29 +01:00
# include <coreplugin/editormanager/editormanager.h>
2010-02-12 16:03:08 +01:00
# include <locator/commandlocator.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>
2010-04-27 12:16:51 +02:00
# include <QtCore/QProcessEnvironment>
2010-09-29 12:16:35 +02:00
# include <QtCore/QUrl>
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>
2010-09-29 12:16:35 +02:00
# include <QtXml/QXmlStreamReader>
2009-02-09 17:33:31 +01:00
# include <limits.h>
2008-12-02 12:01:29 +01:00
2011-03-25 16:39:33 +01:00
namespace Subversion {
namespace Internal {
2008-12-02 12:01:29 +01:00
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 " ;
2010-01-11 17:17:16 +01:00
static const char * const CMD_ID_REVERT_ALL = " Subversion.RevertAll " ;
2009-07-14 17:20:20 +02:00
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 " ;
2010-04-27 12:16:51 +02:00
static const char * const CMD_ID_REPOSITORYUPDATE = " Subversion.RepositoryUpdate " ;
static const char * const CMD_ID_REPOSITORYDIFF = " Subversion.RepositoryDiff " ;
static const char * const CMD_ID_REPOSITORYSTATUS = " Subversion.RepositoryStatus " ;
2009-07-14 17:20:20 +02:00
static const char * const CMD_ID_UPDATE = " Subversion.Update " ;
2010-04-27 12:16:51 +02:00
static const char * const CMD_ID_COMMIT_PROJECT = " Subversion.CommitProject " ;
2009-07-14 17:20:20 +02:00
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 " ;
2010-05-21 17:46:00 +02:00
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 ) ;
2011-02-21 16:02:26 +01:00
return VCSBase : : VCSBaseEditorWidget : : findType ( editorParameters , sizeof ( editorParameters ) / sizeof ( VCSBase : : VCSBaseEditorParameters ) , et ) ;
2008-12-02 12:01:29 +01:00
}
static inline QString debugCodec ( const QTextCodec * c )
{
return c ? QString : : fromAscii ( c - > name ( ) ) : QString : : fromAscii ( " Null codec " ) ;
}
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 ( ) ) ,
2010-02-12 16:03:08 +01:00
m_commandLocator ( 0 ) ,
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 ) ,
2010-01-11 17:17:16 +01:00
m_revertRepositoryAction ( 0 ) ,
2010-04-27 12:16:51 +02:00
m_diffRepositoryAction ( 0 ) ,
m_statusRepositoryAction ( 0 ) ,
m_updateRepositoryAction ( 0 ) ,
2008-12-02 12:01:29 +01:00
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 ) ,
2010-04-27 12:16:51 +02:00
m_commitProjectAction ( 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 ,
2010-06-25 12:56:16 +02:00
const Core : : Context & globalcontext )
2009-02-09 17:33:31 +01:00
{
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 ) ;
2010-02-12 16:03:08 +01:00
const QString description = QLatin1String ( " Subversion " ) ;
const QString prefix = QLatin1String ( " svn " ) ;
m_commandLocator = new Locator : : CommandLocator ( description , prefix , prefix ) ;
addAutoReleasedObject ( m_commandLocator ) ;
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 =
2010-09-10 14:13:19 +02:00
ami - > createMenu ( Core : : Id ( 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 ( ) ;
2010-06-25 17:37:59 +02:00
Core : : Context globalcontext ( C_GLOBAL ) ;
2009-01-14 13:17:53 +01:00
Core : : Command * command ;
2010-01-11 17:17:16 +01:00
m_diffCurrentAction = new Utils : : ParameterAction ( tr ( " Diff Current File " ) , tr ( " Diff \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_diffCurrentAction ,
CMD_ID_DIFF_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+S,Alt+D " ) ) ) ;
connect ( m_diffCurrentAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
subversionMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2008-12-02 12:01:29 +01:00
2010-01-11 17:17:16 +01:00
m_filelogCurrentAction = new Utils : : ParameterAction ( tr ( " Filelog Current File " ) , tr ( " Filelog \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_filelogCurrentAction ,
CMD_ID_FILELOG_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
connect ( m_filelogCurrentAction , SIGNAL ( triggered ( ) ) , this ,
SLOT ( filelogCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
subversionMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2008-12-02 12:01:29 +01:00
2010-01-11 17:17:16 +01:00
m_annotateCurrentAction = new Utils : : ParameterAction ( tr ( " Annotate Current File " ) , tr ( " Annotate \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_annotateCurrentAction ,
CMD_ID_ANNOTATE_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
connect ( m_annotateCurrentAction , SIGNAL ( triggered ( ) ) , this ,
SLOT ( annotateCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
subversionMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2008-12-02 12:01:29 +01:00
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
2010-01-11 17:17:16 +01:00
m_addAction = new Utils : : ParameterAction ( tr ( " Add " ) , tr ( " Add \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_addAction , CMD_ID_ADD ,
2008-12-02 12:01:29 +01:00
globalcontext ) ;
2009-12-08 16:50:27 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+S,Alt+A " ) ) ) ;
connect ( m_addAction , SIGNAL ( triggered ( ) ) , this , SLOT ( addCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
subversionMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2008-12-02 12:01:29 +01:00
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 ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2008-12-02 12:01:29 +01:00
2010-01-11 17:17:16 +01:00
m_deleteAction = new Utils : : ParameterAction ( tr ( " Delete... " ) , tr ( " Delete \" %1 \" ... " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_deleteAction , CMD_ID_DELETE_FILE ,
globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
connect ( m_deleteAction , SIGNAL ( triggered ( ) ) , this , SLOT ( promptToDeleteCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
subversionMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2008-12-02 12:01:29 +01:00
2010-01-11 17:17:16 +01:00
m_revertAction = new Utils : : ParameterAction ( tr ( " Revert... " ) , tr ( " Revert \" %1 \" ... " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_revertAction , CMD_ID_REVERT ,
globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
connect ( m_revertAction , SIGNAL ( triggered ( ) ) , this , SLOT ( revertCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
subversionMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2008-12-02 12:01:29 +01:00
2010-01-11 17:17:16 +01:00
subversionMenu - > addAction ( createSeparator ( this , ami , CMD_ID_SEPARATOR1 , globalcontext ) ) ;
2009-02-09 17:33:31 +01:00
2010-01-11 17:17:16 +01:00
m_diffProjectAction = new Utils : : ParameterAction ( tr ( " Diff Project " ) , tr ( " Diff Project \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_diffProjectAction , CMD_ID_DIFF_PROJECT ,
globalcontext ) ;
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
connect ( m_diffProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffProject ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
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-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2008-12-02 12:01:29 +01:00
2010-02-25 14:52:20 +01:00
m_logProjectAction = new Utils : : ParameterAction ( tr ( " Log Project " ) , tr ( " Log Project \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2010-01-07 11:33:30 +01:00
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 ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2010-01-07 11:33:30 +01:00
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-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2008-12-02 12:01:29 +01:00
2010-04-27 12:16:51 +02:00
m_commitProjectAction = new Utils : : ParameterAction ( tr ( " Commit Project " ) , tr ( " Commit Project \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_commitProjectAction , CMD_ID_COMMIT_PROJECT , globalcontext ) ;
connect ( m_commitProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( startCommitProject ( ) ) ) ;
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
subversionMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
2010-01-11 17:17:16 +01:00
subversionMenu - > addAction ( createSeparator ( this , ami , CMD_ID_SEPARATOR2 , globalcontext ) ) ;
2010-04-27 12:16:51 +02:00
m_diffRepositoryAction = new QAction ( tr ( " Diff Repository " ) , this ) ;
command = ami - > registerAction ( m_diffRepositoryAction , CMD_ID_REPOSITORYDIFF , globalcontext ) ;
connect ( m_diffRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffRepository ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
m_statusRepositoryAction = new QAction ( tr ( " Repository Status " ) , this ) ;
command = ami - > registerAction ( m_statusRepositoryAction , CMD_ID_REPOSITORYSTATUS , globalcontext ) ;
connect ( m_statusRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( statusRepository ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
m_logRepositoryAction = new QAction ( tr ( " Log Repository " ) , this ) ;
2010-01-07 11:33:30 +01:00
command = ami - > registerAction ( m_logRepositoryAction , CMD_ID_REPOSITORYLOG , globalcontext ) ;
connect ( m_logRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( logRepository ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2010-01-07 11:33:30 +01:00
2010-04-27 12:16:51 +02:00
m_updateRepositoryAction = new QAction ( tr ( " Update Repository " ) , this ) ;
command = ami - > registerAction ( m_updateRepositoryAction , CMD_ID_REPOSITORYUPDATE , globalcontext ) ;
connect ( m_updateRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( updateRepository ( ) ) ) ;
2010-01-11 17:17:16 +01:00
subversionMenu - > addAction ( command ) ;
2010-04-27 12:16:51 +02:00
m_commandLocator - > appendCommand ( command ) ;
2010-01-11 17:17:16 +01:00
m_commitAllAction = new QAction ( tr ( " Commit All Files " ) , this ) ;
command = ami - > registerAction ( m_commitAllAction , CMD_ID_COMMIT_ALL ,
globalcontext ) ;
connect ( m_commitAllAction , SIGNAL ( triggered ( ) ) , this , SLOT ( startCommitAll ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2010-01-11 17:17:16 +01:00
2010-04-27 12:16:51 +02:00
m_describeAction = new QAction ( tr ( " Describe... " ) , this ) ;
command = ami - > registerAction ( m_describeAction , CMD_ID_DESCRIBE , globalcontext ) ;
connect ( m_describeAction , SIGNAL ( triggered ( ) ) , this , SLOT ( slotDescribe ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2010-01-11 17:17:16 +01:00
m_revertRepositoryAction = new QAction ( tr ( " Revert Repository... " ) , this ) ;
command = ami - > registerAction ( m_revertRepositoryAction , CMD_ID_REVERT_ALL ,
globalcontext ) ;
connect ( m_revertRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( revertAll ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2010-01-11 17:17:16 +01:00
2008-12-02 12:01:29 +01:00
// Actions of the submit editor
2010-06-25 17:37:59 +02:00
Core : : Context svncommitcontext ( 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 ) ;
2010-08-19 10:04:21 +02:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2008-12-02 12:01:29 +01:00
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 ;
}
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
2011-03-30 12:43:17 +02:00
closeEditor = Core : : ICore : : instance ( ) - > fileManager ( ) - > saveFile ( fileIFace ) ;
if ( closeEditor )
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
}
2011-03-25 16:39:33 +01:00
// Collect all parameters required for a diff to be able to associate them
// with a diff editor and re-run the diff with parameters.
struct SubversionDiffParameters
{
QString workingDir ;
QStringList arguments ;
QStringList files ;
QString diffName ;
} ;
// Parameter widget controlling whitespace diff mode, associated with a parameter
class SubversionDiffParameterWidget : public VCSBase : : VCSBaseEditorParameterWidget
{
Q_OBJECT
public :
explicit SubversionDiffParameterWidget ( const SubversionDiffParameters & p , QWidget * parent = 0 ) ;
signals :
void reRunDiff ( const Subversion : : Internal : : SubversionDiffParameters & ) ;
private slots :
void triggerReRun ( ) ;
private :
const SubversionDiffParameters m_parameters ;
} ;
SubversionDiffParameterWidget : : SubversionDiffParameterWidget ( const SubversionDiffParameters & p , QWidget * parent ) :
VCSBase : : VCSBaseEditorParameterWidget ( parent ) , m_parameters ( p )
{
setBaseArguments ( p . arguments ) ;
addIgnoreWhiteSpaceButton ( QString ( QLatin1Char ( ' w ' ) ) ) ;
connect ( this , SIGNAL ( argumentsChanged ( ) ) , this , SLOT ( triggerReRun ( ) ) ) ;
}
void SubversionDiffParameterWidget : : triggerReRun ( )
{
SubversionDiffParameters effectiveParameters = m_parameters ;
// Subversion wants" -x -<ext-args>", default being -u
const QStringList a = arguments ( ) ;
if ( ! a . isEmpty ( ) )
effectiveParameters . arguments < < QLatin1String ( " -x " ) < < ( QLatin1String ( " -u " ) + a . join ( QString ( ) ) ) ;
emit reRunDiff ( effectiveParameters ) ;
}
2009-12-09 12:41:10 +01:00
static inline void setDiffBaseDirectory ( Core : : IEditor * editor , const QString & db )
{
2011-02-21 16:02:26 +01:00
if ( VCSBase : : VCSBaseEditorWidget * ve = qobject_cast < VCSBase : : VCSBaseEditorWidget * > ( editor - > widget ( ) ) )
2009-12-09 12:41:10 +01:00
ve - > setDiffBaseDirectory ( db ) ;
}
2009-12-08 16:50:27 +01:00
void SubversionPlugin : : svnDiff ( const QString & workingDir , const QStringList & files , QString diffname )
2011-03-25 16:39:33 +01:00
{
SubversionDiffParameters p ;
p . workingDir = workingDir ;
p . files = files ;
p . diffName = diffname ;
svnDiff ( p ) ;
}
void SubversionPlugin : : svnDiff ( const Subversion : : Internal : : SubversionDiffParameters & p )
2008-12-02 12:01:29 +01:00
{
if ( Subversion : : Constants : : debug )
2011-03-25 16:39:33 +01:00
qDebug ( ) < < Q_FUNC_INFO < < p . files < < p . diffName ;
const QString source = VCSBase : : VCSBaseEditorWidget : : getSource ( p . workingDir , p . files ) ;
2011-02-21 16:02:26 +01:00
QTextCodec * codec = source . isEmpty ( ) ? static_cast < QTextCodec * > ( 0 ) : VCSBase : : VCSBaseEditorWidget : : getCodec ( source ) ;
2008-12-02 12:01:29 +01:00
2011-03-25 16:39:33 +01:00
const QString diffName = p . files . count ( ) = = 1 & & p . diffName . isEmpty ( ) ?
QFileInfo ( p . files . front ( ) ) . fileName ( ) : p . diffName ;
2008-12-02 12:01:29 +01:00
QStringList args ( QLatin1String ( " diff " ) ) ;
2011-03-25 16:39:33 +01:00
args . append ( p . arguments ) ;
args < < p . files ;
2008-12-02 12:01:29 +01:00
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
2011-03-25 16:39:33 +01:00
runSvn ( p . workingDir , args , m_settings . timeOutMS ( ) , 0 , 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
2011-03-31 10:57:33 +02:00
const QString tag = VCSBase : : VCSBaseEditorWidget : : editorTag ( VCSBase : : DiffOutput , p . workingDir , p . files ) ;
// Show in the same editor if diff has been executed before
if ( Core : : IEditor * existingEditor = VCSBase : : VCSBaseEditorWidget : : locateEditorByTag ( tag ) ) {
existingEditor - > createNew ( response . stdOut ) ;
Core : : EditorManager : : instance ( ) - > activateEditor ( existingEditor , Core : : EditorManager : : ModeSwitch ) ;
setDiffBaseDirectory ( existingEditor , p . workingDir ) ;
return ;
2008-12-02 12:01:29 +01:00
}
2011-03-25 16:39:33 +01: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 ) ;
2011-03-25 16:39:33 +01:00
setDiffBaseDirectory ( editor , p . workingDir ) ;
2011-03-31 10:57:33 +02:00
VCSBase : : VCSBaseEditorWidget : : tagEditor ( editor , tag ) ;
2011-03-25 16:39:33 +01:00
SubversionEditor * diffEditorWidget = qobject_cast < SubversionEditor * > ( editor - > widget ( ) ) ;
QTC_ASSERT ( diffEditorWidget , return ; )
// Wire up the parameter widget to trigger a re-run on
// parameter change and 'revert' from inside the diff editor.
diffEditorWidget - > setRevertDiffChunkEnabled ( true ) ;
SubversionDiffParameterWidget * pw = new SubversionDiffParameterWidget ( p ) ;
connect ( pw , SIGNAL ( reRunDiff ( Subversion : : Internal : : SubversionDiffParameters ) ) ,
this , SLOT ( svnDiff ( Subversion : : Internal : : SubversionDiffParameters ) ) ) ;
connect ( diffEditorWidget , SIGNAL ( diffChunkReverted ( VCSBase : : DiffChunk ) ) ,
pw , SLOT ( triggerReRun ( ) ) ) ;
diffEditorWidget - > setConfigurationWidget ( pw ) ;
2008-12-02 12:01:29 +01:00
}
SubversionSubmitEditor * SubversionPlugin : : openSubversionSubmitEditor ( const QString & fileName )
{
2010-09-14 15:15:57 +02:00
Core : : IEditor * editor = Core : : EditorManager : : instance ( ) - > openEditor ( fileName ,
QLatin1String ( Constants : : SUBVERSIONCOMMITEDITOR_ID ) ,
Core : : EditorManager : : ModeSwitch ) ;
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
{
2010-02-12 16:03:08 +01:00
if ( ! enableMenuAction ( as , m_menuAction ) ) {
m_commandLocator - > setEnabled ( false ) ;
2009-12-08 14:26:41 +01:00
return ;
2010-02-12 16:03:08 +01:00
}
const bool hasTopLevel = currentState ( ) . hasTopLevel ( ) ;
m_commandLocator - > setEnabled ( hasTopLevel ) ;
m_logRepositoryAction - > setEnabled ( hasTopLevel ) ;
2010-01-07 11:33:30 +01:00
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 ) ;
2010-04-27 12:16:51 +02:00
m_commitProjectAction - > setParameter ( projectName ) ;
2009-12-08 16:50:27 +01:00
const bool repoEnabled = currentState ( ) . hasTopLevel ( ) ;
m_commitAllAction - > setEnabled ( repoEnabled ) ;
m_describeAction - > setEnabled ( repoEnabled ) ;
2010-01-11 17:17:16 +01:00
m_revertRepositoryAction - > setEnabled ( repoEnabled ) ;
2010-04-27 12:16:51 +02:00
m_diffRepositoryAction - > setEnabled ( repoEnabled ) ;
m_statusRepositoryAction - > setEnabled ( repoEnabled ) ;
m_updateRepositoryAction - > setEnabled ( repoEnabled ) ;
2009-12-08 16:50:27 +01:00
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
}
2010-01-11 17:17:16 +01:00
void SubversionPlugin : : revertAll ( )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return )
const QString title = tr ( " Revert repository " ) ;
2010-10-08 10:56:31 +02:00
if ( QMessageBox : : warning ( 0 , title , tr ( " Revert all pending changes to the repository? " ) ,
2010-01-11 17:17:16 +01:00
QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : No )
return ;
// NoteL: Svn "revert ." doesn not work.
QStringList args ;
args < < QLatin1String ( " revert " ) < < QLatin1String ( " --recursive " ) < < state . topLevel ( ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse revertResponse =
runSvn ( state . topLevel ( ) , args , m_settings . timeOutMS ( ) ,
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2010-01-11 17:17:16 +01:00
if ( revertResponse . error ) {
QMessageBox : : warning ( 0 , title , tr ( " Revert failed: %1 " ) . arg ( revertResponse . message ) , QMessageBox : : Ok ) ;
} else {
subVersionControl ( ) - > emitRepositoryChanged ( state . topLevel ( ) ) ;
}
}
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
2010-05-21 17:46:00 +02:00
const SubversionResponse diffResponse =
runSvn ( state . currentFileTopLevel ( ) , args , m_settings . timeOutMS ( ) , 0 ) ;
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
2010-05-21 17:46:00 +02:00
const SubversionResponse revertResponse =
runSvn ( state . currentFileTopLevel ( ) , args , m_settings . timeOutMS ( ) ,
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2009-06-18 14:30:04 +02:00
if ( ! revertResponse . error ) {
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
}
2010-04-27 12:16:51 +02:00
void SubversionPlugin : : startCommitProject ( )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasProject ( ) , return ) ;
startCommit ( state . currentProjectPath ( ) ) ;
}
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 ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
runSvn ( workingDir , args , m_settings . timeOutMS ( ) , 0 ) ;
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 ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
runSvn ( m_commitRepository , args , m_settings . longTimeOutMS ( ) ,
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
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-04-27 12:16:51 +02:00
void SubversionPlugin : : diffRepository ( )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return )
svnDiff ( state . topLevel ( ) , QStringList ( ) ) ;
}
void SubversionPlugin : : statusRepository ( )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return )
svnStatus ( state . topLevel ( ) ) ;
}
void SubversionPlugin : : updateRepository ( )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return )
svnUpdate ( state . topLevel ( ) ) ;
}
void SubversionPlugin : : svnStatus ( const QString & workingDir , const QStringList & relativePaths )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return )
QStringList args ( QLatin1String ( " status " ) ) ;
if ( ! relativePaths . isEmpty ( ) )
args . append ( relativePaths ) ;
VCSBase : : VCSBaseOutputWindow * outwin = VCSBase : : VCSBaseOutputWindow : : instance ( ) ;
outwin - > setRepository ( workingDir ) ;
2010-05-21 17:46:00 +02:00
runSvn ( workingDir , args , m_settings . timeOutMS ( ) ,
2010-08-19 16:56:23 +02:00
ShowStdOutInLogWindow | ShowSuccessMessage ) ;
2010-04-27 12:16:51 +02:00
outwin - > clearRepository ( ) ;
}
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
{
// 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
2010-11-03 10:20:49 +01:00
// subversion stores log in UTF-8 and returns it back in user system locale.
// So we do not need to encode it.
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
runSvn ( workingDir , args , m_settings . timeOutMS ( ) ,
2010-11-03 10:20:49 +01:00
SshPasswordPrompt , 0 /*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
2011-02-21 16:02:26 +01:00
const QString id = VCSBase : : VCSBaseEditorWidget : : getTitleId ( workingDir , files ) ;
2011-03-31 10:57:33 +02:00
const QString tag = VCSBase : : VCSBaseEditorWidget : : editorTag ( VCSBase : : LogOutput , workingDir , files ) ;
if ( Core : : IEditor * editor = VCSBase : : VCSBaseEditorWidget : : locateEditorByTag ( tag ) ) {
2008-12-02 12:01:29 +01:00
editor - > createNew ( response . stdOut ) ;
2010-09-14 15:15:57 +02:00
Core : : EditorManager : : instance ( ) - > activateEditor ( editor , Core : : EditorManager : : ModeSwitch ) ;
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 ) ;
2011-02-21 16:02:26 +01:00
const QString source = VCSBase : : VCSBaseEditorWidget : : getSource ( workingDir , files ) ;
2010-11-03 10:20:49 +01:00
Core : : IEditor * newEditor = showOutputInEditor ( title , response . stdOut , VCSBase : : LogOutput , source , /*codec*/ 0 ) ;
2011-03-31 10:57:33 +02:00
VCSBase : : VCSBaseEditorWidget : : tagEditor ( newEditor , tag ) ;
2010-01-07 11:33:30 +01:00
if ( enableAnnotationContextMenu )
2011-02-21 16:02:26 +01:00
VCSBase : : VCSBaseEditorWidget : : 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 ) ;
2010-04-27 12:16:51 +02:00
svnUpdate ( state . currentProjectTopLevel ( ) , state . relativeCurrentProject ( ) ) ;
}
2008-12-02 12:01:29 +01:00
2010-04-27 12:16:51 +02:00
void SubversionPlugin : : svnUpdate ( const QString & workingDir , const QStringList & relativePaths )
{
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 ) ) ;
2010-04-27 12:16:51 +02:00
if ( ! relativePaths . isEmpty ( ) )
args . append ( relativePaths ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
runSvn ( workingDir , args , m_settings . longTimeOutMS ( ) ,
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2009-12-08 16:50:27 +01:00
if ( ! response . error )
2010-04-27 12:16:51 +02:00
subVersionControl ( ) - > emitRepositoryChanged ( workingDir ) ;
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 ) ;
2010-03-19 17:22:18 +01:00
vcsAnnotate ( 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 ) ;
2010-03-19 17:22:18 +01:00
vcsAnnotate ( fi . absolutePath ( ) , fi . fileName ( ) , revision , lineNr ) ;
2010-01-06 17:24:40 +01:00
}
2010-03-19 17:22:18 +01:00
void SubversionPlugin : : vcsAnnotate ( const QString & workingDir , const QString & file ,
2010-01-06 17:24:40 +01:00
const QString & revision /* = QString() */ ,
int lineNumber /* = -1 */ )
2008-12-02 12:01:29 +01:00
{
2011-02-21 16:02:26 +01:00
const QString source = VCSBase : : VCSBaseEditorWidget : : getSource ( workingDir , file ) ;
QTextCodec * codec = VCSBase : : VCSBaseEditorWidget : : getCodec ( source ) ;
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 ) ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
runSvn ( workingDir , args , m_settings . timeOutMS ( ) ,
2010-11-17 17:20:22 +01:00
SshPasswordPrompt | ForceCLocale , 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
2010-01-06 17:24:40 +01:00
if ( lineNumber < = 0 )
2011-02-21 16:02:26 +01:00
lineNumber = VCSBase : : VCSBaseEditorWidget : : lineNumberOfCurrentEditor ( source ) ;
2010-01-06 17:24:40 +01:00
// Determine id
2011-03-31 10:57:33 +02:00
const QStringList files = QStringList ( file ) ;
const QString id = VCSBase : : VCSBaseEditorWidget : : getTitleId ( workingDir , files , revision ) ;
const QString tag = VCSBase : : VCSBaseEditorWidget : : editorTag ( VCSBase : : AnnotateOutput , workingDir , files ) ;
if ( Core : : IEditor * editor = VCSBase : : VCSBaseEditorWidget : : locateEditorByTag ( tag ) ) {
2008-12-02 12:01:29 +01:00
editor - > createNew ( response . stdOut ) ;
2011-02-21 16:02:26 +01:00
VCSBase : : VCSBaseEditorWidget : : gotoLineOfEditor ( editor , lineNumber ) ;
2010-09-14 15:15:57 +02:00
Core : : EditorManager : : instance ( ) - > activateEditor ( editor , Core : : EditorManager : : ModeSwitch ) ;
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 ) ;
2011-03-31 10:57:33 +02:00
VCSBase : : VCSBaseEditorWidget : : tagEditor ( newEditor , tag ) ;
2011-02-21 16:02:26 +01:00
VCSBase : : VCSBaseEditorWidget : : 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 ) ;
2010-04-27 12:16:51 +02:00
svnStatus ( state . currentFileTopLevel ( ) , state . relativeCurrentProject ( ) ) ;
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 ) ;
2010-05-20 16:24:39 +02:00
QString topLevel ;
const bool manages = managesDirectory ( fi . isDir ( ) ? source : fi . absolutePath ( ) , & topLevel ) ;
if ( ! manages | | topLevel . isEmpty ( ) )
2008-12-02 12:01:29 +01:00
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 ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse logResponse =
runSvn ( topLevel , args , m_settings . timeOutMS ( ) , SshPasswordPrompt ) ;
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 ) ;
2011-02-21 16:02:26 +01:00
QTextCodec * codec = VCSBase : : VCSBaseEditorWidget : : getCodec ( source ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
runSvn ( topLevel , args , m_settings . timeOutMS ( ) ,
SshPasswordPrompt , 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 ;
2011-03-31 10:57:33 +02:00
const QString tag = VCSBase : : VCSBaseEditorWidget : : editorTag ( VCSBase : : DiffOutput , source , QStringList ( ) , changeNr ) ;
if ( Core : : IEditor * editor = VCSBase : : VCSBaseEditorWidget : : locateEditorByTag ( tag ) ) {
2009-02-10 08:38:12 +01:00
editor - > createNew ( description ) ;
2010-09-14 15:15:57 +02:00
Core : : EditorManager : : instance ( ) - > activateEditor ( editor , Core : : EditorManager : : ModeSwitch ) ;
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 ) ;
2011-03-31 10:57:33 +02:00
VCSBase : : VCSBaseEditorWidget : : tagEditor ( newEditor , tag ) ;
2008-12-02 12:01:29 +01:00
}
}
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
}
2010-06-08 10:04:23 +02:00
SubversionResponse
SubversionPlugin : : runSvn ( const QString & workingDir ,
const QStringList & arguments ,
int timeOut ,
unsigned flags ,
QTextCodec * outputCodec )
{
return m_settings . hasAuthentication ( ) ?
runSvn ( workingDir , m_settings . user , m_settings . password ,
arguments , timeOut , flags , outputCodec ) :
runSvn ( workingDir , QString ( ) , QString ( ) ,
arguments , timeOut , flags , outputCodec ) ;
}
// Add authorization options to the command line arguments.
// SVN pre 1.5 does not accept "--userName" for "add", which is most likely
// an oversight. As no password is needed for the option, generally omit it.
QStringList SubversionPlugin : : addAuthenticationOptions ( const QStringList & args ,
const QString & userName , const QString & password )
{
if ( userName . isEmpty ( ) )
return args ;
if ( ! args . empty ( ) & & args . front ( ) = = QLatin1String ( " add " ) )
return args ;
QStringList rc ;
rc . push_back ( QLatin1String ( " --username " ) ) ;
rc . push_back ( userName ) ;
if ( ! password . isEmpty ( ) ) {
rc . push_back ( QLatin1String ( " --password " ) ) ;
rc . push_back ( password ) ;
}
rc . append ( args ) ;
return rc ;
}
2009-12-08 16:50:27 +01:00
SubversionResponse SubversionPlugin : : runSvn ( const QString & workingDir ,
2010-06-08 10:04:23 +02:00
const QString & userName , const QString & password ,
const QStringList & arguments , int timeOut ,
unsigned flags , QTextCodec * outputCodec )
2008-12-02 12:01:29 +01:00
{
const QString executable = m_settings . svnCommand ;
SubversionResponse response ;
if ( executable . isEmpty ( ) ) {
response . error = true ;
response . message = tr ( " No subversion executable specified! " ) ;
return response ;
}
2010-06-08 10:04:23 +02:00
const QStringList completeArguments = SubversionPlugin : : addAuthenticationOptions ( arguments , userName , password ) ;
2010-05-21 17:46:00 +02:00
const Utils : : SynchronousProcessResponse sp_resp =
VCSBase : : VCSBasePlugin : : runVCS ( workingDir , executable ,
2010-06-08 10:04:23 +02:00
completeArguments , timeOut , flags , outputCodec ) ;
2008-12-02 12:01:29 +01:00
2010-05-21 17:46:00 +02:00
response . error = sp_resp . result ! = Utils : : SynchronousProcessResponse : : Finished ;
if ( response . error )
response . message = sp_resp . exitMessage ( executable , timeOut ) ;
2008-12-02 12:01:29 +01:00
response . stdErr = sp_resp . stdErr ;
response . stdOut = sp_resp . stdOut ;
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 ;
2010-06-07 14:53:28 +02:00
e - > setForceReadOnly ( true ) ;
2008-12-02 12:01:29 +01:00
s . replace ( QLatin1Char ( ' ' ) , QLatin1Char ( ' _ ' ) ) ;
e - > setSuggestedFileName ( s ) ;
if ( ! source . isEmpty ( ) )
e - > setSource ( source ) ;
if ( codec )
e - > setCodec ( codec ) ;
2011-02-21 16:02:26 +01:00
Core : : IEditor * ie = e - > editor ( ) ;
2010-09-14 15:15:57 +02:00
Core : : EditorManager : : instance ( ) - > activateEditor ( ie , Core : : EditorManager : : ModeSwitch ) ;
2009-03-10 11:02:12 +01:00
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 ) ;
2011-04-15 17:43:44 +02:00
subVersionControl ( ) - > emitConfigurationChanged ( ) ;
2008-12-02 12:01:29 +01:00
}
}
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 ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
runSvn ( workingDir , args , m_settings . timeOutMS ( ) ,
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
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 ) ;
2010-05-20 16:24:39 +02:00
if ( ! checkSVNSubDir ( QDir ( path ) ) ) {
2010-01-08 12:55:30 +01:00
QStringList addDirArgs ;
addDirArgs < < QLatin1String ( " add " ) < < QLatin1String ( " --non-recursive " ) < < QDir : : toNativeSeparators ( path ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse addDirResponse =
runSvn ( workingDir , addDirArgs , m_settings . timeOutMS ( ) ,
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2010-01-08 12:55:30 +01:00
if ( addDirResponse . error )
return false ;
}
}
}
// Add file
QStringList args ;
args < < QLatin1String ( " add " ) < < QDir : : toNativeSeparators ( rawFileName ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
runSvn ( workingDir , args , m_settings . timeOutMS ( ) ,
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2010-01-08 12:55:30 +01:00
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 ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
runSvn ( workingDir , args , m_settings . timeOutMS ( ) ,
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2008-12-02 12:01:29 +01:00
return ! response . error ;
}
2010-05-11 14:13:38 +02:00
bool SubversionPlugin : : vcsMove ( const QString & workingDir , const QString & from , const QString & to )
{
QStringList args ( QLatin1String ( " move " ) ) ;
args < < QDir : : toNativeSeparators ( from ) < < QDir : : toNativeSeparators ( to ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
runSvn ( workingDir , args , m_settings . timeOutMS ( ) ,
2010-11-22 14:53:20 +01:00
SshPasswordPrompt | ShowStdOutInLogWindow | FullySynchronously ) ;
2010-05-11 14:13:38 +02:00
return ! response . error ;
}
2010-09-29 12:16:35 +02:00
bool SubversionPlugin : : vcsCheckout ( const QString & directory , const QByteArray & url )
{
QUrl tempUrl ;
tempUrl . setEncodedUrl ( url ) ;
QString username = tempUrl . userName ( ) ;
QString password = tempUrl . password ( ) ;
QStringList args = QStringList ( QLatin1String ( " checkout " ) ) ;
args < < QLatin1String ( nonInteractiveOptionC ) ;
if ( ! username . isEmpty ( ) & & ! password . isEmpty ( ) )
{
// If url contains username and password we have to use separate username and password
// arguments instead of passing those in the url. Otherwise the subversion 'non-interactive'
// authentication will always fail (if the username and password data are not stored locally),
// if for example we are logging into a new host for the first time using svn. There seems to
// be a bug in subversion, so this might get fixed in the future.
tempUrl . setUserInfo ( " " ) ;
args < < tempUrl . toEncoded ( ) < < directory ;
2010-09-29 12:16:37 +02:00
const SubversionResponse response = runSvn ( directory , username , password , args ,
m_settings . longTimeOutMS ( ) ,
VCSBase : : VCSBasePlugin : : SshPasswordPrompt ) ;
2010-09-29 12:16:35 +02:00
return ! response . error ;
} else {
args < < url < < directory ;
const SubversionResponse response = runSvn ( directory , args , m_settings . longTimeOutMS ( ) ,
2010-09-29 12:16:37 +02:00
VCSBase : : VCSBasePlugin : : SshPasswordPrompt ) ;
2010-09-29 12:16:35 +02:00
return ! response . error ;
}
}
QString SubversionPlugin : : vcsGetRepositoryURL ( const QString & directory )
{
QXmlStreamReader xml ;
QStringList args = QStringList ( QLatin1String ( " info " ) ) ;
args < < QLatin1String ( " --xml " ) ;
const SubversionResponse response = runSvn ( directory , args , m_settings . longTimeOutMS ( ) , SuppressCommandLogging ) ;
xml . addData ( response . stdOut ) ;
bool repo = false ;
bool root = false ;
while ( ! xml . atEnd ( ) & & ! xml . hasError ( ) ) {
switch ( xml . readNext ( ) ) {
case QXmlStreamReader : : StartDocument :
break ;
case QXmlStreamReader : : StartElement :
if ( xml . name ( ) = = QLatin1String ( " repository " ) )
repo = true ;
else if ( repo & & xml . name ( ) = = QLatin1String ( " root " ) )
root = true ;
break ;
case QXmlStreamReader : : EndElement :
if ( xml . name ( ) = = QLatin1String ( " repository " ) )
repo = false ;
else if ( repo & & xml . name ( ) = = QLatin1String ( " root " ) )
root = false ;
break ;
case QXmlStreamReader : : Characters :
if ( repo & & root )
return xml . text ( ) . toString ( ) ;
break ;
default :
break ;
}
}
return QString ( ) ;
}
2008-12-02 12:01:29 +01:00
/* 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 " . */
2010-05-20 16:24:39 +02:00
bool SubversionPlugin : : managesDirectory ( const QString & directory , QString * topLevel /* = 0 */ ) const
2008-12-02 12:01:29 +01:00
{
const QDir dir ( directory ) ;
2010-05-20 16:24:39 +02:00
if ( topLevel )
topLevel - > clear ( ) ;
bool manages = false ;
do {
if ( ! dir . exists ( ) | | ! checkSVNSubDir ( dir ) )
break ;
manages = true ;
if ( ! topLevel )
break ;
/* 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 = dir ;
for ( QDir parentDir = lastDirectory ; parentDir . cdUp ( ) ; lastDirectory = parentDir ) {
if ( ! checkSVNSubDir ( parentDir ) ) {
* topLevel = lastDirectory . absolutePath ( ) ;
break ;
}
}
} while ( false ) ;
if ( Subversion : : Constants : : debug ) {
QDebug nsp = qDebug ( ) . nospace ( ) ;
nsp < < " SubversionPlugin::managesDirectory " < < directory < < manages ;
if ( topLevel )
nsp < < * topLevel ;
}
return manages ;
2008-12-02 12:01:29 +01:00
}
2010-05-20 16:24:39 +02:00
// Check whether SVN management subdirs exist.
bool SubversionPlugin : : checkSVNSubDir ( const QDir & directory ) const
2008-12-02 12:01:29 +01:00
{
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
}
2009-12-08 14:26:41 +01:00
SubversionControl * SubversionPlugin : : subVersionControl ( ) const
{
return static_cast < SubversionControl * > ( versionControl ( ) ) ;
}
2011-03-25 16:39:33 +01:00
} // Internal
} // Subversion
Q_EXPORT_PLUGIN ( Subversion : : Internal : : SubversionPlugin )
# include "subversionplugin.moc"