2012-10-02 09:12:39 +02:00
/****************************************************************************
2008-12-02 12:01:29 +01:00
* *
2014-01-07 13:27:11 +01:00
* * Copyright ( C ) 2014 Digia Plc and / or its subsidiary ( - ies ) .
2012-10-02 09:12:39 +02:00
* * Contact : http : //www.qt-project.org/legal
2008-12-02 12:01:29 +01:00
* *
2012-10-02 09:12:39 +02:00
* * This file is part of Qt Creator .
2008-12-02 12:01:29 +01:00
* *
2012-10-02 09:12:39 +02:00
* * Commercial License Usage
* * Licensees holding valid commercial Qt licenses may use this file in
* * accordance with the commercial license agreement provided with the
* * Software or , alternatively , in accordance with the terms contained in
* * a written agreement between you and Digia . For licensing terms and
* * conditions see http : //qt.digia.com/licensing. For further information
* * use the contact form at http : //qt.digia.com/contact-us.
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01:00
* * GNU Lesser General Public License Usage
2012-10-02 09:12:39 +02: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.
* *
* * In addition , as a special exception , Digia gives you certain additional
* * rights . These rights are described in the Digia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
* * version 1.1 , included in the file LGPL_EXCEPTION . txt in this package .
* *
2012-10-02 09:12:39 +02: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"
2013-09-27 15:39:16 +02:00
# include "subversionclient.h"
2008-12-02 12:01:29 +01:00
# 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>
2011-03-30 15:15:15 +02:00
# include <utils/fileutils.h>
2012-08-23 15:53:58 +02:00
# include <utils/hostosinfo.h>
2008-12-02 12:01:29 +01:00
# include <coreplugin/icore.h>
# include <coreplugin/coreconstants.h>
2012-02-14 16:43:51 +01:00
# include <coreplugin/documentmanager.h>
2008-12-02 12:01:29 +01:00
# 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>
2011-09-05 16:10:37 +02:00
# include <coreplugin/id.h>
2008-12-02 12:01:29 +01:00
# include <coreplugin/editormanager/editormanager.h>
2010-02-12 16:03:08 +01:00
2014-01-13 16:17:34 +01:00
# include <coreplugin/locator/commandlocator.h>
2010-02-12 16:03:08 +01:00
2008-12-09 15:25:01 +01:00
# include <utils/qtcassert.h>
2008-12-02 12:01:29 +01:00
2012-02-15 10:42:41 +01:00
# include <QDebug>
# include <QDir>
# include <QFileInfo>
# include <QTextCodec>
# include <QtPlugin>
# include <QProcessEnvironment>
# include <QUrl>
# include <QXmlStreamReader>
# include <QAction>
# include <QFileDialog>
# include <QMenu>
# include <QMessageBox>
# include <QInputDialog>
2009-02-09 17:33:31 +01:00
# include <limits.h>
2008-12-02 12:01:29 +01:00
2013-01-19 23:19:38 +02:00
# ifdef WITH_TESTS
# include <QTest>
# endif
2011-03-25 16:39:33 +01:00
namespace Subversion {
namespace Internal {
2008-12-02 12:01:29 +01:00
2011-11-02 16:45:13 +01:00
static const char CMD_ID_SUBVERSION_MENU [ ] = " Subversion.Menu " ;
static const char CMD_ID_ADD [ ] = " Subversion.Add " ;
static const char CMD_ID_DELETE_FILE [ ] = " Subversion.Delete " ;
static const char CMD_ID_REVERT [ ] = " Subversion.Revert " ;
static const char CMD_ID_DIFF_PROJECT [ ] = " Subversion.DiffAll " ;
static const char CMD_ID_DIFF_CURRENT [ ] = " Subversion.DiffCurrent " ;
static const char CMD_ID_COMMIT_ALL [ ] = " Subversion.CommitAll " ;
static const char CMD_ID_REVERT_ALL [ ] = " Subversion.RevertAll " ;
static const char CMD_ID_COMMIT_CURRENT [ ] = " Subversion.CommitCurrent " ;
static const char CMD_ID_FILELOG_CURRENT [ ] = " Subversion.FilelogCurrent " ;
static const char CMD_ID_ANNOTATE_CURRENT [ ] = " Subversion.AnnotateCurrent " ;
static const char CMD_ID_STATUS [ ] = " Subversion.Status " ;
static const char CMD_ID_PROJECTLOG [ ] = " Subversion.ProjectLog " ;
static const char CMD_ID_REPOSITORYLOG [ ] = " Subversion.RepositoryLog " ;
static const char CMD_ID_REPOSITORYUPDATE [ ] = " Subversion.RepositoryUpdate " ;
static const char CMD_ID_REPOSITORYDIFF [ ] = " Subversion.RepositoryDiff " ;
static const char CMD_ID_REPOSITORYSTATUS [ ] = " Subversion.RepositoryStatus " ;
static const char CMD_ID_UPDATE [ ] = " Subversion.Update " ;
static const char CMD_ID_COMMIT_PROJECT [ ] = " Subversion.CommitProject " ;
static const char CMD_ID_DESCRIBE [ ] = " Subversion.Describe " ;
2008-12-02 12:01:29 +01:00
2011-11-02 16:45:13 +01:00
static const char nonInteractiveOptionC [ ] = " --non-interactive " ;
2009-05-05 10:16:09 +02:00
2010-05-21 17:46:00 +02:00
2012-01-07 12:31:48 +01:00
static const VcsBase : : VcsBaseEditorParameters editorParameters [ ] = {
2008-12-02 12:01:29 +01:00
{
2013-05-22 21:03:37 +03:00
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
2013-05-21 23:37:47 +03:00
" text/vnd.qtcreator.svn.log " } ,
2012-01-07 12:31:48 +01:00
{ 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
2013-05-21 23:37:47 +03:00
" text/vnd.qtcreator.svn.annotation " } ,
2012-01-07 12:31:48 +01:00
{ 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
2013-05-21 20:54:26 +03:00
" text/x-patch " }
2008-12-02 12:01:29 +01:00
} ;
// Utility to find a parameter set by type
2012-01-07 12:31:48 +01:00
static inline const VcsBase : : VcsBaseEditorParameters * findType ( int ie )
2008-12-02 12:01:29 +01:00
{
2012-01-07 12:31:48 +01:00
const VcsBase : : EditorContentType et = static_cast < VcsBase : : EditorContentType > ( ie ) ;
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 )
{
2012-09-21 13:54:38 +02:00
return c ? QString : : fromLatin1 ( c - > name ( ) ) : QString : : fromLatin1 ( " Null codec " ) ;
2008-12-02 12:01:29 +01:00
}
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 " ) ) ;
2012-08-23 15:53:58 +02:00
if ( Utils : : HostOsInfo : : isWindowsHost ( ) )
// Option on Windows systems to avoid hassle with some IDEs
rc . push_back ( QLatin1String ( " _svn " ) ) ;
2009-05-26 12:25:32 +02:00
return rc ;
}
2008-12-02 12:01:29 +01:00
// ------------- SubversionPlugin
SubversionPlugin * SubversionPlugin : : m_subversionPluginInstance = 0 ;
SubversionPlugin : : SubversionPlugin ( ) :
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 ( )
{
2013-09-27 15:39:16 +02:00
delete m_client ;
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 ( ) ;
}
2012-01-07 12:31:48 +01:00
static const VcsBase : : VcsBaseSubmitEditorParameters submitParameters = {
2008-12-02 12:01:29 +01:00
Subversion : : Constants : : SUBVERSION_SUBMIT_MIMETYPE ,
2010-01-08 09:48:54 +01:00
Subversion : : Constants : : SUBVERSIONCOMMITEDITOR_ID ,
Subversion : : Constants : : SUBVERSIONCOMMITEDITOR_DISPLAY_NAME ,
2013-01-11 10:45:00 +02:00
Subversion : : Constants : : SUBVERSIONCOMMITEDITOR ,
VcsBase : : VcsBaseSubmitEditorParameters : : DiffFiles
2008-12-02 12:01:29 +01:00
} ;
2009-12-08 14:26:41 +01:00
bool SubversionPlugin : : initialize ( const QStringList & /*arguments */ , QString * errorMessage )
2008-12-02 12:01:29 +01:00
{
2012-01-07 12:31:48 +01:00
typedef VcsBase : : VcsSubmitEditorFactory < SubversionSubmitEditor > SubversionSubmitEditorFactory ;
typedef VcsBase : : VcsEditorFactory < SubversionEditor > SubversionEditorFactory ;
2008-12-02 12:01:29 +01:00
using namespace Constants ;
using namespace Core : : Constants ;
using namespace ExtensionSystem ;
2011-06-04 21:07:34 +02:00
initializeVcs ( new SubversionControl ( this ) ) ;
2009-12-08 14:26:41 +01:00
2008-12-02 12:01:29 +01:00
m_subversionPluginInstance = this ;
2013-08-30 16:38:57 +02:00
if ( ! Core : : MimeDatabase : : addMimeTypes ( QLatin1String ( " :/trolltech.subversion/Subversion.mimetypes.xml " ) , errorMessage ) )
2008-12-02 12:01:29 +01:00
return false ;
2013-02-27 13:25:21 +01:00
m_settings . readSettings ( Core : : ICore : : settings ( ) ) ;
2013-09-27 15:39:16 +02:00
m_client = new SubversionClient ( & m_settings ) ;
2008-12-02 12:01:29 +01:00
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 ) ) ;
2012-01-07 12:31:48 +01:00
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 prefix = QLatin1String ( " svn " ) ;
2014-01-13 16:17:34 +01:00
m_commandLocator = new Core : : CommandLocator ( " Subversion " , prefix , prefix ) ;
2010-02-12 16:03:08 +01:00
addAutoReleasedObject ( m_commandLocator ) ;
2008-12-02 12:01:29 +01:00
//register actions
2012-05-24 13:49:06 +02:00
Core : : ActionContainer * toolsContainer = Core : : ActionManager : : actionContainer ( M_TOOLS ) ;
2008-12-02 12:01:29 +01:00
2009-01-14 12:39:59 +01:00
Core : : ActionContainer * subversionMenu =
2012-05-24 13:49:06 +02:00
Core : : ActionManager : : 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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_diffCurrentAction ,
2010-01-11 17:17:16 +01:00
CMD_ID_DIFF_CURRENT , globalcontext ) ;
2009-01-14 13:17:53 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2012-05-23 13:25:51 +02:00
command - > setDefaultKeySequence ( QKeySequence ( Core : : UseMacShortcuts ? tr ( " Meta+S,Meta+D " ) : tr ( " Alt+S,Alt+D " ) ) ) ;
2010-01-11 17:17:16 +01:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_filelogCurrentAction ,
2010-01-11 17:17:16 +01:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_annotateCurrentAction ,
2010-01-11 17:17:16 +01:00
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
2012-06-05 14:22:20 +02:00
subversionMenu - > addSeparator ( 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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : 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 ) ;
2012-05-23 13:25:51 +02:00
command - > setDefaultKeySequence ( QKeySequence ( Core : : UseMacShortcuts ? tr ( " Meta+S,Meta+A " ) : tr ( " Alt+S,Alt+A " ) ) ) ;
2010-01-11 17:17:16 +01:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : 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 ) ;
2012-05-23 13:25:51 +02:00
command - > setDefaultKeySequence ( QKeySequence ( Core : : UseMacShortcuts ? tr ( " Meta+S,Meta+C " ) : tr ( " Alt+S,Alt+C " ) ) ) ;
2008-12-02 12:01:29 +01:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_deleteAction , CMD_ID_DELETE_FILE ,
2010-01-11 17:17:16 +01:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_revertAction , CMD_ID_REVERT ,
2010-01-11 17:17:16 +01:00
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
2012-06-05 14:22:20 +02:00
subversionMenu - > addSeparator ( 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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_diffProjectAction , CMD_ID_DIFF_PROJECT ,
2010-01-11 17:17:16 +01:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : 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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_logProjectAction , CMD_ID_PROJECTLOG , globalcontext ) ;
2010-01-07 11:33:30 +01:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : 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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_commitProjectAction , CMD_ID_COMMIT_PROJECT , globalcontext ) ;
2010-04-27 12:16:51 +02:00
connect ( m_commitProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( startCommitProject ( ) ) ) ;
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
subversionMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
2012-06-05 14:22:20 +02:00
subversionMenu - > addSeparator ( globalcontext ) ;
2010-01-11 17:17:16 +01:00
2010-04-27 12:16:51 +02:00
m_diffRepositoryAction = new QAction ( tr ( " Diff Repository " ) , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_diffRepositoryAction , CMD_ID_REPOSITORYDIFF , globalcontext ) ;
2010-04-27 12:16:51 +02:00
connect ( m_diffRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffRepository ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
m_statusRepositoryAction = new QAction ( tr ( " Repository Status " ) , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_statusRepositoryAction , CMD_ID_REPOSITORYSTATUS , globalcontext ) ;
2010-04-27 12:16:51 +02:00
connect ( m_statusRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( statusRepository ( ) ) ) ;
subversionMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
m_logRepositoryAction = new QAction ( tr ( " Log Repository " ) , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_logRepositoryAction , CMD_ID_REPOSITORYLOG , globalcontext ) ;
2010-01-07 11:33:30 +01:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_updateRepositoryAction , CMD_ID_REPOSITORYUPDATE , globalcontext ) ;
2010-04-27 12:16:51 +02:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_commitAllAction , CMD_ID_COMMIT_ALL ,
2010-01-11 17:17:16 +01:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_describeAction , CMD_ID_DESCRIBE , globalcontext ) ;
2010-04-27 12:16:51 +02:00
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 ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_revertRepositoryAction , CMD_ID_REVERT_ALL ,
2010-01-11 17:17:16 +01:00
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
2012-01-07 12:31:48 +01:00
m_submitCurrentLogAction = new QAction ( VcsBase : : VcsBaseSubmitEditor : : submitIcon ( ) , tr ( " Commit " ) , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : 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 ( ) ) ) ;
2012-01-07 12:31:48 +01:00
m_submitDiffAction = new QAction ( VcsBase : : VcsBaseSubmitEditor : : diffIcon ( ) , tr ( " Diff &Selected Files " ) , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_submitDiffAction , Constants : : DIFF_SELECTED , svncommitcontext ) ;
2008-12-02 12:01:29 +01:00
m_submitUndoAction = new QAction ( tr ( " &Undo " ) , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_submitUndoAction , Core : : Constants : : UNDO , svncommitcontext ) ;
2008-12-02 12:01:29 +01:00
m_submitRedoAction = new QAction ( tr ( " &Redo " ) , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_submitRedoAction , Core : : Constants : : REDO , svncommitcontext ) ;
2008-12-02 12:01:29 +01:00
return true ;
}
2013-04-18 12:06:43 +02:00
bool SubversionPlugin : : submitEditorAboutToClose ( )
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 ;
2013-04-18 12:06:43 +02:00
SubversionSubmitEditor * editor = qobject_cast < SubversionSubmitEditor * > ( submitEditor ( ) ) ;
QTC_ASSERT ( editor , return true ) ;
Core : : IDocument * editorDocument = editor - > document ( ) ;
QTC_ASSERT ( editorDocument , return true ) ;
2008-12-02 12:01:29 +01:00
// Submit editor closing. Make it write out the commit message
// and retrieve files
2013-07-04 13:30:26 +02:00
const QFileInfo editorFile ( editorDocument - > filePath ( ) ) ;
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 ;
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBaseSubmitEditor : : PromptSubmitResult answer =
2009-03-19 17:40:01 +01:00
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? " ) ,
2013-02-27 13:25:21 +01:00
newSettings . boolPointer ( SubversionSettings : : promptOnSubmitKey ) ,
! m_submitActionTriggered ) ;
2009-03-20 10:16:18 +01:00
m_submitActionTriggered = false ;
2008-12-02 12:01:29 +01:00
switch ( answer ) {
2012-01-07 12:31:48 +01:00
case VcsBase : : VcsBaseSubmitEditor : : SubmitCanceled :
2008-12-02 12:01:29 +01:00
return false ; // Keep editing and change file
2012-01-07 12:31:48 +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
2012-02-14 16:43:51 +01:00
closeEditor = Core : : DocumentManager : : saveDocument ( editorDocument ) ;
2011-03-30 12:43:17 +02:00
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
{
2013-09-27 15:39:16 +02:00
m_client - > diff ( m_commitRepository , files ) ;
2011-03-25 16:39:33 +01:00
}
2008-12-02 12:01:29 +01:00
SubversionSubmitEditor * SubversionPlugin : : openSubversionSubmitEditor ( const QString & fileName )
{
2012-05-08 09:43:14 +02:00
Core : : IEditor * editor = Core : : EditorManager : : openEditor ( fileName ,
2013-05-31 12:52:53 +02:00
Constants : : SUBVERSIONCOMMITEDITOR_ID ) ;
2008-12-02 12:01:29 +01:00
SubversionSubmitEditor * submitEditor = qobject_cast < SubversionSubmitEditor * > ( editor ) ;
2011-07-29 12:00:11 +02:00
QTC_CHECK ( submitEditor ) ;
2013-04-18 12:06:43 +02:00
setSubmitEditor ( 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 ;
}
2012-01-07 12:31:48 +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 ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2009-12-08 16:50:27 +01:00
vcsAdd ( state . currentFileTopLevel ( ) , state . relativeCurrentFile ( ) ) ;
2008-12-02 12:01:29 +01:00
}
2010-01-11 17:17:16 +01:00
void SubversionPlugin : : revertAll ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2010-01-11 17:17:16 +01:00
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 =
2013-02-27 13:25:21 +01:00
runSvn ( state . topLevel ( ) , args , m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
if ( revertResponse . error )
2010-01-11 17:17:16 +01:00
QMessageBox : : warning ( 0 , title , tr ( " Revert failed: %1 " ) . arg ( revertResponse . message ) , QMessageBox : : Ok ) ;
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
else
2010-01-11 17:17:16 +01:00
subVersionControl ( ) - > emitRepositoryChanged ( state . topLevel ( ) ) ;
}
2008-12-02 12:01:29 +01:00
void SubversionPlugin : : revertCurrentFile ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
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 =
2013-02-27 13:25:21 +01:00
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 =
2013-02-27 13:25:21 +01:00
runSvn ( state . currentFileTopLevel ( ) , args , m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +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 ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasProject ( ) , return ) ;
2013-09-27 15:39:16 +02:00
const QString relativeProject = state . relativeCurrentProject ( ) ;
m_client - > diff ( state . currentProjectTopLevel ( ) ,
relativeProject . isEmpty ( ) ? QStringList ( ) : QStringList ( relativeProject ) ) ;
2008-12-02 12:01:29 +01:00
}
void SubversionPlugin : : diffCurrentFile ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2013-09-27 15:39:16 +02:00
m_client - > diff ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
}
void SubversionPlugin : : startCommitCurrentFile ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2009-12-08 16:50:27 +01:00
startCommit ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) ) ;
2008-12-02 12:01:29 +01:00
}
void SubversionPlugin : : startCommitAll ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2009-12-08 16:50:27 +01:00
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 ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2010-04-27 12:16:51 +02:00
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
{
2013-04-18 12:06:43 +02:00
if ( raiseSubmitEditor ( ) )
2009-05-27 16:17:24 +02:00
return ;
2009-09-22 12:23:44 +02:00
if ( isCommitEditorOpen ( ) ) {
2012-01-07 12:31:48 +01: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 =
2013-02-27 13:25:21 +01:00
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 ( ) ) {
2012-01-07 12:31:48 +01: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
2011-03-30 15:15:15 +02:00
Utils : : TempFileSaver saver ;
saver . setAutoRemove ( false ) ;
// TODO: Retrieve submit template from
2008-12-02 12:01:29 +01:00
const QString submitTemplate ;
// Create a submit
2011-03-30 15:15:15 +02:00
saver . write ( submitTemplate . toUtf8 ( ) ) ;
if ( ! saver . finalize ( ) ) {
2012-01-07 12:31:48 +01:00
VcsBase : : VcsBaseOutputWindow : : instance ( ) - > appendError ( saver . errorString ( ) ) ;
2011-03-30 15:15:15 +02:00
return ;
}
m_commitMessageFileName = saver . fileName ( ) ;
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 =
2013-02-27 13:25:21 +01:00
runSvn ( m_commitRepository , args , 10 * m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2008-12-02 12:01:29 +01:00
return ! response . error ;
}
void SubversionPlugin : : filelogCurrentFile ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2013-08-06 15:14:54 +03:00
filelog ( state . currentFileTopLevel ( ) , state . relativeCurrentFile ( ) , true ) ;
2010-01-07 11:33:30 +01:00
}
void SubversionPlugin : : logProject ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasProject ( ) , return ) ;
2010-01-07 11:33:30 +01:00
filelog ( state . currentProjectTopLevel ( ) , state . relativeCurrentProject ( ) ) ;
}
void SubversionPlugin : : logRepository ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2010-01-07 11:33:30 +01:00
filelog ( state . topLevel ( ) ) ;
2008-12-02 12:01:29 +01:00
}
2010-04-27 12:16:51 +02:00
void SubversionPlugin : : diffRepository ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2013-09-27 15:39:16 +02:00
m_client - > diff ( state . topLevel ( ) , QStringList ( ) ) ;
2010-04-27 12:16:51 +02:00
}
void SubversionPlugin : : statusRepository ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2010-04-27 12:16:51 +02:00
svnStatus ( state . topLevel ( ) ) ;
}
void SubversionPlugin : : updateRepository ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2010-04-27 12:16:51 +02:00
svnUpdate ( state . topLevel ( ) ) ;
}
2013-08-06 15:14:54 +03:00
void SubversionPlugin : : svnStatus ( const QString & workingDir , const QString & relativePath )
2010-04-27 12:16:51 +02:00
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2010-04-27 12:16:51 +02:00
QStringList args ( QLatin1String ( " status " ) ) ;
2013-08-06 15:14:54 +03:00
if ( ! relativePath . isEmpty ( ) )
args . append ( relativePath ) ;
2012-01-07 12:31:48 +01:00
VcsBase : : VcsBaseOutputWindow * outwin = VcsBase : : VcsBaseOutputWindow : : instance ( ) ;
2010-04-27 12:16:51 +02:00
outwin - > setRepository ( workingDir ) ;
2013-02-27 13:25:21 +01: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 ,
2013-08-06 15:14:54 +03:00
const QString & file ,
2010-01-07 11:33:30 +01:00
bool enableAnnotationContextMenu )
2008-12-02 12:01:29 +01:00
{
// no need for temp file
QStringList args ( QLatin1String ( " log " ) ) ;
2013-02-27 13:25:21 +01:00
if ( m_settings . intValue ( SubversionSettings : : logCountKey ) > 0 ) {
args < < QLatin1String ( " -l " )
< < QString : : number ( m_settings . intValue ( SubversionSettings : : logCountKey ) ) ;
}
2013-08-06 15:14:54 +03:00
if ( ! file . isEmpty ( ) )
2009-12-08 16:50:27 +01:00
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 =
2013-02-27 13:25:21 +01:00
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
2013-08-06 15:14:54 +03:00
const QString id = VcsBase : : VcsBaseEditorWidget : : getTitleId ( workingDir , QStringList ( file ) ) ;
const QString tag = VcsBase : : VcsBaseEditorWidget : : editorTag ( VcsBase : : LogOutput , workingDir ,
QStringList ( file ) ) ;
2012-01-07 12:31:48 +01:00
if ( Core : : IEditor * editor = VcsBase : : VcsBaseEditorWidget : : locateEditorByTag ( tag ) ) {
2013-07-15 15:14:10 +02:00
editor - > document ( ) - > setContents ( response . stdOut . toUtf8 ( ) ) ;
2013-05-31 12:52:53 +02:00
Core : : EditorManager : : 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 ) ;
2013-08-06 15:14:54 +03:00
const QString source = VcsBase : : VcsBaseEditorWidget : : getSource ( workingDir , file ) ;
2012-01-07 12:31:48 +01:00
Core : : IEditor * newEditor = showOutputInEditor ( title , response . stdOut , VcsBase : : LogOutput , source , /*codec*/ 0 ) ;
VcsBase : : VcsBaseEditorWidget : : tagEditor ( newEditor , tag ) ;
2010-01-07 11:33:30 +01:00
if ( enableAnnotationContextMenu )
2012-01-07 12:31:48 +01:00
VcsBase : : VcsBaseEditorWidget : : getVcsBaseEditor ( newEditor ) - > setFileLogAnnotateEnabled ( true ) ;
2008-12-02 12:01:29 +01:00
}
}
void SubversionPlugin : : updateProject ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2009-12-08 16:50:27 +01:00
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
2013-08-06 15:14:54 +03:00
void SubversionPlugin : : svnUpdate ( const QString & workingDir , const QString & relativePath )
2010-04-27 12:16:51 +02:00
{
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 ) ) ;
2013-08-06 15:14:54 +03:00
if ( ! relativePath . isEmpty ( ) )
args . append ( relativePath ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
2013-02-27 13:25:21 +01:00
runSvn ( workingDir , args , 10 * m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
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 ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2009-12-08 16:50:27 +01:00
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
}
2013-10-06 20:47:29 +03:00
void SubversionPlugin : : annotateVersion ( const QString & workingDirectory ,
const QString & file ,
2010-01-06 17:24:40 +01:00
const QString & revision ,
int lineNr )
{
2013-10-06 20:47:29 +03:00
vcsAnnotate ( workingDirectory , file , 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
{
2012-01-07 12:31:48 +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 " ) ) ;
2013-02-27 13:25:21 +01:00
if ( m_settings . boolValue ( SubversionSettings : : spaceIgnorantAnnotationKey ) )
2010-01-05 15:45:41 +01:00
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 =
2013-02-27 13:25:21 +01:00
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 )
2012-01-07 12:31:48 +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 ) ;
2012-01-07 12:31:48 +01:00
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 ) ) {
2013-07-15 15:14:10 +02:00
editor - > document ( ) - > setContents ( response . stdOut . toUtf8 ( ) ) ;
2012-01-07 12:31:48 +01:00
VcsBase : : VcsBaseEditorWidget : : gotoLineOfEditor ( editor , lineNumber ) ;
2013-05-31 12:52:53 +02:00
Core : : EditorManager : : 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 ) ;
2012-01-07 12:31:48 +01:00
Core : : IEditor * newEditor = showOutputInEditor ( title , response . stdOut , VcsBase : : AnnotateOutput , source , codec ) ;
VcsBase : : VcsBaseEditorWidget : : tagEditor ( newEditor , tag ) ;
VcsBase : : VcsBaseEditorWidget : : gotoLineOfEditor ( newEditor , lineNumber ) ;
2008-12-02 12:01:29 +01:00
}
}
void SubversionPlugin : : projectStatus ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2009-12-08 16:50:27 +01:00
QTC_ASSERT ( state . hasProject ( ) , return ) ;
2012-05-15 19:54:12 +10:00
svnStatus ( state . currentProjectTopLevel ( ) , 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 =
2013-02-27 13:25:21 +01:00
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 ) ;
2012-01-07 12:31:48 +01:00
QTextCodec * codec = VcsBase : : VcsBaseEditorWidget : : getCodec ( source ) ;
2010-05-21 17:46:00 +02:00
const SubversionResponse response =
2013-02-27 13:25:21 +01:00
runSvn ( topLevel , args , m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
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 ;
2012-01-07 12:31:48 +01:00
const QString tag = VcsBase : : VcsBaseEditorWidget : : editorTag ( VcsBase : : DiffOutput , source , QStringList ( ) , changeNr ) ;
if ( Core : : IEditor * editor = VcsBase : : VcsBaseEditorWidget : : locateEditorByTag ( tag ) ) {
2013-07-15 15:14:10 +02:00
editor - > document ( ) - > setContents ( description . toUtf8 ( ) ) ;
2013-05-31 12:52:53 +02:00
Core : : EditorManager : : 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 ) ;
2012-01-07 12:31:48 +01:00
Core : : IEditor * newEditor = showOutputInEditor ( title , description , VcsBase : : DiffOutput , source , codec ) ;
VcsBase : : VcsBaseEditorWidget : : tagEditor ( newEditor , tag ) ;
2008-12-02 12:01:29 +01:00
}
}
2009-02-09 17:33:31 +01:00
void SubversionPlugin : : slotDescribe ( )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBasePluginState state = currentState ( ) ;
2009-12-08 16:50:27 +01:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2009-02-09 17:33:31 +01:00
2012-01-24 15:36:40 +01:00
QInputDialog inputDialog ( Core : : ICore : : mainWindow ( ) ) ;
2009-02-09 17:33:31 +01:00
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 ;
2013-08-29 15:46:04 +02:00
Core : : EditorManager : : closeEditors ( QList < Core : : IEditor * > ( )
2012-05-08 09:43:14 +02:00
< < Core : : EditorManager : : 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 ,
2013-10-02 00:18:39 +03:00
QTextCodec * outputCodec ) const
2010-06-08 10:04:23 +02:00
{
2013-02-27 13:25:21 +01:00
const bool hasAuth = m_settings . hasAuthentication ( ) ;
return runSvn ( workingDir ,
hasAuth ? m_settings . stringValue ( SubversionSettings : : userKey ) : QString ( ) ,
hasAuth ? m_settings . stringValue ( SubversionSettings : : passwordKey ) : QString ( ) ,
arguments , timeOut , flags , outputCodec ) ;
2010-06-08 10:04:23 +02:00
}
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 ,
2013-10-02 00:18:39 +03:00
unsigned flags , QTextCodec * outputCodec ) const
2008-12-02 12:01:29 +01:00
{
2013-02-27 13:25:21 +01:00
const QString executable = m_settings . binaryPath ( ) ;
2008-12-02 12:01:29 +01:00
SubversionResponse response ;
if ( executable . isEmpty ( ) ) {
response . error = true ;
response . message = tr ( " No subversion executable specified! " ) ;
return response ;
}
2013-09-27 15:39:16 +02:00
const QStringList completeArguments = SubversionClient : : addAuthenticationOptions ( arguments , userName , password ) ;
2010-05-21 17:46:00 +02:00
const Utils : : SynchronousProcessResponse sp_resp =
2013-08-16 17:02:30 +03:00
VcsBase : : VcsBasePlugin : : runVcs ( workingDir , executable , completeArguments , timeOut ,
2013-08-28 11:32:33 +03:00
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 ;
}
2011-11-10 11:36:51 +01:00
Core : : IEditor * SubversionPlugin : : showOutputInEditor ( const QString & title , const QString & output ,
2008-12-02 12:01:29 +01:00
int editorType , const QString & source ,
QTextCodec * codec )
{
2012-01-07 12:31:48 +01:00
const VcsBase : : VcsBaseEditorParameters * params = findType ( editorType ) ;
2008-12-09 15:25:01 +01:00
QTC_ASSERT ( params , return 0 ) ;
2013-03-19 18:27:04 +01:00
const Core : : Id id = params - > id ;
2008-12-02 12:01:29 +01:00
if ( Subversion : : Constants : : debug )
2011-11-10 11:36:51 +01:00
qDebug ( ) < < " SubversionPlugin::showOutputInEditor " < < title < < id . name ( )
< < " Size= " < < output . size ( ) < < " Type= " < < editorType < < debugCodec ( codec ) ;
2008-12-02 12:01:29 +01:00
QString s = title ;
2013-07-15 15:14:10 +02:00
Core : : IEditor * editor = Core : : EditorManager : : openEditorWithContents ( id , & s , output . toUtf8 ( ) ) ;
2013-10-06 20:47:29 +03:00
connect ( editor , SIGNAL ( annotateRevisionRequested ( QString , QString , QString , int ) ) ,
this , SLOT ( annotateVersion ( QString , 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 ( ' _ ' ) ) ;
2013-12-13 11:17:57 +01:00
e - > baseTextDocument ( ) - > setSuggestedFileName ( s ) ;
2008-12-02 12:01:29 +01:00
if ( ! source . isEmpty ( ) )
e - > setSource ( source ) ;
if ( codec )
e - > setCodec ( codec ) ;
2013-12-19 10:22:02 +01:00
return editor ;
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 ;
2013-02-27 13:25:21 +01:00
m_settings . writeSettings ( Core : : ICore : : settings ( ) ) ;
2011-04-15 17:43:44 +02:00
subVersionControl ( ) - > emitConfigurationChanged ( ) ;
2008-12-02 12:01:29 +01:00
}
}
2011-04-20 15:49:06 +02:00
SubversionPlugin * SubversionPlugin : : instance ( )
2008-12-02 12:01:29 +01:00
{
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 )
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 =
2013-02-27 13:25:21 +01:00
runSvn ( workingDir , args , m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2008-12-02 12:01:29 +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 =
2013-02-27 13:25:21 +01:00
runSvn ( workingDir , args , m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
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 =
2013-02-27 13:25:21 +01:00
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 )
{
2013-02-27 17:30:19 +08:00
QUrl tempUrl = QUrl : : fromEncoded ( url ) ;
2010-09-29 12:16:35 +02:00
QString username = tempUrl . userName ( ) ;
QString password = tempUrl . password ( ) ;
QStringList args = QStringList ( QLatin1String ( " checkout " ) ) ;
args < < QLatin1String ( nonInteractiveOptionC ) ;
2011-09-19 10:02:45 +02:00
if ( ! username . isEmpty ( ) & & ! password . isEmpty ( ) ) {
2010-09-29 12:16:35 +02:00
// 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.
2012-01-31 10:57:10 +01:00
tempUrl . setUserInfo ( QString ( ) ) ;
args < < QLatin1String ( tempUrl . toEncoded ( ) ) < < directory ;
2010-09-29 12:16:37 +02:00
const SubversionResponse response = runSvn ( directory , username , password , args ,
2013-02-27 13:25:21 +01:00
10 * m_settings . timeOutMs ( ) ,
2012-01-07 12:31:48 +01:00
VcsBase : : VcsBasePlugin : : SshPasswordPrompt ) ;
2010-09-29 12:16:35 +02:00
return ! response . error ;
} else {
2012-01-31 10:57:10 +01:00
args < < QLatin1String ( url ) < < directory ;
2013-02-27 13:25:21 +01:00
const SubversionResponse response = runSvn ( directory , args , 10 * m_settings . timeOutMs ( ) ,
2012-01-07 12:31:48 +01: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 " ) ;
2013-02-27 13:25:21 +01:00
const SubversionResponse response = runSvn ( directory , args , 10 * m_settings . timeOutMs ( ) , SuppressCommandLogging ) ;
2010-09-29 12:16:35 +02:00
xml . addData ( response . stdOut ) ;
bool repo = false ;
bool root = false ;
2012-11-28 20:44:03 +02:00
while ( ! xml . atEnd ( ) & & ! xml . hasError ( ) ) {
switch ( xml . readNext ( ) ) {
2010-09-29 12:16:35 +02:00
case QXmlStreamReader : : StartDocument :
break ;
case QXmlStreamReader : : StartElement :
2012-11-28 20:44:03 +02:00
if ( xml . name ( ) = = QLatin1String ( " repository " ) )
2010-09-29 12:16:35 +02:00
repo = true ;
2012-11-28 20:44:03 +02:00
else if ( repo & & xml . name ( ) = = QLatin1String ( " root " ) )
2010-09-29 12:16:35 +02:00
root = true ;
break ;
case QXmlStreamReader : : EndElement :
2012-11-28 20:44:03 +02:00
if ( xml . name ( ) = = QLatin1String ( " repository " ) )
2010-09-29 12:16:35 +02:00
repo = false ;
2012-11-28 20:44:03 +02:00
else if ( repo & & xml . name ( ) = = QLatin1String ( " root " ) )
2010-09-29 12:16:35 +02:00
root = false ;
break ;
case QXmlStreamReader : : Characters :
if ( repo & & root )
return xml . text ( ) . toString ( ) ;
break ;
default :
break ;
}
}
return QString ( ) ;
}
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 ) ;
2011-10-19 14:07:26 +00:00
if ( ! dir . exists ( ) )
return false ;
2010-05-20 16:24:39 +02:00
if ( topLevel )
topLevel - > clear ( ) ;
2011-10-19 14:07:26 +00:00
/* Subversion >= 1.7 has ".svn" directory in the root of the working copy. Check for
* furthest parent containing " .svn/wc.db " . Need to check for furthest parent as closer
* parents may be svn : externals . */
QDir parentDir = dir ;
2013-12-03 08:15:44 +02:00
while ( ! parentDir . isRoot ( ) & & parentDir . cdUp ( ) ) {
2011-10-19 14:07:26 +00:00
if ( checkSVNSubDir ( parentDir , QLatin1String ( " wc.db " ) ) ) {
if ( topLevel )
* topLevel = parentDir . absolutePath ( ) ;
return true ;
2011-10-19 14:06:40 +00:00
}
}
2011-10-19 14:07:26 +00:00
/* Subversion < 1.7 has ".svn" directory in each directory
* it manages . The top level is the first directory
* under the directory that does not have a " .svn " . */
if ( ! checkSVNSubDir ( dir ) )
return false ;
if ( topLevel ) {
QDir lastDirectory = dir ;
2013-12-03 08:15:44 +02:00
for ( parentDir = lastDirectory ;
! parentDir . isRoot ( ) & & parentDir . cdUp ( ) ;
lastDirectory = parentDir ) {
2011-10-19 14:07:26 +00:00
if ( ! checkSVNSubDir ( parentDir ) ) {
* topLevel = lastDirectory . absolutePath ( ) ;
break ;
2010-05-20 16:24:39 +02:00
}
}
}
2011-11-07 20:49:48 +11:00
return true ;
2008-12-02 12:01:29 +01:00
}
2013-10-02 00:18:39 +03:00
bool SubversionPlugin : : managesFile ( const QString & workingDirectory , const QString & fileName ) const
{
QStringList args ;
args < < QLatin1String ( " status " ) < < fileName ;
SubversionResponse response =
runSvn ( workingDirectory , args , m_settings . timeOutMs ( ) , 0 ) ;
return response . stdOut . isEmpty ( ) | | response . stdOut . at ( 0 ) ! = QLatin1Char ( ' ? ' ) ;
}
2010-05-20 16:24:39 +02:00
// Check whether SVN management subdirs exist.
2011-10-19 14:06:40 +00:00
bool SubversionPlugin : : checkSVNSubDir ( const QDir & directory , const QString & fileName ) 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 ) ) ;
2011-10-19 14:06:40 +00:00
if ( ! QFileInfo ( svnDir ) . isDir ( ) )
continue ;
if ( ! fileName . isEmpty ( ) & & ! QDir ( svnDir ) . exists ( fileName ) )
continue ;
return true ;
2009-05-26 12:25:32 +02:00
}
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 ( ) ) ;
}
2013-01-19 23:19:38 +02:00
# ifdef WITH_TESTS
void SubversionPlugin : : testDiffFileResolving_data ( )
{
QTest : : addColumn < QByteArray > ( " header " ) ;
QTest : : addColumn < QByteArray > ( " fileName " ) ;
QTest : : newRow ( " New " ) < < QByteArray (
" Index: src/plugins/subversion/subversioneditor.cpp \n "
" =================================================================== \n "
" --- src/plugins/subversion/subversioneditor.cpp \t (revision 0) \n "
" +++ src/plugins/subversion/subversioneditor.cpp \t (revision 0) \n "
" @@ -0,0 +125 @@ \n \n " )
< < QByteArray ( " src/plugins/subversion/subversioneditor.cpp " ) ;
QTest : : newRow ( " Deleted " ) < < QByteArray (
" Index: src/plugins/subversion/subversioneditor.cpp \n "
" =================================================================== \n "
" --- src/plugins/subversion/subversioneditor.cpp \t (revision 42) \n "
" +++ src/plugins/subversion/subversioneditor.cpp \t (working copy) \n "
" @@ -1,125 +0,0 @@ \n \n " )
< < QByteArray ( " src/plugins/subversion/subversioneditor.cpp " ) ;
QTest : : newRow ( " Normal " ) < < QByteArray (
" Index: src/plugins/subversion/subversioneditor.cpp \n "
" =================================================================== \n "
" --- src/plugins/subversion/subversioneditor.cpp \t (revision 42) \n "
" +++ src/plugins/subversion/subversioneditor.cpp \t (working copy) \n "
" @@ -120,7 +120,7 @@ \n \n " )
< < QByteArray ( " src/plugins/subversion/subversioneditor.cpp " ) ;
}
void SubversionPlugin : : testDiffFileResolving ( )
{
2013-05-27 18:34:02 +03:00
SubversionEditor editor ( editorParameters + 2 , 0 ) ;
2013-01-28 20:50:05 +02:00
editor . testDiffFileResolving ( ) ;
2013-01-19 23:19:38 +02:00
}
2013-01-28 22:02:35 +02:00
void SubversionPlugin : : testLogResolving ( )
{
QByteArray data (
" ------------------------------------------------------------------------ \n "
" r1439551 | philip | 2013-01-28 20:19:55 +0200 (Mon, 28 Jan 2013) | 4 lines \n "
" \n "
" * subversion/tests/cmdline/update_tests.py \n "
" (update_moved_dir_file_move): Resolve conflict, adjust expectations, \n "
" remove XFail. \n "
" \n "
" ------------------------------------------------------------------------ \n "
" r1439540 | philip | 2013-01-28 20:06:36 +0200 (Mon, 28 Jan 2013) | 4 lines \n "
" \n "
" * subversion/tests/cmdline/update_tests.py \n "
" (update_moved_dir_edited_leaf_del): Do non-recursive resolution, adjust \n "
" expectations, remove XFail. \n "
" \n "
) ;
2013-05-27 18:34:02 +03:00
SubversionEditor editor ( editorParameters , 0 ) ;
2013-01-28 22:02:35 +02:00
editor . testLogResolving ( data , " r1439551 " , " r1439540 " ) ;
}
2013-01-19 23:19:38 +02:00
# endif
2011-03-25 16:39:33 +01:00
} // Internal
} // Subversion
Q_EXPORT_PLUGIN ( Subversion : : Internal : : SubversionPlugin )