2009-07-15 12:28:40 +02:00
/**************************************************************************
* *
* * This file is part of Qt Creator
* *
2010-03-05 11:25:49 +01:00
* * Copyright ( c ) 2010 Nokia Corporation and / or its subsidiary ( - ies ) .
2009-07-15 12:28:40 +02:00
* *
* * Contact : Nokia Corporation ( qt - info @ nokia . com )
* *
* * Commercial Usage
* *
* * Licensees holding valid Qt Commercial licenses may use this file in
* * accordance with the Qt Commercial License Agreement provided with the
* * Software or , alternatively , in accordance with the terms contained in
* * a written agreement between you and Nokia .
* *
* * GNU Lesser General Public License Usage
* *
* * 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.
* *
* * If you are unsure which license is appropriate for your use , please
2009-08-14 09:30:56 +02:00
* * contact the sales department at http : //qt.nokia.com/contact.
2009-07-15 12:28:40 +02:00
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "cvsplugin.h"
# include "settingspage.h"
# include "cvseditor.h"
# include "cvssubmiteditor.h"
# 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>
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>
# include <coreplugin/icore.h>
# include <coreplugin/coreconstants.h>
# include <coreplugin/filemanager.h>
# include <coreplugin/messagemanager.h>
# include <coreplugin/mimedatabase.h>
# include <coreplugin/uniqueidmanager.h>
# include <coreplugin/actionmanager/actionmanager.h>
2010-03-18 10:59:06 +01:00
# include <coreplugin/actionmanager/actioncontainer.h>
# include <coreplugin/actionmanager/command.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>
2009-07-15 12:28:40 +02:00
# include <utils/qtcassert.h>
# include <QtCore/QDebug>
# include <QtCore/QDate>
# include <QtCore/QDir>
# include <QtCore/QFileInfo>
# include <QtCore/QTextCodec>
# include <QtCore/QtPlugin>
2009-09-22 12:23:44 +02:00
# include <QtCore/QTemporaryFile>
2009-07-15 12:28:40 +02:00
# include <QtGui/QAction>
# include <QtGui/QMainWindow>
# include <QtGui/QMenu>
# include <QtGui/QMessageBox>
namespace CVS {
namespace Internal {
static inline QString msgCannotFindTopLevel ( const QString & f )
{
return CVSPlugin : : tr ( " Cannot find repository for '%1' " ) . arg ( f ) ;
}
static inline QString msgLogParsingFailed ( )
{
return CVSPlugin : : tr ( " Parsing of the log output failed " ) ;
}
static const char * const CMD_ID_CVS_MENU = " CVS.Menu " ;
static const char * const CMD_ID_ADD = " CVS.Add " ;
static const char * const CMD_ID_DELETE_FILE = " CVS.Delete " ;
static const char * const CMD_ID_REVERT = " CVS.Revert " ;
static const char * const CMD_ID_SEPARATOR0 = " CVS.Separator0 " ;
static const char * const CMD_ID_DIFF_PROJECT = " CVS.DiffAll " ;
static const char * const CMD_ID_DIFF_CURRENT = " CVS.DiffCurrent " ;
static const char * const CMD_ID_SEPARATOR1 = " CVS.Separator1 " ;
static const char * const CMD_ID_COMMIT_ALL = " CVS.CommitAll " ;
2010-01-11 17:17:16 +01:00
static const char * const CMD_ID_REVERT_ALL = " CVS.RevertAll " ;
2009-07-15 12:28:40 +02:00
static const char * const CMD_ID_COMMIT_CURRENT = " CVS.CommitCurrent " ;
static const char * const CMD_ID_SEPARATOR2 = " CVS.Separator2 " ;
static const char * const CMD_ID_FILELOG_CURRENT = " CVS.FilelogCurrent " ;
static const char * const CMD_ID_ANNOTATE_CURRENT = " CVS.AnnotateCurrent " ;
static const char * const CMD_ID_STATUS = " CVS.Status " ;
static const char * const CMD_ID_UPDATE = " CVS.Update " ;
2010-01-07 11:33:30 +01:00
static const char * const CMD_ID_PROJECTLOG = " CVS.ProjectLog " ;
static const char * const CMD_ID_REPOSITORYLOG = " CVS.RepositoryLog " ;
2009-07-15 12:28:40 +02:00
static const VCSBase : : VCSBaseEditorParameters editorParameters [ ] = {
{
VCSBase : : RegularCommandOutput ,
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
" application/vnd.nokia.text.scs_cvs_commandlog " ,
" scslog " } ,
{ VCSBase : : 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
" application/vnd.nokia.text.scs_cvs_filelog " ,
" scsfilelog " } ,
{ VCSBase : : 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
" application/vnd.nokia.text.scs_cvs_annotation " ,
" scsannotate " } ,
{ VCSBase : : 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
" text/x-patch " , " diff " }
} ;
// Utility to find a parameter set by type
static inline const VCSBase : : VCSBaseEditorParameters * findType ( int ie )
{
const VCSBase : : EditorContentType et = static_cast < VCSBase : : EditorContentType > ( ie ) ;
return VCSBase : : VCSBaseEditor : : findType ( editorParameters , sizeof ( editorParameters ) / sizeof ( VCSBase : : VCSBaseEditorParameters ) , et ) ;
}
static inline QString debugCodec ( const QTextCodec * c )
{
return c ? QString : : fromAscii ( c - > name ( ) ) : QString : : fromAscii ( " Null codec " ) ;
}
Core : : IEditor * locateEditor ( const char * property , const QString & entry )
{
foreach ( Core : : IEditor * ed , Core : : EditorManager : : instance ( ) - > openedEditors ( ) )
if ( ed - > property ( property ) . toString ( ) = = entry )
return ed ;
return 0 ;
}
// ------------- CVSPlugin
CVSPlugin * CVSPlugin : : m_cvsPluginInstance = 0 ;
CVSPlugin : : CVSPlugin ( ) :
2010-01-08 09:48:54 +01:00
VCSBase : : VCSBasePlugin ( QLatin1String ( CVS : : Constants : : CVSCOMMITEDITOR_ID ) ) ,
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 ) ,
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 ) ,
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 )
{
}
CVSPlugin : : ~ CVSPlugin ( )
{
2009-09-22 12:23:44 +02:00
cleanCommitMessageFile ( ) ;
2009-07-15 12:28:40 +02:00
}
2009-09-22 12:23:44 +02: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
}
}
2009-09-22 12:23:44 +02:00
bool CVSPlugin : : isCommitEditorOpen ( ) const
{
return ! m_commitMessageFileName . isEmpty ( ) ;
}
2009-07-15 12:28:40 +02:00
static const VCSBase : : VCSBaseSubmitEditorParameters submitParameters = {
CVS : : Constants : : CVS_SUBMIT_MIMETYPE ,
2010-01-08 09:48:54 +01:00
CVS : : Constants : : CVSCOMMITEDITOR_ID ,
CVS : : Constants : : CVSCOMMITEDITOR_DISPLAY_NAME ,
2009-07-15 12:28:40 +02:00
CVS : : Constants : : CVSCOMMITEDITOR
} ;
static inline Core : : Command * createSeparator ( QObject * parent ,
Core : : ActionManager * ami ,
const char * id ,
const QList < int > & globalcontext )
{
QAction * tmpaction = new QAction ( parent ) ;
tmpaction - > setSeparator ( true ) ;
return ami - > registerAction ( tmpaction , id , globalcontext ) ;
}
2009-12-08 14:26:41 +01:00
bool CVSPlugin : : initialize ( const QStringList & /*arguments */ , QString * errorMessage )
2009-07-15 12:28:40 +02:00
{
typedef VCSBase : : VCSSubmitEditorFactory < CVSSubmitEditor > CVSSubmitEditorFactory ;
typedef VCSBase : : VCSEditorFactory < CVSEditor > CVSEditorFactory ;
using namespace Constants ;
using namespace Core : : Constants ;
using namespace ExtensionSystem ;
2009-12-08 14:26:41 +01:00
VCSBase : : VCSBasePlugin : : initialize ( new CVSControl ( this ) ) ;
2009-07-15 12:28:40 +02:00
m_cvsPluginInstance = this ;
Core : : ICore * core = Core : : ICore : : instance ( ) ;
if ( ! core - > mimeDatabase ( ) - > addMimeTypes ( QLatin1String ( " :/trolltech.cvs/CVS.mimetypes.xml " ) , errorMessage ) )
return false ;
if ( QSettings * settings = core - > settings ( ) )
m_settings . fromSettings ( settings ) ;
addAutoReleasedObject ( new SettingsPage ) ;
addAutoReleasedObject ( new CVSSubmitEditorFactory ( & submitParameters ) ) ;
static const char * describeSlotC = SLOT ( slotDescribe ( QString , QString ) ) ;
const int editorCount = sizeof ( editorParameters ) / sizeof ( VCSBase : : VCSBaseEditorParameters ) ;
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 " ) ;
m_commandLocator = new Locator : : CommandLocator ( QLatin1String ( " CVS " ) , prefix , prefix ) ;
addAutoReleasedObject ( m_commandLocator ) ;
2009-07-15 12:28:40 +02:00
//register actions
Core : : ActionManager * ami = core - > actionManager ( ) ;
Core : : ActionContainer * toolsContainer = ami - > actionContainer ( M_TOOLS ) ;
Core : : ActionContainer * cvsMenu =
ami - > createMenu ( QLatin1String ( CMD_ID_CVS_MENU ) ) ;
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
QList < int > globalcontext ;
globalcontext < < core - > uniqueIDManager ( ) - > uniqueIdentifier ( C_GLOBAL ) ;
Core : : Command * command ;
2010-01-11 17:17:16 +01:00
m_diffCurrentAction = new Utils : : ParameterAction ( tr ( " Diff Current File " ) , tr ( " Diff \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_diffCurrentAction ,
CMD_ID_DIFF_CURRENT , globalcontext ) ;
2009-07-15 12:28:40 +02:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+C,Alt+D " ) ) ) ;
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 ) ;
command = ami - > registerAction ( m_filelogCurrentAction ,
CMD_ID_FILELOG_CURRENT , globalcontext ) ;
2009-07-15 12:28:40 +02:00
command - > setAttribute ( Core : : 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 ) ;
command = ami - > registerAction ( m_annotateCurrentAction ,
CMD_ID_ANNOTATE_CURRENT , globalcontext ) ;
2009-07-15 12:28:40 +02:00
command - > setAttribute ( Core : : 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
cvsMenu - > addAction ( createSeparator ( this , ami , CMD_ID_SEPARATOR0 , globalcontext ) ) ;
2010-01-11 17:17:16 +01:00
m_addAction = new Utils : : ParameterAction ( tr ( " Add " ) , tr ( " Add \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_addAction , CMD_ID_ADD ,
2009-07-15 12:28:40 +02:00
globalcontext ) ;
2009-12-09 12:41:10 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
2010-01-11 17:17:16 +01:00
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+C,Alt+A " ) ) ) ;
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 ) ;
2009-07-15 12:28:40 +02:00
command = ami - > registerAction ( m_commitCurrentAction ,
CMD_ID_COMMIT_CURRENT , globalcontext ) ;
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
command - > setDefaultKeySequence ( QKeySequence ( tr ( " Alt+C,Alt+C " ) ) ) ;
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 ) ;
command = ami - > registerAction ( m_deleteAction , CMD_ID_DELETE_FILE ,
globalcontext ) ;
2009-07-15 12:28:40 +02:00
command - > setAttribute ( Core : : 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 ) ;
command = ami - > registerAction ( m_revertAction , CMD_ID_REVERT ,
globalcontext ) ;
2009-07-15 12:28:40 +02:00
command - > setAttribute ( Core : : 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
2010-01-11 17:17:16 +01:00
cvsMenu - > addAction ( createSeparator ( this , ami , CMD_ID_SEPARATOR1 , globalcontext ) ) ;
m_diffProjectAction = new Utils : : ParameterAction ( tr ( " Diff Project " ) , tr ( " Diff Project \" %1 \" " ) , Utils : : ParameterAction : : EnabledWithParameter , this ) ;
command = ami - > registerAction ( m_diffProjectAction , CMD_ID_DIFF_PROJECT ,
globalcontext ) ;
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
connect ( m_diffProjectAction , SIGNAL ( triggered ( ) ) , this , SLOT ( diffProject ( ) ) ) ;
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 ) ;
command = ami - > registerAction ( m_statusProjectAction , CMD_ID_STATUS ,
2009-07-15 12:28:40 +02:00
globalcontext ) ;
2009-12-09 12:41:10 +01:00
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
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 ) ;
command = ami - > registerAction ( m_logProjectAction , CMD_ID_PROJECTLOG , globalcontext ) ;
command - > setAttribute ( Core : : Command : : CA_UpdateText ) ;
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 ) ;
2009-07-15 12:28:40 +02:00
command = ami - > registerAction ( m_updateProjectAction , CMD_ID_UPDATE , globalcontext ) ;
2009-12-09 12:41:10 +01:00
command - > setAttribute ( Core : : 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-01-11 17:17:16 +01:00
cvsMenu - > addAction ( createSeparator ( this , ami , CMD_ID_SEPARATOR2 , globalcontext ) ) ;
2010-01-07 11:33:30 +01:00
m_logRepositoryAction = new QAction ( tr ( " Repository Log " ) , this ) ;
command = ami - > registerAction ( m_logRepositoryAction , CMD_ID_REPOSITORYLOG , globalcontext ) ;
connect ( m_logRepositoryAction , SIGNAL ( triggered ( ) ) , this , SLOT ( logRepository ( ) ) ) ;
cvsMenu - > addAction ( command ) ;
2010-02-12 16:03:08 +01:00
m_commandLocator - > appendCommand ( command ) ;
2010-01-07 11:33:30 +01:00
2010-01-11 17:17:16 +01:00
m_commitAllAction = new QAction ( tr ( " Commit All Files " ) , this ) ;
command = ami - > registerAction ( m_commitAllAction , CMD_ID_COMMIT_ALL ,
globalcontext ) ;
connect ( m_commitAllAction , SIGNAL ( triggered ( ) ) , this , SLOT ( startCommitAll ( ) ) ) ;
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 ) ;
command = ami - > registerAction ( m_revertRepositoryAction , CMD_ID_REVERT_ALL ,
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
QList < int > cvscommitcontext ;
cvscommitcontext < < Core : : UniqueIDManager : : instance ( ) - > uniqueIdentifier ( Constants : : CVSCOMMITEDITOR ) ;
m_submitCurrentLogAction = new QAction ( VCSBase : : VCSBaseSubmitEditor : : submitIcon ( ) , tr ( " Commit " ) , this ) ;
command = ami - > registerAction ( m_submitCurrentLogAction , Constants : : SUBMIT_CURRENT , cvscommitcontext ) ;
connect ( m_submitCurrentLogAction , SIGNAL ( triggered ( ) ) , this , SLOT ( submitCurrentLog ( ) ) ) ;
m_submitDiffAction = new QAction ( VCSBase : : VCSBaseSubmitEditor : : diffIcon ( ) , tr ( " Diff Selected Files " ) , this ) ;
command = ami - > registerAction ( m_submitDiffAction , Constants : : DIFF_SELECTED , cvscommitcontext ) ;
m_submitUndoAction = new QAction ( tr ( " &Undo " ) , this ) ;
command = ami - > registerAction ( m_submitUndoAction , Core : : Constants : : UNDO , cvscommitcontext ) ;
m_submitRedoAction = new QAction ( tr ( " &Redo " ) , this ) ;
command = ami - > registerAction ( m_submitRedoAction , Core : : Constants : : REDO , cvscommitcontext ) ;
return true ;
}
void CVSPlugin : : extensionsInitialized ( )
{
}
2009-12-08 14:26:41 +01:00
bool CVSPlugin : : submitEditorAboutToClose ( VCSBase : : VCSBaseSubmitEditor * submitEditor )
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 ;
2009-12-08 14:26:41 +01:00
Core : : IFile * fileIFace = submitEditor - > file ( ) ;
const CVSSubmitEditor * editor = qobject_cast < CVSSubmitEditor * > ( submitEditor ) ;
2009-07-15 12:28:40 +02:00
if ( ! fileIFace | | ! editor )
return true ;
// Submit editor closing. Make it write out the commit message
// and retrieve files
const QFileInfo editorFile ( fileIFace - > fileName ( ) ) ;
2009-09-22 12:23:44 +02:00
const QFileInfo changeFile ( m_commitMessageFileName ) ;
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).
CVSSettings newSettings = m_settings ;
const VCSBase : : VCSBaseSubmitEditor : : PromptSubmitResult answer =
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? " ) ,
& newSettings . promptToSubmit , ! m_submitActionTriggered ) ;
m_submitActionTriggered = false ;
switch ( answer ) {
case VCSBase : : VCSBaseSubmitEditor : : SubmitCanceled :
return false ; // Keep editing and change file
case VCSBase : : 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
Core : : ICore : : instance ( ) - > fileManager ( ) - > blockFileChange ( fileIFace ) ;
fileIFace - > save ( ) ;
Core : : ICore : : instance ( ) - > fileManager ( ) - > unblockFileChange ( fileIFace ) ;
2009-09-22 12:23:44 +02:00
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 ;
}
2009-12-09 12:41:10 +01:00
void CVSPlugin : : diffCommitFiles ( const QStringList & files )
2009-07-15 12:28:40 +02:00
{
2009-12-09 12:41:10 +01:00
cvsDiff ( m_commitRepository , files ) ;
2009-07-15 12:28:40 +02:00
}
2009-12-09 12:41:10 +01:00
static inline void setDiffBaseDirectory ( Core : : IEditor * editor , const QString & db )
2009-07-15 12:28:40 +02:00
{
2009-12-09 12:41:10 +01:00
if ( VCSBase : : VCSBaseEditor * ve = qobject_cast < VCSBase : : VCSBaseEditor * > ( editor - > widget ( ) ) )
ve - > setDiffBaseDirectory ( db ) ;
}
2009-07-15 12:28:40 +02:00
2009-12-09 12:41:10 +01:00
void CVSPlugin : : cvsDiff ( const QString & workingDir , const QStringList & files )
{
if ( CVS : : Constants : : debug )
qDebug ( ) < < Q_FUNC_INFO < < files ;
const QString source = VCSBase : : VCSBaseEditor : : getSource ( workingDir , files ) ;
QTextCodec * codec = VCSBase : : VCSBaseEditor : : getCodec ( workingDir , files ) ;
const QString id = VCSBase : : VCSBaseEditor : : getTitleId ( workingDir , files ) ;
2009-07-15 12:28:40 +02:00
QStringList args ( QLatin1String ( " diff " ) ) ;
args < < m_settings . cvsDiffOptions ;
2009-12-09 12:41:10 +01:00
args . append ( files ) ;
2009-07-15 12:28:40 +02:00
// CVS returns the diff exit code (1 if files differ), which is
// undistinguishable from a "file not found" error, unfortunately.
2009-12-14 12:45:45 +01:00
const CVSResponse response = runCVS ( workingDir , args , m_settings . timeOutMS ( ) , false , codec ) ;
2009-07-15 12:28:40 +02:00
switch ( response . result ) {
case CVSResponse : : NonNullExitCode :
case CVSResponse : : Ok :
break ;
case CVSResponse : : OtherError :
return ;
}
QString output = fixDiffOutput ( response . stdOut ) ;
if ( output . isEmpty ( ) )
output = tr ( " The files do not differ. " ) ;
// diff of a single file? re-use an existing view if possible to support
// the common usage pattern of continuously changing and diffing a file
if ( files . count ( ) = = 1 ) {
// Show in the same editor if diff has been executed before
2009-12-09 12:41:10 +01:00
if ( Core : : IEditor * editor = locateEditor ( " originalFileName " , id ) ) {
2009-07-15 12:28:40 +02:00
editor - > createNew ( output ) ;
Core : : EditorManager : : instance ( ) - > activateEditor ( editor ) ;
2009-12-09 12:41:10 +01:00
setDiffBaseDirectory ( editor , workingDir ) ;
2009-07-15 12:28:40 +02:00
return ;
}
}
2009-12-09 12:41:10 +01:00
const QString title = QString : : fromLatin1 ( " cvs diff %1 " ) . arg ( id ) ;
2009-07-15 12:28:40 +02:00
Core : : IEditor * editor = showOutputInEditor ( title , output , VCSBase : : DiffOutput , source , codec ) ;
if ( files . count ( ) = = 1 )
2009-12-09 12:41:10 +01:00
editor - > setProperty ( " originalFileName " , id ) ;
setDiffBaseDirectory ( editor , workingDir ) ;
2009-07-15 12:28:40 +02:00
}
CVSSubmitEditor * CVSPlugin : : openCVSSubmitEditor ( const QString & fileName )
{
2010-01-08 09:48:54 +01:00
Core : : IEditor * editor = Core : : EditorManager : : instance ( ) - > openEditor ( fileName , QLatin1String ( Constants : : CVSCOMMITEDITOR_ID ) ) ;
2009-07-15 12:28:40 +02:00
CVSSubmitEditor * submitEditor = qobject_cast < CVSSubmitEditor * > ( editor ) ;
QTC_ASSERT ( submitEditor , /**/ ) ;
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 ;
}
2009-12-08 14:26:41 +01:00
void CVSPlugin : : updateActions ( VCSBase : : 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 ) ;
m_logRepositoryAction - > 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 ) ;
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 ) ;
2009-12-09 12:41:10 +01:00
2010-02-12 16:03:08 +01:00
m_commitAllAction - > setEnabled ( hasTopLevel ) ;
2009-07-15 12:28:40 +02:00
}
void CVSPlugin : : addCurrentFile ( )
{
2009-12-09 12:41:10 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
vcsAdd ( state . currentFileTopLevel ( ) , state . relativeCurrentFile ( ) ) ;
2009-07-15 12:28:40 +02:00
}
2010-01-11 17:17:16 +01:00
void CVSPlugin : : revertAll ( )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return )
const QString title = tr ( " Revert repository " ) ;
if ( QMessageBox : : warning ( 0 , title , tr ( " Would you like to revert all changes to the repository? " ) ,
QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : No )
return ;
QStringList args ;
args < < QLatin1String ( " update " ) < < QLatin1String ( " -C " ) < < state . topLevel ( ) ;
const CVSResponse revertResponse = runCVS ( state . topLevel ( ) , args , m_settings . timeOutMS ( ) , true ) ;
if ( revertResponse . result = = CVSResponse : : Ok ) {
cvsVersionControl ( ) - > emitRepositoryChanged ( state . topLevel ( ) ) ;
} else {
QMessageBox : : warning ( 0 , title , tr ( " Revert failed: %1 " ) . arg ( revertResponse . message ) , QMessageBox : : Ok ) ;
}
}
2009-07-15 12:28:40 +02:00
void CVSPlugin : : revertCurrentFile ( )
{
2009-12-09 12:41:10 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
QStringList args ;
args < < QLatin1String ( " diff " ) < < state . relativeCurrentFile ( ) ;
2009-12-14 12:45:45 +01:00
const CVSResponse diffResponse = runCVS ( state . currentFileTopLevel ( ) , args , m_settings . timeOutMS ( ) , false ) ;
2009-07-15 12:28:40 +02:00
switch ( diffResponse . result ) {
case CVSResponse : : Ok :
return ; // Not modified, diff exit code 0
case CVSResponse : : NonNullExitCode : // Diff exit code != 0
if ( diffResponse . stdOut . isEmpty ( ) ) // Paranoia: Something else failed?
return ;
break ;
case CVSResponse : : OtherError :
return ;
}
if ( QMessageBox : : warning ( 0 , QLatin1String ( " CVS revert " ) , tr ( " The file has been changed. Do you want to revert it? " ) ,
QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : No )
return ;
2009-12-09 12:41:10 +01:00
Core : : 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 ( ) ;
2009-12-14 12:45:45 +01:00
const CVSResponse revertResponse = runCVS ( state . currentFileTopLevel ( ) , args , m_settings . timeOutMS ( ) , true ) ;
2009-07-15 12:28:40 +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
}
}
void CVSPlugin : : diffProject ( )
{
2009-12-09 12:41:10 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasProject ( ) , return )
cvsDiff ( state . currentProjectTopLevel ( ) , state . relativeCurrentProject ( ) ) ;
2009-07-15 12:28:40 +02:00
}
void CVSPlugin : : diffCurrentFile ( )
{
2009-12-09 12:41:10 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
cvsDiff ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) ) ;
2009-07-15 12:28:40 +02:00
}
void CVSPlugin : : startCommitCurrentFile ( )
{
2009-12-09 12:41:10 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
startCommit ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) ) ;
2009-07-15 12:28:40 +02:00
}
void CVSPlugin : : startCommitAll ( )
{
2009-12-09 12:41:10 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return )
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 . */
2009-12-09 12:41:10 +01:00
void CVSPlugin : : startCommit ( const QString & workingDir , const QStringList & files )
2009-07-15 12:28:40 +02:00
{
if ( VCSBase : : VCSBaseSubmitEditor : : raiseSubmitEditor ( ) )
return ;
2009-09-22 12:23:44 +02:00
if ( isCommitEditorOpen ( ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendWarning ( tr ( " Another commit is currently being executed. " ) ) ;
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 " ) ) ;
2009-12-14 12:45:45 +01:00
const CVSResponse response = runCVS ( workingDir , args , m_settings . timeOutMS ( ) , false , 0 , true ) ;
2009-07-15 12:28:40 +02:00
if ( response . result ! = CVSResponse : : Ok )
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 ) ;
if ( ! files . isEmpty ( ) ) {
for ( StateList : : iterator it = statusOutput . begin ( ) ; it ! = statusOutput . end ( ) ; ) {
if ( files . contains ( it - > second ) ) {
+ + it ;
} else {
it = statusOutput . erase ( it ) ;
}
}
}
2009-07-15 12:28:40 +02:00
if ( statusOutput . empty ( ) ) {
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > append ( 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
2009-09-22 12:23:44 +02:00
QTemporaryFile changeTmpFile ;
changeTmpFile . setAutoRemove ( false ) ;
if ( ! changeTmpFile . open ( ) ) {
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( tr ( " Cannot create temporary file: %1 " ) . arg ( changeTmpFile . errorString ( ) ) ) ;
2009-07-15 12:28:40 +02:00
return ;
}
// TODO: Retrieve submit template from
const QString submitTemplate ;
2009-09-22 12:23:44 +02:00
m_commitMessageFileName = changeTmpFile . fileName ( ) ;
2009-07-15 12:28:40 +02:00
// Create a submit
2009-09-22 12:23:44 +02:00
changeTmpFile . write ( submitTemplate . toUtf8 ( ) ) ;
changeTmpFile . flush ( ) ;
changeTmpFile . close ( ) ;
2009-07-15 12:28:40 +02:00
// Create a submit editor and set file list
2009-09-22 12:23:44 +02:00
CVSSubmitEditor * editor = openCVSSubmitEditor ( m_commitMessageFileName ) ;
2009-12-14 10:56:50 +01:00
editor - > setCheckScriptWorkingDirectory ( m_commitRepository ) ;
2009-07-15 12:28:40 +02:00
editor - > setStateList ( statusOutput ) ;
}
bool CVSPlugin : : commit ( const QString & messageFile ,
const QStringList & fileList )
{
if ( CVS : : Constants : : debug )
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 ) ;
2009-12-14 12:45:45 +01:00
const CVSResponse response = runCVS ( m_commitRepository , args , m_settings . longTimeOutMS ( ) , true ) ;
2009-07-15 12:28:40 +02:00
return response . result = = CVSResponse : : Ok ;
}
void CVSPlugin : : filelogCurrentFile ( )
{
2009-12-09 12:41:10 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
2010-01-07 11:33:30 +01:00
filelog ( state . currentFileTopLevel ( ) , QStringList ( state . relativeCurrentFile ( ) ) , true ) ;
2009-07-15 12:28:40 +02:00
}
2010-01-07 11:33:30 +01:00
void CVSPlugin : : logProject ( )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasProject ( ) , return )
filelog ( state . currentProjectTopLevel ( ) , state . relativeCurrentProject ( ) ) ;
}
void CVSPlugin : : logRepository ( )
{
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasTopLevel ( ) , return )
filelog ( state . topLevel ( ) ) ;
}
void CVSPlugin : : filelog ( const QString & workingDir ,
const QStringList & files ,
bool enableAnnotationContextMenu )
2009-07-15 12:28:40 +02:00
{
2009-12-09 12:41:10 +01:00
QTextCodec * codec = VCSBase : : VCSBaseEditor : : getCodec ( workingDir , files ) ;
2009-07-15 12:28:40 +02:00
// no need for temp file
2009-12-09 12:41:10 +01:00
const QString id = VCSBase : : VCSBaseEditor : : getTitleId ( workingDir , files ) ;
const QString source = VCSBase : : VCSBaseEditor : : getSource ( workingDir , files ) ;
QStringList args ;
args < < QLatin1String ( " log " ) ;
args . append ( files ) ;
2009-12-14 12:45:45 +01:00
const CVSResponse response = runCVS ( workingDir , args , m_settings . timeOutMS ( ) , false , codec ) ;
2009-07-15 12:28:40 +02:00
if ( response . result ! = CVSResponse : : Ok )
return ;
// Re-use an existing view if possible to support
// the common usage pattern of continuously changing and diffing a file
2009-12-09 12:41:10 +01:00
if ( Core : : IEditor * editor = locateEditor ( " logFileName " , id ) ) {
2009-07-15 12:28:40 +02:00
editor - > createNew ( response . stdOut ) ;
Core : : EditorManager : : instance ( ) - > activateEditor ( editor ) ;
} else {
2009-12-09 12:41:10 +01:00
const QString title = QString : : fromLatin1 ( " cvs log %1 " ) . arg ( id ) ;
Core : : IEditor * newEditor = showOutputInEditor ( title , response . stdOut , VCSBase : : LogOutput , source , codec ) ;
newEditor - > setProperty ( " logFileName " , id ) ;
2010-01-07 11:33:30 +01:00
if ( enableAnnotationContextMenu )
VCSBase : : VCSBaseEditor : : getVcsBaseEditor ( newEditor ) - > setFileLogAnnotateEnabled ( true ) ;
2009-07-15 12:28:40 +02:00
}
}
void CVSPlugin : : updateProject ( )
{
2009-12-09 12:41:10 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasProject ( ) , return )
QStringList args ( QLatin1String ( " update " ) ) ;
args . push_back ( QLatin1String ( " -dR " ) ) ;
args . append ( state . relativeCurrentProject ( ) ) ;
2009-12-14 12:45:45 +01:00
const CVSResponse response = runCVS ( state . currentProjectTopLevel ( ) , args , m_settings . longTimeOutMS ( ) , true ) ;
2009-12-09 12:41:10 +01:00
if ( response . result = = CVSResponse : : Ok )
cvsVersionControl ( ) - > emitRepositoryChanged ( state . currentProjectTopLevel ( ) ) ;
2009-07-15 12:28:40 +02:00
}
void CVSPlugin : : annotateCurrentFile ( )
{
2009-12-09 12:41:10 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasFile ( ) , return )
annotate ( state . currentFileTopLevel ( ) , state . relativeCurrentFile ( ) ) ;
2009-07-15 12:28:40 +02:00
}
2010-01-06 17:24:40 +01:00
void CVSPlugin : : annotateVersion ( const QString & file , const QString & revision , int lineNumber )
{
const QFileInfo fi ( file ) ;
annotate ( fi . absolutePath ( ) , fi . fileName ( ) , revision , lineNumber ) ;
}
void CVSPlugin : : annotate ( const QString & workingDir , const QString & file ,
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 ) ;
QTextCodec * codec = VCSBase : : VCSBaseEditor : : getCodec ( workingDir , files ) ;
2010-01-06 17:24:40 +01:00
const QString id = VCSBase : : VCSBaseEditor : : getTitleId ( workingDir , files , revision ) ;
2009-12-09 12:41:10 +01:00
const QString source = VCSBase : : VCSBaseEditor : : getSource ( workingDir , file ) ;
QStringList args ;
2010-01-06 17:24:40 +01:00
args < < QLatin1String ( " annotate " ) ;
if ( ! revision . isEmpty ( ) )
args < < QLatin1String ( " -r " ) < < revision ;
args < < file ;
2009-12-14 12:45:45 +01:00
const CVSResponse response = runCVS ( workingDir , args , m_settings . timeOutMS ( ) , false , codec ) ;
2009-07-15 12:28:40 +02:00
if ( response . result ! = CVSResponse : : Ok )
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 )
lineNumber = VCSBase : : VCSBaseEditor : : lineNumberOfCurrentEditor ( file ) ;
2009-07-15 12:28:40 +02:00
2009-12-09 12:41:10 +01:00
if ( Core : : IEditor * editor = locateEditor ( " annotateFileName " , id ) ) {
2009-07-15 12:28:40 +02:00
editor - > createNew ( response . stdOut ) ;
2009-10-01 17:32:26 +02:00
VCSBase : : VCSBaseEditor : : gotoLineOfEditor ( editor , lineNumber ) ;
2009-07-15 12:28:40 +02:00
Core : : EditorManager : : instance ( ) - > activateEditor ( editor ) ;
} else {
2009-12-09 12:41:10 +01:00
const QString title = QString : : fromLatin1 ( " cvs annotate %1 " ) . arg ( id ) ;
Core : : IEditor * newEditor = showOutputInEditor ( title , response . stdOut , VCSBase : : AnnotateOutput , source , codec ) ;
newEditor - > setProperty ( " annotateFileName " , id ) ;
2009-10-01 17:32:26 +02:00
VCSBase : : VCSBaseEditor : : gotoLineOfEditor ( newEditor , lineNumber ) ;
2009-07-15 12:28:40 +02:00
}
}
void CVSPlugin : : projectStatus ( )
{
2009-12-09 12:41:10 +01:00
const VCSBase : : VCSBasePluginState state = currentState ( ) ;
QTC_ASSERT ( state . hasProject ( ) , return )
QStringList args ;
args < < QLatin1String ( " status " ) < < state . relativeCurrentProject ( ) ;
2009-12-14 12:45:45 +01:00
const CVSResponse response = runCVS ( state . currentProjectTopLevel ( ) , args , m_settings . timeOutMS ( ) , false ) ;
2009-07-15 12:28:40 +02:00
if ( response . result = = CVSResponse : : Ok )
2009-12-09 12:41:10 +01:00
showOutputInEditor ( tr ( " Project status " ) , response . stdOut , VCSBase : : RegularCommandOutput , state . currentProjectTopLevel ( ) , 0 ) ;
2009-07-15 12:28:40 +02:00
}
void CVSPlugin : : slotDescribe ( const QString & source , const QString & changeNr )
{
QString errorMessage ;
if ( ! describe ( source , changeNr , & errorMessage ) )
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( errorMessage ) ;
2009-07-15 12:28:40 +02:00
}
bool CVSPlugin : : describe ( const QString & file , const QString & changeNr , QString * errorMessage )
{
2009-12-09 12:41:10 +01:00
const QString toplevel = findTopLevelForDirectory ( QFileInfo ( file ) . absolutePath ( ) ) ;
if ( toplevel . isEmpty ( ) ) {
* errorMessage = msgCannotFindTopLevel ( file ) ;
return false ;
}
return describe ( toplevel , QDir ( toplevel ) . relativeFilePath ( file ) , changeNr , errorMessage ) ;
}
bool CVSPlugin : : describe ( const QString & toplevel , const QString & file , const
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.
if ( CVS : : Constants : : debug )
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 ;
2009-12-14 12:45:45 +01:00
const CVSResponse logResponse = runCVS ( toplevel , args , m_settings . timeOutMS ( ) , false ) ;
2009-07-15 12:28:40 +02:00
if ( logResponse . result ! = CVSResponse : : Ok ) {
* errorMessage = logResponse . message ;
return false ;
}
2009-12-09 12:41:10 +01:00
const QList < CVS_LogEntry > fileLog = parseLogEntries ( logResponse . stdOut ) ;
2009-07-15 12:28:40 +02:00
if ( fileLog . empty ( ) | | fileLog . front ( ) . revisions . empty ( ) ) {
* errorMessage = msgLogParsingFailed ( ) ;
return false ;
}
if ( m_settings . describeByCommitId ) {
// 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
2009-12-14 12:45:45 +01:00
const CVSResponse repoLogResponse = runCVS ( toplevel , args , m_settings . longTimeOutMS ( ) , false ) ;
2009-07-15 12:28:40 +02:00
if ( repoLogResponse . result ! = CVSResponse : : Ok ) {
* errorMessage = repoLogResponse . message ;
return false ;
}
// Describe all files found, pass on dir to obtain correct absolute paths.
2009-12-09 12:41:10 +01:00
const QList < CVS_LogEntry > 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
2009-12-09 12:41:10 +01:00
bool CVSPlugin : : describe ( const QString & repositoryPath ,
QList < CVS_LogEntry > entries ,
2009-07-15 12:28:40 +02:00
QString * errorMessage )
{
// Collect logs
QString output ;
QTextCodec * codec = 0 ;
const QList < CVS_LogEntry > : : iterator lend = entries . end ( ) ;
for ( QList < CVS_LogEntry > : : iterator it = entries . begin ( ) ; it ! = lend ; + + it ) {
// Before fiddling file names, try to find codec
if ( ! codec )
2009-12-09 12:41:10 +01:00
codec = VCSBase : : VCSBaseEditor : : 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 ;
2009-12-14 12:45:45 +01:00
const CVSResponse logResponse = runCVS ( repositoryPath , args , m_settings . timeOutMS ( ) , false ) ;
2009-07-15 12:28:40 +02:00
if ( logResponse . result ! = CVSResponse : : Ok ) {
* errorMessage = logResponse . message ;
return false ;
}
output + = logResponse . stdOut ;
}
// Collect diffs relative to repository
for ( QList < CVS_LogEntry > : : 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 " ) ) ;
args < < m_settings . cvsDiffOptions < < QLatin1String ( " -r " ) < < previousRev
< < QLatin1String ( " -r " ) < < it - > revisions . front ( ) . revision
< < it - > file ;
2009-12-14 12:45:45 +01:00
const CVSResponse diffResponse = runCVS ( repositoryPath , args , m_settings . timeOutMS ( ) , false , codec ) ;
2009-07-16 09:24:44 +02:00
switch ( diffResponse . result ) {
case CVSResponse : : Ok :
case CVSResponse : : NonNullExitCode : // Diff exit code != 0
if ( diffResponse . stdOut . isEmpty ( ) ) {
* errorMessage = diffResponse . message ;
return false ; // Something else failed.
}
break ;
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 ;
if ( Core : : IEditor * editor = locateEditor ( " describeChange " , commitId ) ) {
editor - > createNew ( output ) ;
Core : : EditorManager : : instance ( ) - > 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 ) ;
Core : : IEditor * newEditor = showOutputInEditor ( title , output , VCSBase : : DiffOutput , entries . front ( ) . file , codec ) ;
newEditor - > setProperty ( " describeChange " , commitId ) ;
2009-12-09 12:41:10 +01:00
setDiffBaseDirectory ( editor , repositoryPath ) ;
2009-07-15 12:28:40 +02:00
}
return true ;
}
void CVSPlugin : : submitCurrentLog ( )
{
m_submitActionTriggered = true ;
Core : : EditorManager : : instance ( ) - > closeEditors ( QList < Core : : IEditor * > ( )
< < Core : : EditorManager : : instance ( ) - > currentEditor ( ) ) ;
}
static inline QString processStdErr ( QProcess & proc )
{
return QString : : fromLocal8Bit ( proc . readAllStandardError ( ) ) . remove ( QLatin1Char ( ' \r ' ) ) ;
}
// Format log entry for command
static inline QString msgExecutionLogEntry ( const QString & workingDir , const QString & executable , const QStringList & arguments )
{
2009-08-10 15:46:45 +02:00
//: Executing: <executable> <arguments>
2009-07-15 12:28:40 +02:00
const QString args = arguments . join ( QString ( QLatin1Char ( ' ' ) ) ) ;
if ( workingDir . isEmpty ( ) )
2009-08-17 15:50:43 +02:00
return CVSPlugin : : tr ( " Executing: %1 %2 \n " ) . arg ( executable , args ) ;
2009-08-19 15:58:53 +02:00
return CVSPlugin : : tr ( " Executing in %1: %2 %3 \n " ) . arg ( workingDir , executable , args ) ;
2009-07-15 12:28:40 +02:00
}
// Run CVS. At this point, file arguments must be relative to
// the working directory (see above).
CVSResponse CVSPlugin : : runCVS ( const QString & workingDirectory ,
const QStringList & arguments ,
int timeOut ,
bool showStdOutInOutputWindow , QTextCodec * outputCodec ,
bool mergeStderr )
{
const QString executable = m_settings . cvsCommand ;
CVSResponse response ;
if ( executable . isEmpty ( ) ) {
response . result = CVSResponse : : OtherError ;
response . message = tr ( " No cvs executable specified! " ) ;
return response ;
}
// Fix files and compile complete arguments
const QStringList allArgs = m_settings . addOptions ( arguments ) ;
2009-12-09 12:41:10 +01:00
const QString outputText = msgExecutionLogEntry ( workingDirectory , executable , allArgs ) ;
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendCommand ( outputText ) ;
2009-07-15 12:28:40 +02:00
if ( CVS : : Constants : : debug )
qDebug ( ) < < " runCVS " < < timeOut < < outputText ;
// Run, connect stderr to the output window
2009-10-05 11:06:05 +02:00
Utils : : SynchronousProcess process ;
2009-12-09 12:41:10 +01:00
if ( ! workingDirectory . isEmpty ( ) )
process . setWorkingDirectory ( workingDirectory ) ;
2009-07-15 12:28:40 +02:00
if ( mergeStderr )
process . setProcessChannelMode ( QProcess : : MergedChannels ) ;
process . setTimeout ( timeOut ) ;
process . setStdOutCodec ( outputCodec ) ;
process . setStdErrBufferedSignalsEnabled ( true ) ;
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow * outputWindow = VCSBase : : VCSBaseOutputWindow : : instance ( ) ;
connect ( & process , SIGNAL ( stdErrBuffered ( QString , bool ) ) , outputWindow , SLOT ( append ( QString ) ) ) ;
2009-07-15 12:28:40 +02:00
// connect stdout to the output window if desired
if ( showStdOutInOutputWindow ) {
process . setStdOutBufferedSignalsEnabled ( true ) ;
2009-08-10 15:46:45 +02:00
connect ( & process , SIGNAL ( stdOutBuffered ( QString , bool ) ) , outputWindow , SLOT ( append ( QString ) ) ) ;
2009-07-15 12:28:40 +02:00
}
2009-10-05 11:06:05 +02:00
const Utils : : SynchronousProcessResponse sp_resp = process . run ( executable , allArgs ) ;
2009-07-15 12:28:40 +02:00
response . result = CVSResponse : : OtherError ;
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 :
2009-07-15 12:28:40 +02:00
response . result = CVSResponse : : Ok ;
break ;
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : FinishedError :
2009-07-15 12:28:40 +02:00
response . result = CVSResponse : : NonNullExitCode ;
response . message = tr ( " The process terminated with exit code %1. " ) . arg ( sp_resp . exitCode ) ;
break ;
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : TerminatedAbnormally :
2009-07-15 12:28:40 +02:00
response . message = tr ( " The process terminated abnormally. " ) ;
break ;
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : StartFailed :
2009-07-15 12:28:40 +02:00
response . message = tr ( " Could not start cvs '%1'. Please check your settings in the preferences. " ) . arg ( executable ) ;
break ;
2009-10-05 11:06:05 +02:00
case Utils : : SynchronousProcessResponse : : Hang :
2009-07-15 12:28:40 +02:00
response . message = tr ( " CVS did not respond within timeout limit (%1 ms). " ) . arg ( timeOut ) ;
break ;
}
if ( response . result ! = CVSResponse : : Ok )
2009-08-10 15:46:45 +02:00
VCSBase : : VCSBaseOutputWindow : : instance ( ) - > appendError ( response . message ) ;
2009-07-15 12:28:40 +02:00
return response ;
}
Core : : IEditor * CVSPlugin : : showOutputInEditor ( const QString & title , const QString & output ,
int editorType , const QString & source ,
QTextCodec * codec )
{
const VCSBase : : VCSBaseEditorParameters * params = findType ( editorType ) ;
QTC_ASSERT ( params , return 0 ) ;
2010-01-07 18:17:24 +01:00
const QString id = params - > id ;
2009-07-15 12:28:40 +02:00
if ( CVS : : Constants : : debug )
2010-01-07 18:17:24 +01:00
qDebug ( ) < < " CVSPlugin::showOutputInEditor " < < title < < id < < " source= " < < source < < " Size= " < < output . size ( ) < < " Type= " < < editorType < < debugCodec ( codec ) ;
2009-07-15 12:28:40 +02:00
QString s = title ;
2010-01-07 18:17:24 +01:00
Core : : IEditor * editor = Core : : EditorManager : : instance ( ) - > openEditorWithContents ( id , & s , output . toLocal8Bit ( ) ) ;
2010-01-07 11:33:30 +01:00
connect ( editor , SIGNAL ( annotateRevisionRequested ( QString , QString , int ) ) ,
this , SLOT ( annotateVersion ( QString , QString , int ) ) ) ;
2009-07-15 12:28:40 +02:00
CVSEditor * e = qobject_cast < CVSEditor * > ( editor - > widget ( ) ) ;
if ( ! e )
return 0 ;
s . replace ( QLatin1Char ( ' ' ) , QLatin1Char ( ' _ ' ) ) ;
e - > setSuggestedFileName ( s ) ;
if ( ! source . isEmpty ( ) )
e - > setSource ( source ) ;
if ( codec )
e - > setCodec ( codec ) ;
Core : : IEditor * ie = e - > editableInterface ( ) ;
Core : : EditorManager : : instance ( ) - > activateEditor ( ie ) ;
return ie ;
}
CVSSettings CVSPlugin : : settings ( ) const
{
return m_settings ;
}
void CVSPlugin : : setSettings ( const CVSSettings & s )
{
if ( s ! = m_settings ) {
m_settings = s ;
if ( QSettings * settings = Core : : ICore : : instance ( ) - > settings ( ) )
m_settings . toSettings ( settings ) ;
}
}
CVSPlugin * CVSPlugin : : cvsPluginInstance ( )
{
QTC_ASSERT ( m_cvsPluginInstance , return m_cvsPluginInstance ) ;
return m_cvsPluginInstance ;
}
2009-12-09 12:41:10 +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 ;
2009-12-14 12:45:45 +01:00
const CVSResponse response = runCVS ( workingDir , args , m_settings . timeOutMS ( ) , true ) ;
2009-07-15 12:28:40 +02:00
return response . result = = CVSResponse : : Ok ;
}
2009-12-09 12:41:10 +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 ;
2009-12-14 12:45:45 +01:00
const CVSResponse response = runCVS ( workingDir , args , m_settings . timeOutMS ( ) , true ) ;
2009-07-15 12:28:40 +02:00
return response . result = = CVSResponse : : Ok ;
}
/* 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 . */
bool CVSPlugin : : managesDirectory ( const QString & directory ) const
{
const QDir dir ( directory ) ;
const bool rc = dir . exists ( ) & & managesDirectory ( dir ) ;
if ( CVS : : Constants : : debug )
qDebug ( ) < < " CVSPlugin::managesDirectory " < < directory < < rc ;
return rc ;
}
bool CVSPlugin : : managesDirectory ( const QDir & directory ) const
{
const QString cvsDir = directory . absoluteFilePath ( QLatin1String ( " CVS " ) ) ;
return QFileInfo ( cvsDir ) . isDir ( ) ;
}
QString CVSPlugin : : findTopLevelForDirectory ( const QString & directory ) const
{
// Debug wrapper
const QString rc = findTopLevelForDirectoryI ( directory ) ;
if ( CVS : : Constants : : debug )
qDebug ( ) < < " CVSPlugin::findTopLevelForDirectory " < < directory < < rc ;
return rc ;
}
QString CVSPlugin : : findTopLevelForDirectoryI ( const QString & directory ) const
{
/* 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 = QDir ( directory ) ;
if ( ! lastDirectory . exists ( ) | | ! managesDirectory ( lastDirectory ) )
return QString ( ) ;
for ( QDir parentDir = lastDirectory ; parentDir . cdUp ( ) ; lastDirectory = parentDir ) {
if ( ! managesDirectory ( parentDir ) )
return lastDirectory . absolutePath ( ) ;
}
return QString ( ) ;
}
2009-12-08 14:26:41 +01:00
CVSControl * CVSPlugin : : cvsVersionControl ( ) const
{
return static_cast < CVSControl * > ( versionControl ( ) ) ;
}
2009-07-15 12:28:40 +02:00
}
}
Q_EXPORT_PLUGIN ( CVS : : Internal : : CVSPlugin )