1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
|
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "cvsplugin.h"
#include "settingspage.h"
#include "cvseditor.h"
#include "cvssubmiteditor.h"
#include "cvsconstants.h"
#include "cvscontrol.h"
#include "checkoutwizard.h"
#include <vcsbase/basevcseditorfactory.h>
#include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/basevcssubmiteditorfactory.h>
#include <vcsbase/vcsbaseoutputwindow.h>
#include <vcsbase/vcsbaseeditorparameterwidget.h>
#include <locator/commandlocator.h>
#include <utils/synchronousprocess.h>
#include <utils/parameteraction.h>
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/filemanager.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/vcsmanager.h>
#include <utils/stringutils.h>
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
#include <QtCore/QDate>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QTextCodec>
#include <QtCore/QtPlugin>
#include <QtCore/QTemporaryFile>
#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(QDir::toNativeSeparators(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_EDIT_FILE = "CVS.EditFile";
static const char * const CMD_ID_UNEDIT_FILE = "CVS.UneditFile";
static const char * const CMD_ID_UNEDIT_REPOSITORY = "CVS.UneditRepository";
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";
static const char * const CMD_ID_REVERT_ALL = "CVS.RevertAll";
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";
static const char * const CMD_ID_PROJECTLOG = "CVS.ProjectLog";
static const char * const CMD_ID_PROJECTCOMMIT = "CVS.ProjectCommit";
static const char * const CMD_ID_REPOSITORYLOG = "CVS.RepositoryLog";
static const char * const CMD_ID_REPOSITORYDIFF = "CVS.RepositoryDiff";
static const char * const CMD_ID_REPOSITORYSTATUS = "CVS.RepositoryStatus";
static const char * const CMD_ID_REPOSITORYUPDATE = "CVS.RepositoryUpdate";
static const char * const CMD_ID_SEPARATOR3 = "CVS.Separator3";
static const VCSBase::VCSBaseEditorParameters editorParameters[] = {
{
VCSBase::RegularCommandOutput,
"CVS Command Log Editor", // id
QT_TRANSLATE_NOOP("VCS", "CVS Command Log Editor"), // display name
"CVS Command Log Editor", // context
"application/vnd.nokia.text.scs_cvs_commandlog",
"scslog"},
{ VCSBase::LogOutput,
"CVS File Log Editor", // id
QT_TRANSLATE_NOOP("VCS", "CVS File Log Editor"), // display name
"CVS File Log Editor", // context
"application/vnd.nokia.text.scs_cvs_filelog",
"scsfilelog"},
{ VCSBase::AnnotateOutput,
"CVS Annotation Editor", // id
QT_TRANSLATE_NOOP("VCS", "CVS Annotation Editor"), // display name
"CVS Annotation Editor", // context
"application/vnd.nokia.text.scs_cvs_annotation",
"scsannotate"},
{ VCSBase::DiffOutput,
"CVS Diff Editor", // id
QT_TRANSLATE_NOOP("VCS", "CVS Diff Editor"), // display name
"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::VCSBaseEditorWidget::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");
}
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;
}
// ------------- CVSPlugin
CVSPlugin *CVSPlugin::m_cvsPluginInstance = 0;
CVSPlugin::CVSPlugin() :
VCSBase::VCSBasePlugin(QLatin1String(CVS::Constants::CVSCOMMITEDITOR_ID)),
m_commandLocator(0),
m_addAction(0),
m_deleteAction(0),
m_revertAction(0),
m_editCurrentAction(0),
m_uneditCurrentAction(0),
m_uneditRepositoryAction(0),
m_diffProjectAction(0),
m_diffCurrentAction(0),
m_logProjectAction(0),
m_logRepositoryAction(0),
m_commitAllAction(0),
m_revertRepositoryAction(0),
m_commitCurrentAction(0),
m_filelogCurrentAction(0),
m_annotateCurrentAction(0),
m_statusProjectAction(0),
m_updateProjectAction(0),
m_commitProjectAction(0),
m_diffRepositoryAction(0),
m_updateRepositoryAction(0),
m_statusRepositoryAction(0),
m_submitCurrentLogAction(0),
m_submitDiffAction(0),
m_submitUndoAction(0),
m_submitRedoAction(0),
m_menuAction(0),
m_submitActionTriggered(false)
{
}
CVSPlugin::~CVSPlugin()
{
cleanCommitMessageFile();
}
void CVSPlugin::cleanCommitMessageFile()
{
if (!m_commitMessageFileName.isEmpty()) {
QFile::remove(m_commitMessageFileName);
m_commitMessageFileName.clear();
m_commitRepository.clear();
}
}
bool CVSPlugin::isCommitEditorOpen() const
{
return !m_commitMessageFileName.isEmpty();
}
static const VCSBase::VCSBaseSubmitEditorParameters submitParameters = {
CVS::Constants::CVS_SUBMIT_MIMETYPE,
CVS::Constants::CVSCOMMITEDITOR_ID,
CVS::Constants::CVSCOMMITEDITOR_DISPLAY_NAME,
CVS::Constants::CVSCOMMITEDITOR
};
static inline Core::Command *createSeparator(QObject *parent,
Core::ActionManager *ami,
const char *id,
const Core::Context &globalcontext)
{
QAction *tmpaction = new QAction(parent);
tmpaction->setSeparator(true);
return ami->registerAction(tmpaction, id, globalcontext);
}
bool CVSPlugin::initialize(const QStringList & /*arguments */, QString *errorMessage)
{
typedef VCSBase::VCSSubmitEditorFactory<CVSSubmitEditor> CVSSubmitEditorFactory;
typedef VCSBase::VCSEditorFactory<CVSEditor> CVSEditorFactory;
using namespace Constants;
using namespace Core::Constants;
using namespace ExtensionSystem;
VCSBase::VCSBasePlugin::initialize(new CVSControl(this));
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));
addAutoReleasedObject(new CheckoutWizard);
const QString prefix = QLatin1String("cvs");
m_commandLocator = new Locator::CommandLocator(QLatin1String("CVS"), prefix, prefix);
addAutoReleasedObject(m_commandLocator);
//register actions
Core::ActionManager *ami = core->actionManager();
Core::ActionContainer *toolsContainer = ami->actionContainer(M_TOOLS);
Core::ActionContainer *cvsMenu = ami->createMenu(Core::Id(CMD_ID_CVS_MENU));
cvsMenu->menu()->setTitle(tr("&CVS"));
toolsContainer->addMenu(cvsMenu);
m_menuAction = cvsMenu->menu()->menuAction();
Core::Context globalcontext(C_GLOBAL);
Core::Command *command;
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);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Alt+C,Alt+D")));
connect(m_diffCurrentAction, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
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);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_filelogCurrentAction, SIGNAL(triggered()), this,
SLOT(filelogCurrentFile()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
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);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_annotateCurrentAction, SIGNAL(triggered()), this,
SLOT(annotateCurrentFile()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
cvsMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR0, globalcontext));
m_addAction = new Utils::ParameterAction(tr("Add"), tr("Add \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = ami->registerAction(m_addAction, CMD_ID_ADD,
globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDefaultKeySequence(QKeySequence(tr("Alt+C,Alt+A")));
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
m_commitCurrentAction = new Utils::ParameterAction(tr("Commit Current File"), tr("Commit \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
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);
m_commandLocator->appendCommand(command);
m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
command = ami->registerAction(m_deleteAction, CMD_ID_DELETE_FILE,
globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
m_revertAction = new Utils::ParameterAction(tr("Revert..."), tr("Revert \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
command = ami->registerAction(m_revertAction, CMD_ID_REVERT,
globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_revertAction, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
cvsMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR1, globalcontext));
m_editCurrentAction = new Utils::ParameterAction(tr("Edit"), tr("Edit \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = ami->registerAction(m_editCurrentAction, CMD_ID_EDIT_FILE, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
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);
command = ami->registerAction(m_uneditCurrentAction, CMD_ID_UNEDIT_FILE, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_uneditCurrentAction, SIGNAL(triggered()), this, SLOT(uneditCurrentFile()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
m_uneditRepositoryAction = new QAction(tr("Unedit Repository"), this);
command = ami->registerAction(m_uneditRepositoryAction, CMD_ID_UNEDIT_REPOSITORY, globalcontext);
connect(m_uneditRepositoryAction, SIGNAL(triggered()), this, SLOT(uneditCurrentRepository()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
cvsMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR2, 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);
m_commandLocator->appendCommand(command);
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,
globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_statusProjectAction, SIGNAL(triggered()), this, SLOT(projectStatus()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
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);
m_commandLocator->appendCommand(command);
m_updateProjectAction = new Utils::ParameterAction(tr("Update Project"), tr("Update Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = ami->registerAction(m_updateProjectAction, CMD_ID_UPDATE, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_updateProjectAction, SIGNAL(triggered()), this, SLOT(updateProject()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
m_commitProjectAction = new Utils::ParameterAction(tr("Commit Project"), tr("Commit Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
command = ami->registerAction(m_commitProjectAction, CMD_ID_PROJECTCOMMIT, globalcontext);
command->setAttribute(Core::Command::CA_UpdateText);
connect(m_commitProjectAction, SIGNAL(triggered()), this, SLOT(commitProject()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
cvsMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR3, globalcontext));
m_diffRepositoryAction = new QAction(tr("Diff Repository"), this);
command = ami->registerAction(m_diffRepositoryAction, CMD_ID_REPOSITORYDIFF, globalcontext);
connect(m_diffRepositoryAction, SIGNAL(triggered()), this, SLOT(diffRepository()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
m_statusRepositoryAction = new QAction(tr("Repository Status"), this);
command = ami->registerAction(m_statusRepositoryAction, CMD_ID_REPOSITORYSTATUS, globalcontext);
connect(m_statusRepositoryAction, SIGNAL(triggered()), this, SLOT(statusRepository()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
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);
m_commandLocator->appendCommand(command);
m_updateRepositoryAction = new QAction(tr("Update Repository"), this);
command = ami->registerAction(m_updateRepositoryAction, CMD_ID_REPOSITORYUPDATE, globalcontext);
connect(m_updateRepositoryAction, SIGNAL(triggered()), this, SLOT(updateRepository()));
cvsMenu->addAction(command);
m_commandLocator->appendCommand(command);
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);
m_commandLocator->appendCommand(command);
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);
m_commandLocator->appendCommand(command);
// Actions of the submit editor
Core::Context cvscommitcontext(Constants::CVSCOMMITEDITOR);
m_submitCurrentLogAction = new QAction(VCSBase::VCSBaseSubmitEditor::submitIcon(), tr("Commit"), this);
command = ami->registerAction(m_submitCurrentLogAction, Constants::SUBMIT_CURRENT, cvscommitcontext);
command->setAttribute(Core::Command::CA_UpdateText);
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;
}
bool CVSPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEditor)
{
if (!isCommitEditorOpen())
return true;
Core::IFile *fileIFace = submitEditor->file();
const CVSSubmitEditor *editor = qobject_cast<CVSSubmitEditor *>(submitEditor);
if (!fileIFace || !editor)
return true;
// Submit editor closing. Make it write out the commit message
// and retrieve files
const QFileInfo editorFile(fileIFace->fileName());
const QFileInfo changeFile(m_commitMessageFileName);
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:
cleanCommitMessageFile();
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);
closeEditor= commit(m_commitMessageFileName, fileList);
}
if (closeEditor)
cleanCommitMessageFile();
return closeEditor;
}
void CVSPlugin::diffCommitFiles(const QStringList &files)
{
cvsDiff(m_commitRepository, files);
}
static inline void setDiffBaseDirectory(Core::IEditor *editor, const QString &db)
{
if (VCSBase::VCSBaseEditorWidget *ve = qobject_cast<VCSBase::VCSBaseEditorWidget*>(editor->widget()))
ve->setDiffBaseDirectory(db);
}
// Collect all parameters required for a diff to be able to associate them
// with a diff editor and re-run the diff with parameters.
struct CvsDiffParameters
{
QString workingDir;
QStringList arguments;
QStringList files;
};
// Parameter widget controlling whitespace diff mode, associated with a parameter
// struct.
class CvsDiffParameterWidget : public VCSBase::VCSBaseEditorParameterWidget
{
Q_OBJECT
public:
explicit CvsDiffParameterWidget(const CvsDiffParameters &p, QWidget *parent = 0);
signals:
void reRunDiff(const CVS::Internal::CvsDiffParameters &);
public slots:
void triggerReRun();
private:
const CvsDiffParameters m_parameters;
};
CvsDiffParameterWidget::CvsDiffParameterWidget(const CvsDiffParameters &p, QWidget *parent) :
VCSBase::VCSBaseEditorParameterWidget(parent), m_parameters(p)
{
setBaseArguments(p.arguments);
addIgnoreWhiteSpaceButton(QLatin1String("-w"));
addIgnoreBlankLinesButton(QLatin1String("-B"));
connect(this, SIGNAL(argumentsChanged()),
this, SLOT(triggerReRun()));
}
void CvsDiffParameterWidget::triggerReRun()
{
CvsDiffParameters effectiveParameters = m_parameters;
effectiveParameters.arguments = arguments();
emit reRunDiff(effectiveParameters);
}
void CVSPlugin::cvsDiff(const QString &workingDir, const QStringList &files)
{
CvsDiffParameters p;
p.workingDir = workingDir;
p.files = files;
p.arguments = m_settings.cvsDiffOptions.split(QLatin1Char(' '), QString::SkipEmptyParts);
cvsDiff(p);
}
void CVSPlugin::cvsDiff(const CvsDiffParameters &p)
{
if (CVS::Constants::debug)
qDebug() << Q_FUNC_INFO << p.files;
const QString source = VCSBase::VCSBaseEditorWidget::getSource(p.workingDir, p.files);
QTextCodec *codec = VCSBase::VCSBaseEditorWidget::getCodec(p.workingDir, p.files);
const QString id = VCSBase::VCSBaseEditorWidget::getTitleId(p.workingDir, p.files);
QStringList args(QLatin1String("diff"));
args.append(p.arguments);
args.append(p.files);
// CVS returns the diff exit code (1 if files differ), which is
// undistinguishable from a "file not found" error, unfortunately.
const CVSResponse response =
runCVS(p.workingDir, args, m_settings.timeOutMS(), 0, codec);
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
// Show in the same editor if diff has been executed before
const QString tag = VCSBase::VCSBaseEditorWidget::editorTag(VCSBase::DiffOutput, p.workingDir, p.files);
if (Core::IEditor *existingEditor = VCSBase::VCSBaseEditorWidget::locateEditorByTag(tag)) {
existingEditor->createNew(output);
Core::EditorManager::instance()->activateEditor(existingEditor, Core::EditorManager::ModeSwitch);
setDiffBaseDirectory(existingEditor, p.workingDir);
return;
}
const QString title = QString::fromLatin1("cvs diff %1").arg(id);
Core::IEditor *editor = showOutputInEditor(title, output, VCSBase::DiffOutput, source, codec);
VCSBase::VCSBaseEditorWidget::tagEditor(editor, tag);
setDiffBaseDirectory(editor, p.workingDir);
CVSEditor *diffEditorWidget = qobject_cast<CVSEditor*>(editor->widget());
QTC_ASSERT(diffEditorWidget, return ; )
// Wire up the parameter widget to trigger a re-run on
// parameter change and 'revert' from inside the diff editor.
diffEditorWidget->setRevertDiffChunkEnabled(true);
CvsDiffParameterWidget *pw = new CvsDiffParameterWidget(p);
connect(pw, SIGNAL(reRunDiff(CVS::Internal::CvsDiffParameters)),
this, SLOT(cvsDiff(CVS::Internal::CvsDiffParameters)));
connect(diffEditorWidget, SIGNAL(diffChunkReverted(VCSBase::DiffChunk)),
pw, SLOT(triggerReRun()));
diffEditorWidget->setConfigurationWidget(pw);
}
CVSSubmitEditor *CVSPlugin::openCVSSubmitEditor(const QString &fileName)
{
Core::IEditor *editor = Core::EditorManager::instance()->openEditor(fileName, QLatin1String(Constants::CVSCOMMITEDITOR_ID),
Core::EditorManager::ModeSwitch);
CVSSubmitEditor *submitEditor = qobject_cast<CVSSubmitEditor*>(editor);
QTC_ASSERT(submitEditor, /**/);
submitEditor->registerActions(m_submitUndoAction, m_submitRedoAction, m_submitCurrentLogAction, m_submitDiffAction);
connect(submitEditor, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(diffCommitFiles(QStringList)));
return submitEditor;
}
void CVSPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
{
if (!enableMenuAction(as, m_menuAction)) {
m_commandLocator->setEnabled(false);
return;
}
const bool hasTopLevel = currentState().hasTopLevel();
m_commandLocator->setEnabled(hasTopLevel);
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);
m_editCurrentAction->setParameter(currentFileName);
m_uneditCurrentAction->setParameter(currentFileName);
const QString currentProjectName = currentState().currentProjectName();
m_diffProjectAction->setParameter(currentProjectName);
m_statusProjectAction->setParameter(currentProjectName);
m_updateProjectAction->setParameter(currentProjectName);
m_logProjectAction->setParameter(currentProjectName);
m_commitProjectAction->setParameter(currentProjectName);
m_diffRepositoryAction->setEnabled(hasTopLevel);
m_statusRepositoryAction->setEnabled(hasTopLevel);
m_updateRepositoryAction->setEnabled(hasTopLevel);
m_commitAllAction->setEnabled(hasTopLevel);
m_logRepositoryAction->setEnabled(hasTopLevel);
m_uneditRepositoryAction->setEnabled(hasTopLevel);
}
void CVSPlugin::addCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
vcsAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
}
void CVSPlugin::revertAll()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return)
const QString title = tr("Revert repository");
if (!messageBoxQuestion(title, tr("Revert all pending changes to the repository?")))
return;
QStringList args;
args << QLatin1String("update") << QLatin1String("-C") << state.topLevel();
const CVSResponse revertResponse =
runCVS(state.topLevel(), args, m_settings.timeOutMS(),
SshPasswordPrompt|ShowStdOutInLogWindow);
if (revertResponse.result == CVSResponse::Ok) {
cvsVersionControl()->emitRepositoryChanged(state.topLevel());
} else {
QMessageBox::warning(0, title, tr("Revert failed: %1").arg(revertResponse.message), QMessageBox::Ok);
}
}
void CVSPlugin::revertCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
QStringList args;
args << QLatin1String("diff") << state.relativeCurrentFile();
const CVSResponse diffResponse =
runCVS(state.currentFileTopLevel(), args, m_settings.timeOutMS(), 0);
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 (!messageBoxQuestion(QLatin1String("CVS Revert"),
tr("The file has been changed. Do you want to revert it?")))
return;
Core::FileChangeBlocker fcb(state.currentFile());
// revert
args.clear();
args << QLatin1String("update") << QLatin1String("-C") << state.relativeCurrentFile();
const CVSResponse revertResponse =
runCVS(state.currentFileTopLevel(), args, m_settings.timeOutMS(),
SshPasswordPrompt|ShowStdOutInLogWindow);
if (revertResponse.result == CVSResponse::Ok) {
cvsVersionControl()->emitFilesChanged(QStringList(state.currentFile()));
}
}
void CVSPlugin::diffProject()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasProject(), return)
cvsDiff(state.currentProjectTopLevel(), state.relativeCurrentProject());
}
void CVSPlugin::diffCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
cvsDiff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
}
void CVSPlugin::startCommitCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
startCommit(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
}
void CVSPlugin::startCommitAll()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return)
startCommit(state.topLevel());
}
/* Start commit of files of a single repository by displaying
* template and files in a submit editor. On closing, the real
* commit will start. */
void CVSPlugin::startCommit(const QString &workingDir, const QStringList &files)
{
if (VCSBase::VCSBaseSubmitEditor::raiseSubmitEditor())
return;
if (isCommitEditorOpen()) {
VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("Another commit is currently being executed."));
return;
}
// We need the "Examining <subdir>" stderr output to tell
// where we are, so, have stdout/stderr channels merged.
QStringList args = QStringList(QLatin1String("status"));
const CVSResponse response =
runCVS(workingDir, args, m_settings.timeOutMS(), MergeOutputChannels);
if (response.result != CVSResponse::Ok)
return;
// 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);
}
}
}
if (statusOutput.empty()) {
VCSBase::VCSBaseOutputWindow::instance()->append(tr("There are no modified files."));
return;
}
m_commitRepository = workingDir;
// Create a new submit change file containing the submit template
QTemporaryFile changeTmpFile;
changeTmpFile.setAutoRemove(false);
if (!changeTmpFile.open()) {
VCSBase::VCSBaseOutputWindow::instance()->appendError(tr("Cannot create temporary file: %1").arg(changeTmpFile.errorString()));
return;
}
// TODO: Retrieve submit template from
const QString submitTemplate;
m_commitMessageFileName = changeTmpFile.fileName();
// Create a submit
changeTmpFile.write(submitTemplate.toUtf8());
changeTmpFile.flush();
changeTmpFile.close();
// Create a submit editor and set file list
CVSSubmitEditor *editor = openCVSSubmitEditor(m_commitMessageFileName);
editor->setCheckScriptWorkingDirectory(m_commitRepository);
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;
args.append(fileList);
const CVSResponse response =
runCVS(m_commitRepository, args, m_settings.longTimeOutMS(),
SshPasswordPrompt|ShowStdOutInLogWindow);
return response.result == CVSResponse::Ok ;
}
void CVSPlugin::filelogCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
filelog(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()), true);
}
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)
{
QTextCodec *codec = VCSBase::VCSBaseEditorWidget::getCodec(workingDir, files);
// no need for temp file
const QString id = VCSBase::VCSBaseEditorWidget::getTitleId(workingDir, files);
const QString source = VCSBase::VCSBaseEditorWidget::getSource(workingDir, files);
QStringList args;
args << QLatin1String("log");
args.append(files);
const CVSResponse response =
runCVS(workingDir, args, m_settings.timeOutMS(),
SshPasswordPrompt, codec);
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
const QString tag = VCSBase::VCSBaseEditorWidget::editorTag(VCSBase::LogOutput, workingDir, files);
if (Core::IEditor *editor = VCSBase::VCSBaseEditorWidget::locateEditorByTag(tag)) {
editor->createNew(response.stdOut);
Core::EditorManager::instance()->activateEditor(editor, Core::EditorManager::ModeSwitch);
} else {
const QString title = QString::fromLatin1("cvs log %1").arg(id);
Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::LogOutput, source, codec);
VCSBase::VCSBaseEditorWidget::tagEditor(newEditor, tag);
if (enableAnnotationContextMenu)
VCSBase::VCSBaseEditorWidget::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true);
}
}
void CVSPlugin::updateProject()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasProject(), return)
update(state.currentProjectTopLevel(), state.relativeCurrentProject());
}
bool CVSPlugin::update(const QString &topLevel, const QStringList &files)
{
QStringList args(QLatin1String("update"));
args.push_back(QLatin1String("-dR"));
args.append(files);
const CVSResponse response =
runCVS(topLevel, args, m_settings.longTimeOutMS(),
SshPasswordPrompt|ShowStdOutInLogWindow);
const bool ok = response.result == CVSResponse::Ok;
if (ok)
cvsVersionControl()->emitRepositoryChanged(topLevel);
return ok;
}
void CVSPlugin::editCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
edit(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
}
void CVSPlugin::uneditCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
unedit(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
}
void CVSPlugin::uneditCurrentRepository()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return)
unedit(state.topLevel(), QStringList());
}
void CVSPlugin::annotateCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
annotate(state.currentFileTopLevel(), state.relativeCurrentFile());
}
void CVSPlugin::vcsAnnotate(const QString &file, const QString &revision, int lineNumber)
{
const QFileInfo fi(file);
annotate(fi.absolutePath(), fi.fileName(), revision, lineNumber);
}
bool CVSPlugin::edit(const QString &topLevel, const QStringList &files)
{
QStringList args(QLatin1String("edit"));
args.append(files);
const CVSResponse response =
runCVS(topLevel, args, m_settings.timeOutMS(),
ShowStdOutInLogWindow|SshPasswordPrompt);
return response.result == CVSResponse::Ok;
}
bool CVSPlugin::diffCheckModified(const QString &topLevel, const QStringList &files, bool *modified)
{
// Quick check for modified files using diff
*modified = false;
QStringList args(QLatin1String("-q"));
args << QLatin1String("diff");
args.append(files);
const CVSResponse response = runCVS(topLevel, args, m_settings.timeOutMS(), 0);
if (response.result == CVSResponse::OtherError)
return false;
*modified = response.result == CVSResponse::NonNullExitCode;
return true;
}
bool CVSPlugin::unedit(const QString &topLevel, const QStringList &files)
{
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);
const CVSResponse response =
runCVS(topLevel, args, m_settings.timeOutMS(),
ShowStdOutInLogWindow|SshPasswordPrompt);
return response.result == CVSResponse::Ok;
}
void CVSPlugin::annotate(const QString &workingDir, const QString &file,
const QString &revision /* = QString() */,
int lineNumber /* = -1 */)
{
const QStringList files(file);
QTextCodec *codec = VCSBase::VCSBaseEditorWidget::getCodec(workingDir, files);
const QString id = VCSBase::VCSBaseEditorWidget::getTitleId(workingDir, files, revision);
const QString source = VCSBase::VCSBaseEditorWidget::getSource(workingDir, file);
QStringList args;
args << QLatin1String("annotate");
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
args << file;
const CVSResponse response =
runCVS(workingDir, args, m_settings.timeOutMS(),
SshPasswordPrompt, codec);
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
if (lineNumber < 1)
lineNumber = VCSBase::VCSBaseEditorWidget::lineNumberOfCurrentEditor(file);
const QString tag = VCSBase::VCSBaseEditorWidget::editorTag(VCSBase::AnnotateOutput, workingDir, QStringList(file), revision);
if (Core::IEditor *editor = VCSBase::VCSBaseEditorWidget::locateEditorByTag(tag)) {
editor->createNew(response.stdOut);
VCSBase::VCSBaseEditorWidget::gotoLineOfEditor(editor, lineNumber);
Core::EditorManager::instance()->activateEditor(editor, Core::EditorManager::ModeSwitch);
} else {
const QString title = QString::fromLatin1("cvs annotate %1").arg(id);
Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::AnnotateOutput, source, codec);
VCSBase::VCSBaseEditorWidget::tagEditor(newEditor, tag);
VCSBase::VCSBaseEditorWidget::gotoLineOfEditor(newEditor, lineNumber);
}
}
bool CVSPlugin::status(const QString &topLevel, const QStringList &files, const QString &title)
{
QStringList args(QLatin1String("status"));
args.append(files);
const CVSResponse response =
runCVS(topLevel, args, m_settings.timeOutMS(), 0);
const bool ok = response.result == CVSResponse::Ok;
if (ok)
showOutputInEditor(title, response.stdOut, VCSBase::RegularCommandOutput, topLevel, 0);
return ok;
}
void CVSPlugin::projectStatus()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasProject(), return)
status(state.currentProjectTopLevel(), state.relativeCurrentProject(), tr("Project status"));
}
void CVSPlugin::commitProject()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasProject(), return)
startCommit(state.currentProjectTopLevel(), state.relativeCurrentProject());
}
void CVSPlugin::diffRepository()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return)
cvsDiff(state.topLevel(), QStringList());
}
void CVSPlugin::statusRepository()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return)
status(state.topLevel(), QStringList(), tr("Repository status"));
}
void CVSPlugin::updateRepository()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return)
update(state.topLevel(), QStringList());
}
void CVSPlugin::slotDescribe(const QString &source, const QString &changeNr)
{
QString errorMessage;
if (!describe(source, changeNr, &errorMessage))
VCSBase::VCSBaseOutputWindow::instance()->appendError(errorMessage);
}
bool CVSPlugin::describe(const QString &file, const QString &changeNr, QString *errorMessage)
{
QString toplevel;
const bool manages = managesDirectory(QFileInfo(file).absolutePath(), &toplevel);
if (!manages || 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)
{
// 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
if (isFirstRevision(changeNr)) {
*errorMessage = tr("The initial revision %1 cannot be described.").arg(changeNr);
return false;
}
// Run log to obtain commit id and details
QStringList args;
args << QLatin1String("log") << (QLatin1String("-r") + changeNr) << file;
const CVSResponse logResponse =
runCVS(toplevel, args, m_settings.timeOutMS(), SshPasswordPrompt);
if (logResponse.result != CVSResponse::Ok) {
*errorMessage = logResponse.message;
return false;
}
const QList<CVS_LogEntry> fileLog = parseLogEntries(logResponse.stdOut);
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);
const CVSResponse repoLogResponse =
runCVS(toplevel, args, m_settings.longTimeOutMS(), SshPasswordPrompt);
if (repoLogResponse.result != CVSResponse::Ok) {
*errorMessage = repoLogResponse.message;
return false;
}
// Describe all files found, pass on dir to obtain correct absolute paths.
const QList<CVS_LogEntry> repoEntries = parseLogEntries(repoLogResponse.stdOut, QString(), commitId);
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
bool CVSPlugin::describe(const QString &repositoryPath,
QList<CVS_LogEntry> entries,
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)
codec = VCSBase::VCSBaseEditorWidget::getCodec(repositoryPath, QStringList(it->file));
// Run log
QStringList args(QLatin1String("log"));
args << (QLatin1String("-r") + it->revisions.front().revision) << it->file;
const CVSResponse logResponse =
runCVS(repositoryPath, args, m_settings.timeOutMS(), SshPasswordPrompt);
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) {
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;
const CVSResponse diffResponse =
runCVS(repositoryPath, args, m_settings.timeOutMS(), 0, codec);
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:
*errorMessage = diffResponse.message;
return false;
}
output += fixDiffOutput(diffResponse.stdOut);
}
}
// 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 = VCSBase::VCSBaseEditorWidget::locateEditorByTag(commitId)) {
editor->createNew(output);
Core::EditorManager::instance()->activateEditor(editor, Core::EditorManager::ModeSwitch);
setDiffBaseDirectory(editor, repositoryPath);
} else {
const QString title = QString::fromLatin1("cvs describe %1").arg(commitId);
Core::IEditor *newEditor = showOutputInEditor(title, output, VCSBase::DiffOutput, entries.front().file, codec);
VCSBase::VCSBaseEditorWidget::tagEditor(newEditor, commitId);
setDiffBaseDirectory(newEditor, repositoryPath);
}
return true;
}
void CVSPlugin::submitCurrentLog()
{
m_submitActionTriggered = true;
Core::EditorManager::instance()->closeEditors(QList<Core::IEditor*>()
<< Core::EditorManager::instance()->currentEditor());
}
// 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,
unsigned flags,
QTextCodec *outputCodec)
{
const QString executable = m_settings.cvsCommand;
CVSResponse response;
if (executable.isEmpty()) {
response.result = CVSResponse::OtherError;
response.message =tr("No cvs executable specified!");
return response;
}
// Run, connect stderr to the output window
const Utils::SynchronousProcessResponse sp_resp =
runVCS(workingDirectory, executable,
m_settings.addOptions(arguments),
timeOut, flags, outputCodec);
response.result = CVSResponse::OtherError;
response.stdErr = sp_resp.stdErr;
response.stdOut = sp_resp.stdOut;
switch (sp_resp.result) {
case Utils::SynchronousProcessResponse::Finished:
response.result = CVSResponse::Ok;
break;
case Utils::SynchronousProcessResponse::FinishedError:
response.result = CVSResponse::NonNullExitCode;
break;
case Utils::SynchronousProcessResponse::TerminatedAbnormally:
case Utils::SynchronousProcessResponse::StartFailed:
case Utils::SynchronousProcessResponse::Hang:
break;
}
if (response.result != CVSResponse::Ok)
response.message = sp_resp.exitMessage(executable, timeOut);
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);
const QString id = params->id;
if (CVS::Constants::debug)
qDebug() << "CVSPlugin::showOutputInEditor" << title << id << "source=" << source << "Size= " << output.size() << " Type=" << editorType << debugCodec(codec);
QString s = title;
Core::IEditor *editor = Core::EditorManager::instance()->openEditorWithContents(id, &s, output.toLocal8Bit());
connect(editor, SIGNAL(annotateRevisionRequested(QString,QString,int)),
this, SLOT(vcsAnnotate(QString,QString,int)));
CVSEditor *e = qobject_cast<CVSEditor*>(editor->widget());
if (!e)
return 0;
s.replace(QLatin1Char(' '), QLatin1Char('_'));
e->setSuggestedFileName(s);
e->setForceReadOnly(true);
if (!source.isEmpty())
e->setSource(source);
if (codec)
e->setCodec(codec);
Core::IEditor *ie = e->editor();
Core::EditorManager::instance()->activateEditor(ie, Core::EditorManager::ModeSwitch);
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;
}
bool CVSPlugin::vcsAdd(const QString &workingDir, const QString &rawFileName)
{
QStringList args;
args << QLatin1String("add") << rawFileName;
const CVSResponse response =
runCVS(workingDir, args, m_settings.timeOutMS(),
SshPasswordPrompt|ShowStdOutInLogWindow);
return response.result == CVSResponse::Ok;
}
bool CVSPlugin::vcsDelete(const QString &workingDir, const QString &rawFileName)
{
QStringList args;
args << QLatin1String("remove") << QLatin1String("-f") << rawFileName;
const CVSResponse response =
runCVS(workingDir, args, m_settings.timeOutMS(),
SshPasswordPrompt|ShowStdOutInLogWindow);
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, QString *topLevel /* = 0 */) const
{
if (topLevel)
topLevel->clear();
bool manages = false;
const QDir dir(directory);
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;
for (QDir parentDir = lastDirectory; parentDir.cdUp() ; lastDirectory = parentDir) {
if (!checkCVSDirectory(parentDir)) {
*topLevel = lastDirectory.absolutePath();
break;
}
}
} while (false);
if (CVS::Constants::debug) {
QDebug nsp = qDebug().nospace();
nsp << "CVSPlugin::managesDirectory" << directory << manages;
if (topLevel)
nsp << *topLevel;
}
return manages;
}
bool CVSPlugin::checkCVSDirectory(const QDir &directory) const
{
const QString cvsDir = directory.absoluteFilePath(QLatin1String("CVS"));
return QFileInfo(cvsDir).isDir();
}
CVSControl *CVSPlugin::cvsVersionControl() const
{
return static_cast<CVSControl *>(versionControl());
}
}
}
Q_EXPORT_PLUGIN(CVS::Internal::CVSPlugin)
#include "cvsplugin.moc"
|