2012-10-02 09:12:39 +02:00
/****************************************************************************
2009-07-15 12:28:40 +02:00
* *
2013-01-28 17:12:19 +01:00
* * Copyright ( C ) 2013 Digia Plc and / or its subsidiary ( - ies ) .
2012-10-02 09:12:39 +02:00
* * Contact : http : //www.qt-project.org/legal
2009-07-15 12:28:40 +02:00
* *
2012-10-02 09:12:39 +02:00
* * This file is part of Qt Creator .
2009-07-15 12:28:40 +02: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.
2009-07-15 12:28:40 +02: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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-07-15 12:28:40 +02:00
# include "cvsplugin.h"
# include "settingspage.h"
# include "cvseditor.h"
# include "cvssubmiteditor.h"
2013-10-15 20:03:22 +02:00
# include "cvsclient.h"
2009-07-15 12:28:40 +02:00
# include "cvsconstants.h"
# include "cvscontrol.h"
2009-07-20 09:23:00 +02:00
# include "checkoutwizard.h"
2009-07-15 12:28:40 +02: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>
2010-02-12 16:03:08 +01:00
# include <locator/commandlocator.h>
2009-07-15 12:28:40 +02:00
# include <utils/synchronousprocess.h>
# include <utils/parameteraction.h>
2011-03-25 16:39:33 +01:00
# include <utils/qtcassert.h>
2009-07-15 12:28:40 +02:00
# include <coreplugin/icore.h>
# include <coreplugin/coreconstants.h>
2012-02-14 16:43:51 +01:00
# include <coreplugin/documentmanager.h>
2009-07-15 12:28:40 +02:00
# include <coreplugin/messagemanager.h>
# include <coreplugin/mimedatabase.h>
# 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>
2009-07-15 12:28:40 +02:00
# include <coreplugin/editormanager/editormanager.h>
# include <coreplugin/vcsmanager.h>
2009-11-25 12:34:56 +01:00
# include <utils/stringutils.h>
2011-03-30 15:15:15 +02:00
# include <utils/fileutils.h>
2009-07-15 12:28:40 +02:00
2012-02-15 10:42:41 +01:00
# include <QDebug>
# include <QDate>
# include <QDir>
# include <QFileInfo>
# include <QTextCodec>
# include <QtPlugin>
# include <QAction>
# include <QMainWindow>
# include <QMenu>
# include <QMessageBox>
2009-07-15 12:28:40 +02:00
2013-01-21 22:56:01 +02:00
# ifdef WITH_TESTS
# include <QTest>
# endif
2012-01-07 16:55:09 +01:00
using namespace VcsBase ;
using namespace Core ;
namespace Cvs {
2011-11-02 16:45:13 +01:00
namespace Internal {
2009-07-15 12:28:40 +02:00
static inline QString msgCannotFindTopLevel ( const QString & f )
{
2012-01-07 16:55:09 +01:00
return CvsPlugin : : tr ( " Cannot find repository for '%1' " ) .
2010-07-05 09:52:32 +02:00
arg ( QDir : : toNativeSeparators ( f ) ) ;
2009-07-15 12:28:40 +02:00
}
static inline QString msgLogParsingFailed ( )
{
2012-01-07 16:55:09 +01:00
return CvsPlugin : : tr ( " Parsing of the log output failed " ) ;
2009-07-15 12:28:40 +02:00
}
2011-11-02 16:45:13 +01:00
static const char CMD_ID_CVS_MENU [ ] = " CVS.Menu " ;
static const char CMD_ID_ADD [ ] = " CVS.Add " ;
static const char CMD_ID_DELETE_FILE [ ] = " CVS.Delete " ;
static const char CMD_ID_EDIT_FILE [ ] = " CVS.EditFile " ;
static const char CMD_ID_UNEDIT_FILE [ ] = " CVS.UneditFile " ;
static const char CMD_ID_UNEDIT_REPOSITORY [ ] = " CVS.UneditRepository " ;
static const char CMD_ID_REVERT [ ] = " CVS.Revert " ;
static const char CMD_ID_DIFF_PROJECT [ ] = " CVS.DiffAll " ;
static const char CMD_ID_DIFF_CURRENT [ ] = " CVS.DiffCurrent " ;
static const char CMD_ID_COMMIT_ALL [ ] = " CVS.CommitAll " ;
static const char CMD_ID_REVERT_ALL [ ] = " CVS.RevertAll " ;
static const char CMD_ID_COMMIT_CURRENT [ ] = " CVS.CommitCurrent " ;
static const char CMD_ID_FILELOG_CURRENT [ ] = " CVS.FilelogCurrent " ;
static const char CMD_ID_ANNOTATE_CURRENT [ ] = " CVS.AnnotateCurrent " ;
static const char CMD_ID_STATUS [ ] = " CVS.Status " ;
static const char CMD_ID_UPDATE [ ] = " CVS.Update " ;
static const char CMD_ID_PROJECTLOG [ ] = " CVS.ProjectLog " ;
static const char CMD_ID_PROJECTCOMMIT [ ] = " CVS.ProjectCommit " ;
static const char CMD_ID_REPOSITORYLOG [ ] = " CVS.RepositoryLog " ;
static const char CMD_ID_REPOSITORYDIFF [ ] = " CVS.RepositoryDiff " ;
static const char CMD_ID_REPOSITORYSTATUS [ ] = " CVS.RepositoryStatus " ;
static const char CMD_ID_REPOSITORYUPDATE [ ] = " CVS.RepositoryUpdate " ;
2009-07-15 12:28:40 +02:00
2012-01-07 16:55:09 +01:00
static const VcsBaseEditorParameters editorParameters [ ] = {
2009-07-15 12:28:40 +02:00
{
2013-05-22 21:32:07 +03:00
OtherContent ,
2010-01-08 09:48:54 +01:00
" CVS Command Log Editor " , // id
QT_TRANSLATE_NOOP ( " VCS " , " CVS Command Log Editor " ) , // display name
2009-07-15 12:28:40 +02:00
" CVS Command Log Editor " , // context
2013-05-21 23:37:47 +03:00
" text/vnd.qtcreator.cvs.commandlog " } ,
2012-01-07 16:55:09 +01:00
{ LogOutput ,
2010-01-08 09:48:54 +01:00
" CVS File Log Editor " , // id
QT_TRANSLATE_NOOP ( " VCS " , " CVS File Log Editor " ) , // display name
2009-07-15 12:28:40 +02:00
" CVS File Log Editor " , // context
2013-05-21 23:37:47 +03:00
" text/vnd.qtcreator.cvs.log " } ,
2012-01-07 16:55:09 +01:00
{ AnnotateOutput ,
2010-01-08 09:48:54 +01:00
" CVS Annotation Editor " , // id
QT_TRANSLATE_NOOP ( " VCS " , " CVS Annotation Editor " ) , // display name
2009-07-15 12:28:40 +02:00
" CVS Annotation Editor " , // context
2013-05-21 23:37:47 +03:00
" text/vnd.qtcreator.cvs.annotation " } ,
2012-01-07 16:55:09 +01:00
{ DiffOutput ,
2010-01-08 09:48:54 +01:00
" CVS Diff Editor " , // id
QT_TRANSLATE_NOOP ( " VCS " , " CVS Diff Editor " ) , // display name
2009-07-15 12:28:40 +02:00
" CVS Diff Editor " , // context
2013-05-21 20:54:26 +03:00
" text/x-patch " }
2009-07-15 12:28:40 +02:00
} ;
// Utility to find a parameter set by type
2012-01-07 16:55:09 +01:00
static inline const VcsBaseEditorParameters * findType ( int ie )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const EditorContentType et = static_cast < EditorContentType > ( ie ) ;
return VcsBaseEditorWidget : : findType ( editorParameters , sizeof ( editorParameters ) / sizeof ( VcsBaseEditorParameters ) , et ) ;
2009-07-15 12:28:40 +02: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 " ) ;
2009-07-15 12:28:40 +02:00
}
2010-08-06 16:12:24 +02:00
static inline bool messageBoxQuestion ( const QString & title , const QString & question , QWidget * parent = 0 )
{
return QMessageBox : : question ( parent , title , question , QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : Yes ;
}
2009-07-15 12:28:40 +02:00
// ------------- CVSPlugin
2012-01-07 16:55:09 +01:00
CvsPlugin * CvsPlugin : : m_cvsPluginInstance = 0 ;
2009-07-15 12:28:40 +02:00
2012-01-07 16:55:09 +01:00
CvsPlugin : : CvsPlugin ( ) :
2010-02-12 16:03:08 +01:00
m_commandLocator ( 0 ) ,
2009-07-15 12:28:40 +02:00
m_addAction ( 0 ) ,
m_deleteAction ( 0 ) ,
m_revertAction ( 0 ) ,
2010-08-06 16:12:24 +02:00
m_editCurrentAction ( 0 ) ,
m_uneditCurrentAction ( 0 ) ,
m_uneditRepositoryAction ( 0 ) ,
2009-07-15 12:28:40 +02:00
m_diffProjectAction ( 0 ) ,
m_diffCurrentAction ( 0 ) ,
2010-01-07 11:33:30 +01:00
m_logProjectAction ( 0 ) ,
m_logRepositoryAction ( 0 ) ,
2009-07-15 12:28:40 +02:00
m_commitAllAction ( 0 ) ,
2010-01-11 17:17:16 +01:00
m_revertRepositoryAction ( 0 ) ,
2009-07-15 12:28:40 +02:00
m_commitCurrentAction ( 0 ) ,
m_filelogCurrentAction ( 0 ) ,
m_annotateCurrentAction ( 0 ) ,
2009-12-09 12:41:10 +01:00
m_statusProjectAction ( 0 ) ,
2009-07-15 12:28:40 +02:00
m_updateProjectAction ( 0 ) ,
2010-08-06 16:12:24 +02:00
m_commitProjectAction ( 0 ) ,
m_diffRepositoryAction ( 0 ) ,
m_updateRepositoryAction ( 0 ) ,
m_statusRepositoryAction ( 0 ) ,
2009-07-15 12:28:40 +02:00
m_submitCurrentLogAction ( 0 ) ,
m_submitDiffAction ( 0 ) ,
m_submitUndoAction ( 0 ) ,
m_submitRedoAction ( 0 ) ,
2009-12-08 14:26:41 +01:00
m_menuAction ( 0 ) ,
2009-07-15 12:28:40 +02:00
m_submitActionTriggered ( false )
{
}
2012-01-07 16:55:09 +01:00
CvsPlugin : : ~ CvsPlugin ( )
2009-07-15 12:28:40 +02:00
{
2013-10-15 20:03:22 +02:00
delete m_client ;
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : cleanCommitMessageFile ( )
2009-07-15 12:28:40 +02:00
{
2009-09-22 12:23:44 +02:00
if ( ! m_commitMessageFileName . isEmpty ( ) ) {
QFile : : remove ( m_commitMessageFileName ) ;
m_commitMessageFileName . clear ( ) ;
2009-12-09 12:41:10 +01:00
m_commitRepository . clear ( ) ;
2009-07-15 12:28:40 +02:00
}
}
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : isCommitEditorOpen ( ) const
2009-09-22 12:23:44 +02:00
{
return ! m_commitMessageFileName . isEmpty ( ) ;
}
2009-07-15 12:28:40 +02:00
2012-01-07 16:55:09 +01:00
static const VcsBaseSubmitEditorParameters submitParameters = {
Constants : : CVS_SUBMIT_MIMETYPE ,
Constants : : CVSCOMMITEDITOR_ID ,
Constants : : CVSCOMMITEDITOR_DISPLAY_NAME ,
2013-01-11 10:45:00 +02:00
Constants : : CVSCOMMITEDITOR ,
VcsBase : : VcsBaseSubmitEditorParameters : : DiffFiles
2009-07-15 12:28:40 +02:00
} ;
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : initialize ( const QStringList & arguments , QString * errorMessage )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
Q_UNUSED ( arguments ) ;
typedef VcsSubmitEditorFactory < CvsSubmitEditor > CVSSubmitEditorFactory ;
typedef VcsEditorFactory < CvsEditor > CVSEditorFactory ;
2009-07-15 12:28:40 +02:00
using namespace Constants ;
using namespace Core : : Constants ;
using namespace ExtensionSystem ;
2013-08-28 21:27:47 +03:00
using Core : : Command ;
2009-07-15 12:28:40 +02:00
2012-01-07 16:55:09 +01:00
initializeVcs ( new CvsControl ( this ) ) ;
2009-12-08 14:26:41 +01:00
2009-07-15 12:28:40 +02:00
m_cvsPluginInstance = this ;
2013-08-30 16:38:57 +02:00
if ( ! MimeDatabase : : addMimeTypes ( QLatin1String ( " :/trolltech.cvs/CVS.mimetypes.xml " ) , errorMessage ) )
2009-07-15 12:28:40 +02:00
return false ;
2013-10-15 20:03:22 +02:00
m_settings . readSettings ( ICore : : settings ( ) ) ;
m_client = new CvsClient ( & m_settings ) ;
2009-07-15 12:28:40 +02:00
addAutoReleasedObject ( new SettingsPage ) ;
addAutoReleasedObject ( new CVSSubmitEditorFactory ( & submitParameters ) ) ;
static const char * describeSlotC = SLOT ( slotDescribe ( QString , QString ) ) ;
2012-01-07 16:55:09 +01:00
const int editorCount = sizeof ( editorParameters ) / sizeof ( editorParameters [ 0 ] ) ;
2009-07-15 12:28:40 +02:00
for ( int i = 0 ; i < editorCount ; i + + )
addAutoReleasedObject ( new CVSEditorFactory ( editorParameters + i , this , describeSlotC ) ) ;
2009-07-20 09:23:00 +02:00
addAutoReleasedObject ( new CheckoutWizard ) ;
2010-02-12 16:03:08 +01:00
const QString prefix = QLatin1String ( " cvs " ) ;
2013-01-18 11:35:38 +01:00
m_commandLocator = new Locator : : CommandLocator ( " CVS " , prefix , prefix ) ;
2010-02-12 16:03:08 +01:00
addAutoReleasedObject ( m_commandLocator ) ;
2012-01-07 16:55:09 +01:00
// Register actions
2012-05-24 13:49:06 +02:00
ActionContainer * toolsContainer = Core : : ActionManager : : actionContainer ( M_TOOLS ) ;
2009-07-15 12:28:40 +02:00
2012-05-24 13:49:06 +02:00
ActionContainer * cvsMenu = Core : : ActionManager : : createMenu ( Id ( CMD_ID_CVS_MENU ) ) ;
2009-07-15 12:28:40 +02:00
cvsMenu - > menu ( ) - > setTitle ( tr ( " &CVS " ) ) ;
toolsContainer - > addMenu ( cvsMenu ) ;
2009-12-08 14:26:41 +01:00
m_menuAction = cvsMenu - > menu ( ) - > menuAction ( ) ;
2009-07-15 12:28:40 +02:00
2012-01-07 16:55:09 +01:00
Context globalcontext ( C_GLOBAL ) ;
2009-07-15 12:28:40 +02:00
2012-01-07 16:55:09 +01:00
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 ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2012-05-23 13:25:51 +02:00
command - > setDefaultKeySequence ( QKeySequence ( UseMacShortcuts ? tr ( " Meta+C,Meta+D " ) : tr ( " Alt+C,Alt+D " ) ) ) ;
2010-01-11 17:17:16 +01:00
connect ( m_diffCurrentAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffCurrentFile ( ) ) ) ;
2009-07-15 12:28:40 +02:00
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2009-07-15 12:28:40 +02: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 ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
connect ( m_filelogCurrentAction , SIGNAL ( triggered ( ) ) , this ,
SLOT ( filelogCurrentFile ( ) ) ) ;
2009-07-15 12:28:40 +02:00
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2009-07-15 12:28:40 +02: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 ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
connect ( m_annotateCurrentAction , SIGNAL ( triggered ( ) ) , this ,
SLOT ( annotateCurrentFile ( ) ) ) ;
2009-07-15 12:28:40 +02:00
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2009-07-15 12:28:40 +02:00
2012-06-05 14:22:20 +02:00
cvsMenu - > addSeparator ( globalcontext ) ;
2009-07-15 12:28:40 +02: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 ,
2009-07-15 12:28:40 +02:00
globalcontext ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2012-05-23 13:25:51 +02:00
command - > setDefaultKeySequence ( QKeySequence ( UseMacShortcuts ? tr ( " Meta+C,Meta+A " ) : tr ( " Alt+C,Alt+A " ) ) ) ;
2010-01-11 17:17:16 +01:00
connect ( m_addAction , SIGNAL ( triggered ( ) ) , this , SLOT ( addCurrentFile ( ) ) ) ;
2009-07-15 12:28:40 +02:00
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2009-07-15 12:28:40 +02: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-15 12:28:40 +02:00
CMD_ID_COMMIT_CURRENT , globalcontext ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2012-05-23 13:25:51 +02:00
command - > setDefaultKeySequence ( QKeySequence ( UseMacShortcuts ? tr ( " Meta+C,Meta+C " ) : tr ( " Alt+C,Alt+C " ) ) ) ;
2009-07-15 12:28:40 +02:00
connect ( m_commitCurrentAction , SIGNAL ( triggered ( ) ) , this , SLOT ( startCommitCurrentFile ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2009-07-15 12:28:40 +02: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 ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
connect ( m_deleteAction , SIGNAL ( triggered ( ) ) , this , SLOT ( promptToDeleteCurrentFile ( ) ) ) ;
2009-07-15 12:28:40 +02:00
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2009-07-15 12:28:40 +02: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 ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
connect ( m_revertAction , SIGNAL ( triggered ( ) ) , this , SLOT ( revertCurrentFile ( ) ) ) ;
2009-07-15 12:28:40 +02:00
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2009-07-15 12:28:40 +02:00
2012-06-05 14:22:20 +02:00
cvsMenu - > addSeparator ( globalcontext ) ;
2010-01-11 17:17:16 +01:00
2010-08-06 16:12:24 +02:00
m_editCurrentAction = new Utils : : ParameterAction ( tr ( " Edit " ) , tr ( " Edit \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_editCurrentAction , CMD_ID_EDIT_FILE , globalcontext ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2010-08-06 16:12:24 +02:00
connect ( m_editCurrentAction , SIGNAL ( triggered ( ) ) , this , SLOT ( editCurrentFile ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
m_uneditCurrentAction = new Utils : : ParameterAction ( tr ( " Unedit " ) , tr ( " Unedit \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_uneditCurrentAction , CMD_ID_UNEDIT_FILE , globalcontext ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2010-08-06 16:12:24 +02:00
connect ( m_uneditCurrentAction , SIGNAL ( triggered ( ) ) , this , SLOT ( uneditCurrentFile ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
m_uneditRepositoryAction = new QAction ( tr ( " Unedit Repository " ) , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_uneditRepositoryAction , CMD_ID_UNEDIT_REPOSITORY , globalcontext ) ;
2010-08-06 16:12:24 +02:00
connect ( m_uneditRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( uneditCurrentRepository ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
2012-06-05 14:22:20 +02:00
cvsMenu - > addSeparator ( globalcontext ) ;
2010-08-06 16:12:24 +02: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 ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
connect ( m_diffProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffProject ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2009-07-15 12:28:40 +02:00
2009-12-09 12:41:10 +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 ,
2009-07-15 12:28:40 +02:00
globalcontext ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2009-12-09 12:41:10 +01:00
connect ( m_statusProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( projectStatus ( ) ) ) ;
2009-07-15 12:28:40 +02:00
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2009-07-15 12:28:40 +02:00
2010-01-07 11:33:30 +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 ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2010-01-07 11:33:30 +01:00
connect ( m_logProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( logProject ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2010-01-07 11:33:30 +01:00
2009-12-09 12:41:10 +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 ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2009-07-15 12:28:40 +02:00
connect ( m_updateProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( updateProject ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2009-07-15 12:28:40 +02:00
2010-08-06 16:12:24 +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_PROJECTCOMMIT , globalcontext ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2010-08-06 16:12:24 +02:00
connect ( m_commitProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( commitProject ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
2012-06-05 14:22:20 +02:00
cvsMenu - > addSeparator ( globalcontext ) ;
2010-08-06 16:12:24 +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-08-06 16:12:24 +02:00
connect ( m_diffRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffRepository ( ) ) ) ;
cvsMenu - > 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-08-06 16:12:24 +02:00
connect ( m_statusRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( statusRepository ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
m_commandLocator - > appendCommand ( command ) ;
2010-01-11 17:17:16 +01:00
2010-01-07 11:33:30 +01:00
m_logRepositoryAction = new QAction ( tr ( " Repository Log " ) , 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 ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2010-01-07 11:33:30 +01:00
2010-08-06 16:12:24 +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-08-06 16:12:24 +02:00
connect ( m_updateRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( updateRepository ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
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 ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( 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 ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2010-01-11 17:17:16 +01:00
2009-07-15 12:28:40 +02:00
// Actions of the submit editor
2012-01-07 16:55:09 +01:00
Context cvscommitcontext ( Constants : : CVSCOMMITEDITOR ) ;
2009-07-15 12:28:40 +02:00
2012-01-07 16:55:09 +01:00
m_submitCurrentLogAction = new QAction ( VcsBaseSubmitEditor : : submitIcon ( ) , tr ( " Commit " ) , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_submitCurrentLogAction , Constants : : SUBMIT_CURRENT , cvscommitcontext ) ;
2012-01-07 16:55:09 +01:00
command - > setAttribute ( Command : : CA_UpdateText ) ;
2009-07-15 12:28:40 +02:00
connect ( m_submitCurrentLogAction , SIGNAL ( triggered ( ) ) , this , SLOT ( submitCurrentLog ( ) ) ) ;
2012-01-07 16:55:09 +01:00
m_submitDiffAction = new QAction ( VcsBaseSubmitEditor : : diffIcon ( ) , tr ( " Diff &Selected Files " ) , this ) ;
2012-05-24 13:49:06 +02:00
command = Core : : ActionManager : : registerAction ( m_submitDiffAction , Constants : : DIFF_SELECTED , cvscommitcontext ) ;
2009-07-15 12:28:40 +02: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 , cvscommitcontext ) ;
2009-07-15 12:28:40 +02: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 , cvscommitcontext ) ;
2009-07-15 12:28:40 +02:00
return true ;
}
2013-04-18 12:06:43 +02:00
bool CvsPlugin : : submitEditorAboutToClose ( )
2009-07-15 12:28:40 +02:00
{
2009-12-08 14:26:41 +01:00
if ( ! isCommitEditorOpen ( ) )
2009-07-15 12:28:40 +02:00
return true ;
2013-04-18 12:06:43 +02:00
CvsSubmitEditor * editor = qobject_cast < CvsSubmitEditor * > ( submitEditor ( ) ) ;
QTC_ASSERT ( editor , return true ) ;
IDocument * editorDocument = editor - > document ( ) ;
QTC_ASSERT ( editorDocument , return true ) ;
2009-07-15 12:28:40 +02: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 ) ;
2009-07-15 12:28:40 +02:00
if ( editorFile . absoluteFilePath ( ) ! = changeFile . absoluteFilePath ( ) )
return true ; // Oops?!
// Prompt user. Force a prompt unless submit was actually invoked (that
// is, the editor was closed or shutdown).
2012-01-07 16:55:09 +01:00
CvsSettings newSettings = m_settings ;
const VcsBaseSubmitEditor : : PromptSubmitResult answer =
2009-07-15 12:28:40 +02:00
editor - > promptSubmit ( tr ( " Closing CVS Editor " ) ,
tr ( " Do you want to commit the change? " ) ,
tr ( " The commit message check failed. Do you want to commit the change? " ) ,
2013-10-15 20:03:22 +02:00
newSettings . boolPointer ( CvsSettings : : promptOnSubmitKey ) ,
! m_submitActionTriggered ) ;
2009-07-15 12:28:40 +02:00
m_submitActionTriggered = false ;
switch ( answer ) {
2012-01-07 16:55:09 +01:00
case VcsBaseSubmitEditor : : SubmitCanceled :
2009-07-15 12:28:40 +02:00
return false ; // Keep editing and change file
2012-01-07 16:55:09 +01:00
case VcsBaseSubmitEditor : : SubmitDiscarded :
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2009-07-15 12:28:40 +02:00
return true ; // Cancel all
default :
break ;
}
setSettings ( newSettings ) ; // in case someone turned prompting off
const QStringList fileList = editor - > checkedFiles ( ) ;
bool closeEditor = true ;
if ( ! fileList . empty ( ) ) {
// get message & commit
2012-02-14 16:43:51 +01:00
closeEditor = DocumentManager : : saveDocument ( editorDocument ) ;
2011-03-30 12:43:17 +02:00
if ( closeEditor )
closeEditor = commit ( m_commitMessageFileName , fileList ) ;
2009-07-15 12:28:40 +02:00
}
if ( closeEditor )
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2009-07-15 12:28:40 +02:00
return closeEditor ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : diffCommitFiles ( const QStringList & files )
2009-07-15 12:28:40 +02:00
{
2013-10-15 20:03:22 +02:00
m_client - > diff ( m_commitRepository , files ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
static void setDiffBaseDirectory ( IEditor * editor , const QString & db )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
if ( VcsBaseEditorWidget * ve = qobject_cast < VcsBaseEditorWidget * > ( editor - > widget ( ) ) )
2013-10-06 20:52:09 +03:00
ve - > setWorkingDirectory ( db ) ;
2009-12-09 12:41:10 +01:00
}
2009-07-15 12:28:40 +02:00
2012-01-07 16:55:09 +01:00
CvsSubmitEditor * CvsPlugin : : openCVSSubmitEditor ( const QString & fileName )
2009-07-15 12:28:40 +02:00
{
2013-05-31 12:52:53 +02:00
IEditor * editor = EditorManager : : openEditor ( fileName , Constants : : CVSCOMMITEDITOR_ID ) ;
2012-01-07 16:55:09 +01:00
CvsSubmitEditor * submitEditor = qobject_cast < CvsSubmitEditor * > ( editor ) ;
2011-07-29 12:00:11 +02:00
QTC_CHECK ( submitEditor ) ;
2009-07-15 12:28:40 +02:00
submitEditor - > registerActions ( m_submitUndoAction , m_submitRedoAction , m_submitCurrentLogAction , m_submitDiffAction ) ;
2009-12-09 12:41:10 +01:00
connect ( submitEditor , SIGNAL ( diffSelectedFiles ( QStringList ) ) , this , SLOT ( diffCommitFiles ( QStringList ) ) ) ;
2009-07-15 12:28:40 +02:00
return submitEditor ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : updateActions ( VcsBasePlugin : : ActionState as )
2009-07-15 12:28:40 +02: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
}
2009-12-08 14:26:41 +01:00
2010-02-12 16:03:08 +01:00
const bool hasTopLevel = currentState ( ) . hasTopLevel ( ) ;
m_commandLocator - > setEnabled ( hasTopLevel ) ;
2010-01-07 11:33:30 +01:00
2009-12-09 12:41:10 +01:00
const QString currentFileName = currentState ( ) . currentFileName ( ) ;
m_addAction - > setParameter ( currentFileName ) ;
m_deleteAction - > setParameter ( currentFileName ) ;
m_revertAction - > setParameter ( currentFileName ) ;
m_diffCurrentAction - > setParameter ( currentFileName ) ;
m_commitCurrentAction - > setParameter ( currentFileName ) ;
m_filelogCurrentAction - > setParameter ( currentFileName ) ;
m_annotateCurrentAction - > setParameter ( currentFileName ) ;
2010-08-06 16:12:24 +02:00
m_editCurrentAction - > setParameter ( currentFileName ) ;
m_uneditCurrentAction - > setParameter ( currentFileName ) ;
2009-12-09 12:41:10 +01:00
const QString currentProjectName = currentState ( ) . currentProjectName ( ) ;
m_diffProjectAction - > setParameter ( currentProjectName ) ;
m_statusProjectAction - > setParameter ( currentProjectName ) ;
m_updateProjectAction - > setParameter ( currentProjectName ) ;
2010-01-07 11:33:30 +01:00
m_logProjectAction - > setParameter ( currentProjectName ) ;
2010-08-06 16:12:24 +02:00
m_commitProjectAction - > setParameter ( currentProjectName ) ;
2009-12-09 12:41:10 +01:00
2010-08-06 16:12:24 +02:00
m_diffRepositoryAction - > setEnabled ( hasTopLevel ) ;
m_statusRepositoryAction - > setEnabled ( hasTopLevel ) ;
m_updateRepositoryAction - > setEnabled ( hasTopLevel ) ;
2010-02-12 16:03:08 +01:00
m_commitAllAction - > setEnabled ( hasTopLevel ) ;
2010-08-06 16:12:24 +02:00
m_logRepositoryAction - > setEnabled ( hasTopLevel ) ;
m_uneditRepositoryAction - > setEnabled ( hasTopLevel ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : addCurrentFile ( )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2009-12-09 12:41:10 +01:00
vcsAdd ( state . currentFileTopLevel ( ) , state . relativeCurrentFile ( ) ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : revertAll ( )
2010-01-11 17:17:16 +01:00
{
2012-01-07 16:55:09 +01:00
const 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 ( ! messageBoxQuestion ( title , tr ( " Revert all pending changes to the repository? " ) ) )
2010-01-11 17:17:16 +01:00
return ;
QStringList args ;
args < < QLatin1String ( " update " ) < < QLatin1String ( " -C " ) < < state . topLevel ( ) ;
2012-01-07 16:55:09 +01:00
const CvsResponse revertResponse =
2013-10-15 20:03:22 +02:00
runCvs ( 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 . result = = CvsResponse : : Ok )
2010-01-11 17:17:16 +01:00
cvsVersionControl ( ) - > emitRepositoryChanged ( state . topLevel ( ) ) ;
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
QMessageBox : : warning ( 0 , title , tr ( " Revert failed: %1 " ) . arg ( revertResponse . message ) , QMessageBox : : Ok ) ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : revertCurrentFile ( )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2009-12-09 12:41:10 +01:00
QStringList args ;
args < < QLatin1String ( " diff " ) < < state . relativeCurrentFile ( ) ;
2012-01-07 16:55:09 +01:00
const CvsResponse diffResponse =
2013-10-15 20:03:22 +02:00
runCvs ( state . currentFileTopLevel ( ) , args , m_settings . timeOutMs ( ) , 0 ) ;
2009-07-15 12:28:40 +02:00
switch ( diffResponse . result ) {
2012-01-07 16:55:09 +01:00
case CvsResponse : : Ok :
2009-07-15 12:28:40 +02:00
return ; // Not modified, diff exit code 0
2012-01-07 16:55:09 +01:00
case CvsResponse : : NonNullExitCode : // Diff exit code != 0
2009-07-15 12:28:40 +02:00
if ( diffResponse . stdOut . isEmpty ( ) ) // Paranoia: Something else failed?
return ;
break ;
2012-01-07 16:55:09 +01:00
case CvsResponse : : OtherError :
2009-07-15 12:28:40 +02:00
return ;
}
2010-08-06 16:12:24 +02:00
if ( ! messageBoxQuestion ( QLatin1String ( " CVS Revert " ) ,
tr ( " The file has been changed. Do you want to revert it? " ) ) )
2009-07-15 12:28:40 +02:00
return ;
2012-01-07 16:55:09 +01:00
FileChangeBlocker fcb ( state . currentFile ( ) ) ;
2009-07-15 12:28:40 +02:00
// revert
2009-12-09 12:41:10 +01:00
args . clear ( ) ;
args < < QLatin1String ( " update " ) < < QLatin1String ( " -C " ) < < state . relativeCurrentFile ( ) ;
2012-01-07 16:55:09 +01:00
const CvsResponse revertResponse =
2013-10-15 20:03:22 +02:00
runCvs ( 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 . result = = CvsResponse : : Ok )
2009-12-09 12:41:10 +01:00
cvsVersionControl ( ) - > emitFilesChanged ( QStringList ( state . currentFile ( ) ) ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : diffProject ( )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasProject ( ) , return ) ;
2013-08-06 15:14:54 +03:00
const QString relativeProject = state . relativeCurrentProject ( ) ;
2013-10-15 20:03:22 +02:00
m_client - > diff ( state . currentProjectTopLevel ( ) ,
2013-08-06 15:14:54 +03:00
relativeProject . isEmpty ( ) ? QStringList ( ) : QStringList ( relativeProject ) ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : diffCurrentFile ( )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2013-10-15 20:03:22 +02:00
m_client - > diff ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : startCommitCurrentFile ( )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2013-08-06 15:14:54 +03:00
startCommit ( state . currentFileTopLevel ( ) , state . relativeCurrentFile ( ) ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : startCommitAll ( )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2009-12-09 12:41:10 +01:00
startCommit ( state . topLevel ( ) ) ;
2009-07-15 12:28:40 +02: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 . */
2013-08-06 15:14:54 +03:00
void CvsPlugin : : startCommit ( const QString & workingDir , const QString & file )
2009-07-15 12:28:40 +02:00
{
2013-04-18 12:06:43 +02:00
if ( raiseSubmitEditor ( ) )
2009-07-15 12:28:40 +02:00
return ;
2009-09-22 12:23:44 +02:00
if ( isCommitEditorOpen ( ) ) {
2012-01-07 16:55:09 +01:00
VcsBaseOutputWindow : : instance ( ) - > appendWarning ( tr ( " Another commit is currently being executed. " ) ) ;
2009-07-15 12:28:40 +02:00
return ;
}
2009-12-09 12:41:10 +01:00
2009-07-15 12:28:40 +02:00
// We need the "Examining <subdir>" stderr output to tell
// where we are, so, have stdout/stderr channels merged.
2009-07-16 09:24:44 +02:00
QStringList args = QStringList ( QLatin1String ( " status " ) ) ;
2012-01-07 16:55:09 +01:00
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( workingDir , args , m_settings . timeOutMs ( ) , MergeOutputChannels ) ;
2012-01-07 16:55:09 +01:00
if ( response . result ! = CvsResponse : : Ok )
2009-07-15 12:28:40 +02:00
return ;
2009-12-09 12:41:10 +01:00
// Get list of added/modified/deleted files and purge out undesired ones
// (do not run status with relative arguments as it will omit the directories)
StateList statusOutput = parseStatusOutput ( QString ( ) , response . stdOut ) ;
2013-08-06 15:14:54 +03:00
if ( ! file . isEmpty ( ) ) {
2009-12-09 12:41:10 +01:00
for ( StateList : : iterator it = statusOutput . begin ( ) ; it ! = statusOutput . end ( ) ; ) {
2013-08-06 15:14:54 +03:00
if ( file = = it - > second )
2009-12-09 12:41:10 +01:00
+ + it ;
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
2009-12-09 12:41:10 +01:00
it = statusOutput . erase ( it ) ;
}
}
2009-07-15 12:28:40 +02:00
if ( statusOutput . empty ( ) ) {
2013-08-11 22:35:49 +03:00
VcsBaseOutputWindow : : instance ( ) - > appendWarning ( tr ( " There are no modified files. " ) ) ;
2009-07-15 12:28:40 +02:00
return ;
}
2009-12-09 12:41:10 +01:00
m_commitRepository = workingDir ;
2009-07-15 12:28:40 +02: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 ) ;
2009-07-15 12:28:40 +02:00
// TODO: Retrieve submit template from
const QString submitTemplate ;
// Create a submit
2011-03-30 15:15:15 +02:00
saver . write ( submitTemplate . toUtf8 ( ) ) ;
if ( ! saver . finalize ( ) ) {
2012-01-07 16:55:09 +01:00
VcsBaseOutputWindow : : instance ( ) - > appendError ( saver . errorString ( ) ) ;
2011-03-30 15:15:15 +02:00
return ;
}
m_commitMessageFileName = saver . fileName ( ) ;
2009-07-15 12:28:40 +02:00
// Create a submit editor and set file list
2012-01-07 16:55:09 +01:00
CvsSubmitEditor * editor = openCVSSubmitEditor ( m_commitMessageFileName ) ;
2013-04-18 12:06:43 +02:00
setSubmitEditor ( editor ) ;
2009-12-14 10:56:50 +01:00
editor - > setCheckScriptWorkingDirectory ( m_commitRepository ) ;
2009-07-15 12:28:40 +02:00
editor - > setStateList ( statusOutput ) ;
}
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : commit ( const QString & messageFile ,
2009-07-15 12:28:40 +02:00
const QStringList & fileList )
{
2013-09-03 15:40:05 +02:00
if ( Constants : : debug )
2009-07-15 12:28:40 +02:00
qDebug ( ) < < Q_FUNC_INFO < < messageFile < < fileList ;
QStringList args = QStringList ( QLatin1String ( " commit " ) ) ;
args < < QLatin1String ( " -F " ) < < messageFile ;
2009-12-09 12:41:10 +01:00
args . append ( fileList ) ;
2012-01-07 16:55:09 +01:00
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( m_commitRepository , args , 10 * m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2012-01-07 16:55:09 +01:00
return response . result = = CvsResponse : : Ok ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : filelogCurrentFile ( )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const 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 ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : logProject ( )
2010-01-07 11:33:30 +01:00
{
2012-01-07 16:55:09 +01:00
const 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 ( ) ) ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : logRepository ( )
2010-01-07 11:33:30 +01:00
{
2012-01-07 16:55:09 +01:00
const 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 ( ) ) ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : 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 )
2009-07-15 12:28:40 +02:00
{
2013-08-06 15:14:54 +03:00
QTextCodec * codec = VcsBaseEditorWidget : : getCodec ( workingDir , QStringList ( file ) ) ;
2009-07-15 12:28:40 +02:00
// no need for temp file
2013-08-06 15:14:54 +03:00
const QString id = VcsBaseEditorWidget : : getTitleId ( workingDir , QStringList ( file ) ) ;
const QString source = VcsBaseEditorWidget : : getSource ( workingDir , file ) ;
2009-12-09 12:41:10 +01:00
QStringList args ;
args < < QLatin1String ( " log " ) ;
2013-08-06 15:14:54 +03:00
args . append ( file ) ;
2012-01-07 16:55:09 +01:00
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( workingDir , args , m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
SshPasswordPrompt , codec ) ;
2012-01-07 16:55:09 +01:00
if ( response . result ! = CvsResponse : : Ok )
2009-07-15 12:28:40 +02:00
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 tag = VcsBaseEditorWidget : : editorTag ( LogOutput , workingDir , QStringList ( file ) ) ;
2012-01-07 16:55:09 +01:00
if ( Core : : IEditor * editor = 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 ) ;
2009-07-15 12:28:40 +02:00
} else {
2009-12-09 12:41:10 +01:00
const QString title = QString : : fromLatin1 ( " cvs log %1 " ) . arg ( id ) ;
2012-01-07 16:55:09 +01:00
Core : : IEditor * newEditor = showOutputInEditor ( title , response . stdOut , LogOutput , source , codec ) ;
VcsBaseEditorWidget : : tagEditor ( newEditor , tag ) ;
2010-01-07 11:33:30 +01:00
if ( enableAnnotationContextMenu )
2012-01-07 16:55:09 +01:00
VcsBaseEditorWidget : : getVcsBaseEditor ( newEditor ) - > setFileLogAnnotateEnabled ( true ) ;
2009-07-15 12:28:40 +02:00
}
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : updateProject ( )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasProject ( ) , return ) ;
2010-08-06 16:12:24 +02:00
update ( state . currentProjectTopLevel ( ) , state . relativeCurrentProject ( ) ) ;
}
2009-12-09 12:41:10 +01:00
2013-08-06 15:14:54 +03:00
bool CvsPlugin : : update ( const QString & topLevel , const QString & file )
2010-08-06 16:12:24 +02:00
{
QStringList args ( QLatin1String ( " update " ) ) ;
args . push_back ( QLatin1String ( " -dR " ) ) ;
2013-08-06 15:14:54 +03:00
if ( ! file . isEmpty ( ) )
args . append ( file ) ;
2012-01-07 16:55:09 +01:00
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( topLevel , args , 10 * m_settings . timeOutMs ( ) ,
2010-08-06 16:12:24 +02:00
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2012-01-07 16:55:09 +01:00
const bool ok = response . result = = CvsResponse : : Ok ;
2010-08-06 16:12:24 +02:00
if ( ok )
cvsVersionControl ( ) - > emitRepositoryChanged ( topLevel ) ;
return ok ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : editCurrentFile ( )
2010-08-06 16:12:24 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2010-08-06 16:12:24 +02:00
edit ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) ) ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : uneditCurrentFile ( )
2010-08-06 16:12:24 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2010-08-06 16:12:24 +02:00
unedit ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) ) ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : uneditCurrentRepository ( )
2010-08-06 16:12:24 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2010-08-06 16:12:24 +02:00
unedit ( state . topLevel ( ) , QStringList ( ) ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : annotateCurrentFile ( )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasFile ( ) , return ) ;
2009-12-09 12:41:10 +01:00
annotate ( state . currentFileTopLevel ( ) , state . relativeCurrentFile ( ) ) ;
2009-07-15 12:28:40 +02:00
}
2013-10-06 20:47:29 +03:00
void CvsPlugin : : vcsAnnotate ( const QString & workingDirectory , const QString & file ,
const QString & revision , int lineNumber )
2010-01-06 17:24:40 +01:00
{
2013-10-06 20:47:29 +03:00
annotate ( workingDirectory , file , revision , lineNumber ) ;
2010-01-06 17:24:40 +01:00
}
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : edit ( const QString & topLevel , const QStringList & files )
2010-08-06 16:12:24 +02:00
{
QStringList args ( QLatin1String ( " edit " ) ) ;
args . append ( files ) ;
2012-01-07 16:55:09 +01:00
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( topLevel , args , m_settings . timeOutMs ( ) ,
2010-08-06 16:12:24 +02:00
ShowStdOutInLogWindow | SshPasswordPrompt ) ;
2012-01-07 16:55:09 +01:00
return response . result = = CvsResponse : : Ok ;
2010-08-06 16:12:24 +02:00
}
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : diffCheckModified ( const QString & topLevel , const QStringList & files , bool * modified )
2010-08-06 16:12:24 +02:00
{
// Quick check for modified files using diff
* modified = false ;
QStringList args ( QLatin1String ( " -q " ) ) ;
args < < QLatin1String ( " diff " ) ;
args . append ( files ) ;
2013-10-15 20:03:22 +02:00
const CvsResponse response = runCvs ( topLevel , args , m_settings . timeOutMs ( ) , 0 ) ;
2012-01-07 16:55:09 +01:00
if ( response . result = = CvsResponse : : OtherError )
2010-08-06 16:12:24 +02:00
return false ;
2012-01-07 16:55:09 +01:00
* modified = response . result = = CvsResponse : : NonNullExitCode ;
2010-08-06 16:12:24 +02:00
return true ;
}
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : unedit ( const QString & topLevel , const QStringList & files )
2010-08-06 16:12:24 +02:00
{
bool modified ;
// Prompt and use force flag if modified
if ( ! diffCheckModified ( topLevel , files , & modified ) )
return false ;
if ( modified ) {
const QString question = files . isEmpty ( ) ?
tr ( " Would you like to discard your changes to the repository '%1'? " ) . arg ( topLevel ) :
tr ( " Would you like to discard your changes to the file '%1'? " ) . arg ( files . front ( ) ) ;
if ( ! messageBoxQuestion ( tr ( " Unedit " ) , question ) )
return false ;
}
QStringList args ( QLatin1String ( " unedit " ) ) ;
// Note: Option '-y' to force 'yes'-answer to CVS' 'undo change' prompt,
// exists in CVSNT only as of 6.8.2010. Standard CVS will otherwise prompt
if ( modified )
args . append ( QLatin1String ( " -y " ) ) ;
args . append ( files ) ;
2012-01-07 16:55:09 +01:00
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( topLevel , args , m_settings . timeOutMs ( ) ,
2010-08-06 16:12:24 +02:00
ShowStdOutInLogWindow | SshPasswordPrompt ) ;
2012-01-07 16:55:09 +01:00
return response . result = = CvsResponse : : Ok ;
2010-08-06 16:12:24 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : annotate ( const QString & workingDir , const QString & file ,
2010-01-06 17:24:40 +01:00
const QString & revision /* = QString() */ ,
int lineNumber /* = -1 */ )
2009-07-15 12:28:40 +02:00
{
2009-12-09 12:41:10 +01:00
const QStringList files ( file ) ;
2012-01-07 16:55:09 +01:00
QTextCodec * codec = VcsBaseEditorWidget : : getCodec ( workingDir , files ) ;
const QString id = VcsBaseEditorWidget : : getTitleId ( workingDir , files , revision ) ;
const QString source = VcsBaseEditorWidget : : getSource ( workingDir , file ) ;
2009-12-09 12:41:10 +01:00
QStringList args ;
2010-01-06 17:24:40 +01:00
args < < QLatin1String ( " annotate " ) ;
if ( ! revision . isEmpty ( ) )
args < < QLatin1String ( " -r " ) < < revision ;
args < < file ;
2012-01-07 16:55:09 +01:00
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( workingDir , args , m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
SshPasswordPrompt , codec ) ;
2012-01-07 16:55:09 +01:00
if ( response . result ! = CvsResponse : : Ok )
2009-07-15 12:28:40 +02:00
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 < 1 )
2012-01-07 16:55:09 +01:00
lineNumber = VcsBaseEditorWidget : : lineNumberOfCurrentEditor ( file ) ;
2009-07-15 12:28:40 +02:00
2012-01-07 16:55:09 +01:00
const QString tag = VcsBaseEditorWidget : : editorTag ( AnnotateOutput , workingDir , QStringList ( file ) , revision ) ;
if ( IEditor * editor = VcsBaseEditorWidget : : locateEditorByTag ( tag ) ) {
2013-07-15 15:14:10 +02:00
editor - > document ( ) - > setContents ( response . stdOut . toUtf8 ( ) ) ;
2012-01-07 16:55:09 +01:00
VcsBaseEditorWidget : : gotoLineOfEditor ( editor , lineNumber ) ;
2013-05-31 12:52:53 +02:00
EditorManager : : activateEditor ( editor ) ;
2009-07-15 12:28:40 +02:00
} else {
2009-12-09 12:41:10 +01:00
const QString title = QString : : fromLatin1 ( " cvs annotate %1 " ) . arg ( id ) ;
2012-01-07 16:55:09 +01:00
IEditor * newEditor = showOutputInEditor ( title , response . stdOut , AnnotateOutput , source , codec ) ;
VcsBaseEditorWidget : : tagEditor ( newEditor , tag ) ;
VcsBaseEditorWidget : : gotoLineOfEditor ( newEditor , lineNumber ) ;
2009-07-15 12:28:40 +02:00
}
}
2013-08-06 15:14:54 +03:00
bool CvsPlugin : : status ( const QString & topLevel , const QString & file , const QString & title )
2010-08-06 16:12:24 +02:00
{
QStringList args ( QLatin1String ( " status " ) ) ;
2013-08-06 15:14:54 +03:00
if ( ! file . isEmpty ( ) )
args . append ( file ) ;
2012-01-07 16:55:09 +01:00
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( topLevel , args , m_settings . timeOutMs ( ) , 0 ) ;
2012-01-07 16:55:09 +01:00
const bool ok = response . result = = CvsResponse : : Ok ;
2010-08-06 16:12:24 +02:00
if ( ok )
2013-05-22 21:32:07 +03:00
showOutputInEditor ( title , response . stdOut , OtherContent , topLevel , 0 ) ;
2010-08-06 16:12:24 +02:00
return ok ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : projectStatus ( )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasProject ( ) , return ) ;
2010-08-06 16:12:24 +02:00
status ( state . currentProjectTopLevel ( ) , state . relativeCurrentProject ( ) , tr ( " Project status " ) ) ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : commitProject ( )
2010-08-06 16:12:24 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasProject ( ) , return ) ;
2010-08-06 16:12:24 +02:00
startCommit ( state . currentProjectTopLevel ( ) , state . relativeCurrentProject ( ) ) ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : diffRepository ( )
2010-08-06 16:12:24 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2013-10-15 20:03:22 +02:00
m_client - > diff ( state . topLevel ( ) , QStringList ( ) ) ;
2010-08-06 16:12:24 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : statusRepository ( )
2010-08-06 16:12:24 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2013-08-06 15:14:54 +03:00
status ( state . topLevel ( ) , QString ( ) , tr ( " Repository status " ) ) ;
2010-08-06 16:12:24 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : updateRepository ( )
2010-08-06 16:12:24 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBasePluginState state = currentState ( ) ;
2012-04-17 08:01:25 +02:00
QTC_ASSERT ( state . hasTopLevel ( ) , return ) ;
2013-08-06 15:14:54 +03:00
update ( state . topLevel ( ) , QString ( ) ) ;
2010-08-06 16:12:24 +02:00
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : slotDescribe ( const QString & source , const QString & changeNr )
2009-07-15 12:28:40 +02:00
{
QString errorMessage ;
if ( ! describe ( source , changeNr , & errorMessage ) )
2012-01-07 16:55:09 +01:00
VcsBaseOutputWindow : : instance ( ) - > appendError ( errorMessage ) ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : describe ( const QString & file , const QString & changeNr , QString * errorMessage )
2009-07-15 12:28:40 +02:00
{
2010-05-20 16:24:39 +02:00
QString toplevel ;
const bool manages = managesDirectory ( QFileInfo ( file ) . absolutePath ( ) , & toplevel ) ;
if ( ! manages | | toplevel . isEmpty ( ) ) {
2009-12-09 12:41:10 +01:00
* errorMessage = msgCannotFindTopLevel ( file ) ;
return false ;
}
return describe ( toplevel , QDir ( toplevel ) . relativeFilePath ( file ) , changeNr , errorMessage ) ;
}
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : describe ( const QString & toplevel , const QString & file , const
2009-12-09 12:41:10 +01:00
QString & changeNr , QString * errorMessage )
{
2009-07-15 12:28:40 +02:00
// In CVS, revisions of files are normally unrelated, there is
// no global revision/change number. The only thing that groups
// a commit is the "commit-id" (as shown in the log).
// This function makes use of it to find all files related to
// a commit in order to emulate a "describe global change" functionality
// if desired.
2013-09-03 15:40:05 +02:00
if ( Constants : : debug )
2009-07-15 12:28:40 +02:00
qDebug ( ) < < Q_FUNC_INFO < < file < < changeNr ;
// Number must be > 1
2009-07-16 09:24:44 +02:00
if ( isFirstRevision ( changeNr ) ) {
2009-07-15 12:28:40 +02:00
* errorMessage = tr ( " The initial revision %1 cannot be described. " ) . arg ( changeNr ) ;
return false ;
}
// Run log to obtain commit id and details
2009-12-09 12:41:10 +01:00
QStringList args ;
args < < QLatin1String ( " log " ) < < ( QLatin1String ( " -r " ) + changeNr ) < < file ;
2012-01-07 16:55:09 +01:00
const CvsResponse logResponse =
2013-10-15 20:03:22 +02:00
runCvs ( toplevel , args , m_settings . timeOutMs ( ) , SshPasswordPrompt ) ;
2012-01-07 16:55:09 +01:00
if ( logResponse . result ! = CvsResponse : : Ok ) {
2009-07-15 12:28:40 +02:00
* errorMessage = logResponse . message ;
return false ;
}
2012-01-07 16:55:09 +01:00
const QList < CvsLogEntry > fileLog = parseLogEntries ( logResponse . stdOut ) ;
2009-07-15 12:28:40 +02:00
if ( fileLog . empty ( ) | | fileLog . front ( ) . revisions . empty ( ) ) {
* errorMessage = msgLogParsingFailed ( ) ;
return false ;
}
2013-10-15 20:03:22 +02:00
if ( m_settings . boolValue ( CvsSettings : : describeByCommitIdKey ) ) {
2009-07-15 12:28:40 +02:00
// Run a log command over the repo, filtering by the commit date
// and commit id, collecting all files touched by the commit.
const QString commitId = fileLog . front ( ) . revisions . front ( ) . commitId ;
// Date range "D1<D2" in ISO format "YYYY-MM-DD"
const QString dateS = fileLog . front ( ) . revisions . front ( ) . date ;
const QDate date = QDate : : fromString ( dateS , Qt : : ISODate ) ;
const QString nextDayS = date . addDays ( 1 ) . toString ( Qt : : ISODate ) ;
args . clear ( ) ;
args < < QLatin1String ( " log " ) < < QLatin1String ( " -d " ) < < ( dateS + QLatin1Char ( ' < ' ) + nextDayS ) ;
2009-12-09 12:41:10 +01:00
2012-01-07 16:55:09 +01:00
const CvsResponse repoLogResponse =
2013-10-15 20:03:22 +02:00
runCvs ( toplevel , args , 10 * m_settings . timeOutMs ( ) , SshPasswordPrompt ) ;
2012-01-07 16:55:09 +01:00
if ( repoLogResponse . result ! = CvsResponse : : Ok ) {
2009-07-15 12:28:40 +02:00
* errorMessage = repoLogResponse . message ;
return false ;
}
// Describe all files found, pass on dir to obtain correct absolute paths.
2012-01-07 16:55:09 +01:00
const QList < CvsLogEntry > repoEntries = parseLogEntries ( repoLogResponse . stdOut , QString ( ) , commitId ) ;
2009-07-15 12:28:40 +02:00
if ( repoEntries . empty ( ) ) {
* errorMessage = tr ( " Could not find commits of id '%1' on %2. " ) . arg ( commitId , dateS ) ;
return false ;
}
return describe ( toplevel , repoEntries , errorMessage ) ;
} else {
// Just describe that single entry
return describe ( toplevel , fileLog , errorMessage ) ;
}
return false ;
}
// Describe a set of files and revisions by
// concatenating log and diffs to previous revisions
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : describe ( const QString & repositoryPath ,
QList < CvsLogEntry > entries ,
2009-07-15 12:28:40 +02:00
QString * errorMessage )
{
// Collect logs
QString output ;
QTextCodec * codec = 0 ;
2012-01-07 16:55:09 +01:00
const QList < CvsLogEntry > : : iterator lend = entries . end ( ) ;
for ( QList < CvsLogEntry > : : iterator it = entries . begin ( ) ; it ! = lend ; + + it ) {
2009-07-15 12:28:40 +02:00
// Before fiddling file names, try to find codec
if ( ! codec )
2012-01-07 16:55:09 +01:00
codec = VcsBaseEditorWidget : : getCodec ( repositoryPath , QStringList ( it - > file ) ) ;
2009-07-15 12:28:40 +02:00
// Run log
QStringList args ( QLatin1String ( " log " ) ) ;
args < < ( QLatin1String ( " -r " ) + it - > revisions . front ( ) . revision ) < < it - > file ;
2012-01-07 16:55:09 +01:00
const CvsResponse logResponse =
2013-10-15 20:03:22 +02:00
runCvs ( repositoryPath , args , m_settings . timeOutMs ( ) , SshPasswordPrompt ) ;
2012-01-07 16:55:09 +01:00
if ( logResponse . result ! = CvsResponse : : Ok ) {
2009-07-15 12:28:40 +02:00
* errorMessage = logResponse . message ;
return false ;
}
output + = logResponse . stdOut ;
}
// Collect diffs relative to repository
2012-01-07 16:55:09 +01:00
for ( QList < CvsLogEntry > : : iterator it = entries . begin ( ) ; it ! = lend ; + + it ) {
2009-07-16 09:24:44 +02:00
const QString & revision = it - > revisions . front ( ) . revision ;
if ( ! isFirstRevision ( revision ) ) {
const QString previousRev = previousRevision ( revision ) ;
QStringList args ( QLatin1String ( " diff " ) ) ;
2013-10-15 20:03:22 +02:00
args < < m_settings . stringValue ( CvsSettings : : diffOptionsKey ) < < QLatin1String ( " -r " ) < < previousRev
2009-07-16 09:24:44 +02:00
< < QLatin1String ( " -r " ) < < it - > revisions . front ( ) . revision
< < it - > file ;
2012-01-07 16:55:09 +01:00
const CvsResponse diffResponse =
2013-10-15 20:03:22 +02:00
runCvs ( repositoryPath , args , m_settings . timeOutMs ( ) , 0 , codec ) ;
2009-07-16 09:24:44 +02:00
switch ( diffResponse . result ) {
2012-01-07 16:55:09 +01:00
case CvsResponse : : Ok :
case CvsResponse : : NonNullExitCode : // Diff exit code != 0
2009-07-16 09:24:44 +02:00
if ( diffResponse . stdOut . isEmpty ( ) ) {
* errorMessage = diffResponse . message ;
return false ; // Something else failed.
}
break ;
2012-01-07 16:55:09 +01:00
case CvsResponse : : OtherError :
2009-07-15 12:28:40 +02:00
* errorMessage = diffResponse . message ;
2009-07-16 09:24:44 +02:00
return false ;
2009-07-15 12:28:40 +02:00
}
2009-07-16 09:24:44 +02:00
output + = fixDiffOutput ( diffResponse . stdOut ) ;
2009-07-15 12:28:40 +02:00
}
}
// Re-use an existing view if possible to support
// the common usage pattern of continuously changing and diffing a file
const QString commitId = entries . front ( ) . revisions . front ( ) . commitId ;
2012-01-07 16:55:09 +01:00
if ( IEditor * editor = VcsBaseEditorWidget : : locateEditorByTag ( commitId ) ) {
2013-07-15 15:14:10 +02:00
editor - > document ( ) - > setContents ( output . toUtf8 ( ) ) ;
2013-05-31 12:52:53 +02:00
EditorManager : : activateEditor ( editor ) ;
2009-12-09 12:41:10 +01:00
setDiffBaseDirectory ( editor , repositoryPath ) ;
2009-07-15 12:28:40 +02:00
} else {
const QString title = QString : : fromLatin1 ( " cvs describe %1 " ) . arg ( commitId ) ;
2012-01-07 16:55:09 +01:00
IEditor * newEditor = showOutputInEditor ( title , output , DiffOutput , entries . front ( ) . file , codec ) ;
VcsBaseEditorWidget : : tagEditor ( newEditor , commitId ) ;
2010-05-21 14:19:12 +02:00
setDiffBaseDirectory ( newEditor , repositoryPath ) ;
2009-07-15 12:28:40 +02:00
}
return true ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : submitCurrentLog ( )
2009-07-15 12:28:40 +02:00
{
m_submitActionTriggered = true ;
2013-08-29 15:46:04 +02:00
EditorManager : : closeEditor ( EditorManager : : currentEditor ( ) ) ;
2009-07-15 12:28:40 +02:00
}
// Run CVS. At this point, file arguments must be relative to
// the working directory (see above).
2012-01-07 16:55:09 +01:00
CvsResponse CvsPlugin : : runCvs ( const QString & workingDirectory ,
2009-07-15 12:28:40 +02:00
const QStringList & arguments ,
int timeOut ,
2010-05-21 17:46:00 +02:00
unsigned flags ,
2013-10-02 00:18:39 +03:00
QTextCodec * outputCodec ) const
2009-07-15 12:28:40 +02:00
{
2013-10-15 20:03:22 +02:00
const QString executable = m_settings . binaryPath ( ) ;
2012-01-07 16:55:09 +01:00
CvsResponse response ;
2009-07-15 12:28:40 +02:00
if ( executable . isEmpty ( ) ) {
2012-01-07 16:55:09 +01:00
response . result = CvsResponse : : OtherError ;
2009-07-15 12:28:40 +02:00
response . message = tr ( " No cvs executable specified! " ) ;
return response ;
}
// Run, connect stderr to the output window
2010-05-21 17:46:00 +02:00
const Utils : : SynchronousProcessResponse sp_resp =
2013-08-16 17:02:30 +03:00
runVcs ( workingDirectory , executable , m_settings . addOptions ( arguments ) ,
2013-08-28 11:32:33 +03:00
timeOut , flags , outputCodec ) ;
2009-07-15 12:28:40 +02:00
2012-01-07 16:55:09 +01:00
response . result = CvsResponse : : OtherError ;
2009-07-15 12:28:40 +02:00
response . stdErr = sp_resp . stdErr ;
response . stdOut = sp_resp . stdOut ;
switch ( sp_resp . result ) {
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : Finished :
2012-01-07 16:55:09 +01:00
response . result = CvsResponse : : Ok ;
2009-07-15 12:28:40 +02:00
break ;
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : FinishedError :
2012-01-07 16:55:09 +01:00
response . result = CvsResponse : : NonNullExitCode ;
2009-07-15 12:28:40 +02:00
break ;
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : TerminatedAbnormally :
case Utils : : SynchronousProcessResponse : : StartFailed :
case Utils : : SynchronousProcessResponse : : Hang :
2009-07-15 12:28:40 +02:00
break ;
}
2010-05-21 17:46:00 +02:00
2012-01-07 16:55:09 +01:00
if ( response . result ! = CvsResponse : : Ok )
2010-05-21 17:46:00 +02:00
response . message = sp_resp . exitMessage ( executable , timeOut ) ;
2009-07-15 12:28:40 +02:00
return response ;
}
2012-01-07 16:55:09 +01:00
IEditor * CvsPlugin : : showOutputInEditor ( const QString & title , const QString & output ,
int editorType , const QString & source ,
QTextCodec * codec )
2009-07-15 12:28:40 +02:00
{
2012-01-07 16:55:09 +01:00
const VcsBaseEditorParameters * params = findType ( editorType ) ;
2009-07-15 12:28:40 +02:00
QTC_ASSERT ( params , return 0 ) ;
2013-03-19 18:27:04 +01:00
const Id id = params - > id ;
2013-09-03 15:40:05 +02:00
if ( Constants : : debug )
2011-11-10 11:36:51 +01:00
qDebug ( ) < < " CVSPlugin::showOutputInEditor " < < title < < id . name ( )
< < " source= " < < source < < " Size= " < < output . size ( ) < < " Type= " < < editorType < < debugCodec ( codec ) ;
2009-07-15 12:28:40 +02:00
QString s = title ;
2013-07-15 15:14:10 +02:00
IEditor * editor = EditorManager : : openEditorWithContents ( id , & s , output . toUtf8 ( ) ) ;
2013-10-06 20:47:29 +03:00
connect ( editor , SIGNAL ( annotateRevisionRequested ( QString , QString , QString , int ) ) ,
this , SLOT ( vcsAnnotate ( QString , QString , QString , int ) ) ) ;
2012-01-07 16:55:09 +01:00
CvsEditor * e = qobject_cast < CvsEditor * > ( editor - > widget ( ) ) ;
2009-07-15 12:28:40 +02:00
if ( ! e )
return 0 ;
s . replace ( QLatin1Char ( ' ' ) , QLatin1Char ( ' _ ' ) ) ;
e - > setSuggestedFileName ( s ) ;
2010-06-07 14:53:28 +02:00
e - > setForceReadOnly ( true ) ;
2009-07-15 12:28:40 +02:00
if ( ! source . isEmpty ( ) )
e - > setSource ( source ) ;
if ( codec )
e - > setCodec ( codec ) ;
2012-01-07 16:55:09 +01:00
IEditor * ie = e - > editor ( ) ;
2013-05-31 12:52:53 +02:00
EditorManager : : activateEditor ( ie ) ;
2009-07-15 12:28:40 +02:00
return ie ;
}
2012-01-07 16:55:09 +01:00
CvsSettings CvsPlugin : : settings ( ) const
2009-07-15 12:28:40 +02:00
{
return m_settings ;
}
2012-01-07 16:55:09 +01:00
void CvsPlugin : : setSettings ( const CvsSettings & s )
2009-07-15 12:28:40 +02:00
{
if ( s ! = m_settings ) {
m_settings = s ;
2013-10-15 20:03:22 +02:00
m_settings . writeSettings ( ICore : : settings ( ) ) ;
2011-04-15 17:43:44 +02:00
cvsVersionControl ( ) - > emitConfigurationChanged ( ) ;
2009-07-15 12:28:40 +02:00
}
}
2012-01-07 16:55:09 +01:00
CvsPlugin * CvsPlugin : : instance ( )
2009-07-15 12:28:40 +02:00
{
QTC_ASSERT ( m_cvsPluginInstance , return m_cvsPluginInstance ) ;
return m_cvsPluginInstance ;
}
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : vcsAdd ( const QString & workingDir , const QString & rawFileName )
2009-07-15 12:28:40 +02:00
{
2009-12-09 12:41:10 +01:00
QStringList args ;
args < < QLatin1String ( " add " ) < < rawFileName ;
2012-01-07 16:55:09 +01:00
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( workingDir , args , m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2012-01-07 16:55:09 +01:00
return response . result = = CvsResponse : : Ok ;
2009-07-15 12:28:40 +02:00
}
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : vcsDelete ( const QString & workingDir , const QString & rawFileName )
2009-07-15 12:28:40 +02:00
{
2009-12-09 12:41:10 +01:00
QStringList args ;
args < < QLatin1String ( " remove " ) < < QLatin1String ( " -f " ) < < rawFileName ;
2012-01-07 16:55:09 +01:00
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( workingDir , args , m_settings . timeOutMs ( ) ,
2010-05-21 17:46:00 +02:00
SshPasswordPrompt | ShowStdOutInLogWindow ) ;
2012-01-07 16:55:09 +01:00
return response . result = = CvsResponse : : Ok ;
2009-07-15 12:28:40 +02:00
}
/* CVS has a "CVS" directory in each directory it manages. The top level
* is the first directory under the directory that does not have it . */
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : managesDirectory ( const QString & directory , QString * topLevel /* = 0 */ ) const
2009-07-15 12:28:40 +02:00
{
2010-05-20 16:24:39 +02:00
if ( topLevel )
topLevel - > clear ( ) ;
bool manages = false ;
2009-07-15 12:28:40 +02:00
const QDir dir ( directory ) ;
2010-05-20 16:24:39 +02:00
do {
if ( ! dir . exists ( ) | | ! checkCVSDirectory ( dir ) )
break ;
manages = true ;
if ( ! topLevel )
break ;
/* Recursing up, the top level is a child of the first directory that does
* not have a " CVS " directory . The starting directory must be a managed
* one . Go up and try to find the first unmanaged parent dir . */
QDir lastDirectory = dir ;
2013-12-03 08:15:44 +02:00
for ( QDir parentDir = lastDirectory ;
! parentDir . isRoot ( ) & & parentDir . cdUp ( ) ;
lastDirectory = parentDir ) {
2010-05-20 16:24:39 +02:00
if ( ! checkCVSDirectory ( parentDir ) ) {
* topLevel = lastDirectory . absolutePath ( ) ;
break ;
}
}
} while ( false ) ;
2013-09-03 15:40:05 +02:00
if ( Constants : : debug ) {
2010-05-20 16:24:39 +02:00
QDebug nsp = qDebug ( ) . nospace ( ) ;
nsp < < " CVSPlugin::managesDirectory " < < directory < < manages ;
if ( topLevel )
nsp < < * topLevel ;
}
return manages ;
2009-07-15 12:28:40 +02:00
}
2013-10-02 00:18:39 +03:00
bool CvsPlugin : : managesFile ( const QString & workingDirectory , const QString & fileName ) const
{
QStringList args ;
args < < QLatin1String ( " status " ) < < fileName ;
const CvsResponse response =
2013-10-15 20:03:22 +02:00
runCvs ( workingDirectory , args , m_settings . timeOutMs ( ) , SshPasswordPrompt ) ;
2013-10-02 00:18:39 +03:00
if ( response . result ! = CvsResponse : : Ok )
return false ;
return ! response . stdOut . contains ( QLatin1String ( " Status: Unknown " ) ) ;
}
2012-01-07 16:55:09 +01:00
bool CvsPlugin : : checkCVSDirectory ( const QDir & directory ) const
2009-07-15 12:28:40 +02:00
{
const QString cvsDir = directory . absoluteFilePath ( QLatin1String ( " CVS " ) ) ;
return QFileInfo ( cvsDir ) . isDir ( ) ;
}
2012-01-07 16:55:09 +01:00
CvsControl * CvsPlugin : : cvsVersionControl ( ) const
2009-12-08 14:26:41 +01:00
{
2012-01-07 16:55:09 +01:00
return static_cast < CvsControl * > ( versionControl ( ) ) ;
2009-12-08 14:26:41 +01:00
}
2013-01-21 22:56:01 +02:00
# ifdef WITH_TESTS
void CvsPlugin : : testDiffFileResolving_data ( )
{
QTest : : addColumn < QByteArray > ( " header " ) ;
QTest : : addColumn < QByteArray > ( " fileName " ) ;
QTest : : newRow ( " Modified " ) < < QByteArray (
" Index: src/plugins/cvs/cvseditor.cpp \n "
" =================================================================== \n "
" --- src/plugins/cvs/cvseditor.cpp \t 21 Jan 2013 20:34:20 -0000 \t 1.1 \n "
" +++ src/plugins/cvs/cvseditor.cpp \t 21 Jan 2013 20:34:28 -0000 \n "
" @@ -120,7 +120,7 @@ \n \n " )
< < QByteArray ( " src/plugins/cvs/cvseditor.cpp " ) ;
}
void CvsPlugin : : testDiffFileResolving ( )
{
CvsEditor editor ( editorParameters + 3 , 0 ) ;
2013-01-28 20:50:05 +02:00
editor . testDiffFileResolving ( ) ;
2013-01-21 22:56:01 +02:00
}
2013-01-28 22:02:35 +02:00
void CvsPlugin : : testLogResolving ( )
{
QByteArray data (
" RCS file: /sources/cvs/ccvs/Attic/FIXED-BUGS,v \n "
" Working file: FIXED-BUGS \n "
" head: 1.3 \n "
" branch: \n "
" locks: strict \n "
" access list: \n "
" symbolic names: \n "
" keyword substitution: kv \n "
" total revisions: 3; selected revisions: 3 \n "
" description: \n "
" ---------------------------- \n "
" revision 1.3 \n "
" date: 1995-04-29 06:22:41 +0300; author: jimb; state: dead; lines: +0 -0; \n "
" *** empty log message *** \n "
" ---------------------------- \n "
" revision 1.2 \n "
" date: 1995-04-28 18:52:24 +0300; author: noel; state: Exp; lines: +6 -0; \n "
" added latest commentary \n "
" ---------------------------- \n "
) ;
CvsEditor editor ( editorParameters + 1 , 0 ) ;
editor . testLogResolving ( data , " 1.3 " , " 1.2 " ) ;
}
2013-01-21 22:56:01 +02:00
# endif
2011-11-02 16:45:13 +01:00
} // namespace Internal
2012-01-07 16:55:09 +01:00
} // namespace Cvs
2011-11-02 16:45:13 +01:00
2012-01-07 16:55:09 +01:00
Q_EXPORT_PLUGIN ( Cvs : : Internal : : CvsPlugin )