subversionplugin.cpp 45.5 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11 12 13 14
** 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.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30 31 32 33 34 35 36 37
#include "subversionplugin.h"

#include "settingspage.h"
#include "subversioneditor.h"

#include "subversionsubmiteditor.h"
#include "subversionconstants.h"
#include "subversioncontrol.h"
38
#include "checkoutwizard.h"
con's avatar
con committed
39 40 41 42

#include <vcsbase/basevcseditorfactory.h>
#include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/basevcssubmiteditorfactory.h>
43
#include <vcsbase/vcsbaseoutputwindow.h>
con's avatar
con committed
44
#include <utils/synchronousprocess.h>
45
#include <utils/parameteraction.h>
con's avatar
con committed
46 47 48 49 50 51 52

#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/filemanager.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/uniqueidmanager.h>
53
#include <coreplugin/actionmanager/actionmanager.h>
con's avatar
con committed
54
#include <coreplugin/editormanager/editormanager.h>
hjk's avatar
hjk committed
55
#include <utils/qtcassert.h>
con's avatar
con committed
56 57

#include <QtCore/QDebug>
58
#include <QtCore/QDir>
con's avatar
con committed
59 60
#include <QtCore/QFileInfo>
#include <QtCore/QTemporaryFile>
61 62
#include <QtCore/QTextCodec>
#include <QtCore/QtPlugin>
con's avatar
con committed
63
#include <QtGui/QAction>
64 65
#include <QtGui/QFileDialog>
#include <QtGui/QMainWindow>
con's avatar
con committed
66 67
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
68 69 70
#include <QtGui/QInputDialog>

#include <limits.h>
con's avatar
con committed
71 72 73

using namespace Subversion::Internal;

74 75 76 77 78 79 80 81 82 83 84 85 86 87
static const char * const CMD_ID_SUBVERSION_MENU    = "Subversion.Menu";
static const char * const CMD_ID_ADD                = "Subversion.Add";
static const char * const CMD_ID_DELETE_FILE        = "Subversion.Delete";
static const char * const CMD_ID_REVERT             = "Subversion.Revert";
static const char * const CMD_ID_SEPARATOR0         = "Subversion.Separator0";
static const char * const CMD_ID_DIFF_PROJECT       = "Subversion.DiffAll";
static const char * const CMD_ID_DIFF_CURRENT       = "Subversion.DiffCurrent";
static const char * const CMD_ID_SEPARATOR1         = "Subversion.Separator1";
static const char * const CMD_ID_COMMIT_ALL         = "Subversion.CommitAll";
static const char * const CMD_ID_COMMIT_CURRENT     = "Subversion.CommitCurrent";
static const char * const CMD_ID_SEPARATOR2         = "Subversion.Separator2";
static const char * const CMD_ID_FILELOG_CURRENT    = "Subversion.FilelogCurrent";
static const char * const CMD_ID_ANNOTATE_CURRENT   = "Subversion.AnnotateCurrent";
static const char * const CMD_ID_SEPARATOR3         = "Subversion.Separator3";
88
static const char * const CMD_ID_SEPARATOR4         = "Subversion.Separator4";
89
static const char * const CMD_ID_STATUS             = "Subversion.Status";
90 91
static const char * const CMD_ID_PROJECTLOG         = "Subversion.ProjectLog";
static const char * const CMD_ID_REPOSITORYLOG      = "Subversion.RepositoryLog";
92 93
static const char * const CMD_ID_UPDATE             = "Subversion.Update";
static const char * const CMD_ID_DESCRIBE           = "Subversion.Describe";
con's avatar
con committed
94

95 96
static const char *nonInteractiveOptionC = "--non-interactive";

con's avatar
con committed
97 98 99
static const VCSBase::VCSBaseEditorParameters editorParameters[] = {
{
    VCSBase::RegularCommandOutput,
100 101
    "Subversion Command Log Editor", // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Command Log Editor"), // display name
102
    "Subversion Command Log Editor", // context
con's avatar
con committed
103 104 105
    "application/vnd.nokia.text.scs_svn_commandlog",
    "scslog"},
{   VCSBase::LogOutput,
106 107
    "Subversion File Log Editor",   // id
    QT_TRANSLATE_NOOP("VCS", "Subversion File Log Editor"),   // display_name
108
    "Subversion File Log Editor",   // context
con's avatar
con committed
109 110 111
    "application/vnd.nokia.text.scs_svn_filelog",
    "scsfilelog"},
{    VCSBase::AnnotateOutput,
112 113
    "Subversion Annotation Editor",  // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Annotation Editor"),   // display_name
114
    "Subversion Annotation Editor",  // context
con's avatar
con committed
115 116 117
    "application/vnd.nokia.text.scs_svn_annotation",
    "scsannotate"},
{   VCSBase::DiffOutput,
118 119
    "Subversion Diff Editor",  // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Diff Editor"),   // display_name
120
    "Subversion Diff Editor",  // context
con's avatar
con committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    "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");
}

hjk's avatar
hjk committed
136
Core::IEditor* locateEditor(const char *property, const QString &entry)
con's avatar
con committed
137
{
138
    foreach (Core::IEditor *ed, Core::EditorManager::instance()->openedEditors())
con's avatar
con committed
139 140 141 142 143
        if (ed->property(property).toString() == entry)
            return ed;
    return 0;
}

144 145 146 147 148 149 150 151 152 153 154 155 156 157
// Parse "svn status" output for added/modified/deleted files
// "M<7blanks>file"
typedef QList<SubversionSubmitEditor::StatusFilePair> StatusList;

StatusList parseStatusOutput(const QString &output)
{
    StatusList changeSet;
    const QString newLine = QString(QLatin1Char('\n'));
    const QStringList list = output.split(newLine, QString::SkipEmptyParts);
    foreach (const QString &l, list) {
        const QString line =l.trimmed();
        if (line.size() > 8) {
            const QChar state = line.at(0);
            if (state == QLatin1Char('A') || state == QLatin1Char('D') || state == QLatin1Char('M')) {
158 159
                const QString fileName = line.mid(7); // Column 8 starting from svn 1.6
                changeSet.push_back(SubversionSubmitEditor::StatusFilePair(QString(state), fileName.trimmed()));
160 161 162 163 164 165 166
            }

        }
    }
    return changeSet;
}

167 168 169 170 171 172 173 174 175 176 177
// Return a list of names for the internal svn directories
static inline QStringList svnDirectories()
{
    QStringList rc(QLatin1String(".svn"));
#ifdef Q_OS_WIN
    // Option on Windows systems to avoid hassle with some IDEs
    rc.push_back(QLatin1String("_svn"));
#endif
    return rc;
}

con's avatar
con committed
178 179 180 181
// ------------- SubversionPlugin
SubversionPlugin *SubversionPlugin::m_subversionPluginInstance = 0;

SubversionPlugin::SubversionPlugin() :
182
    VCSBase::VCSBasePlugin(QLatin1String(Subversion::Constants::SUBVERSIONCOMMITEDITOR_ID)),
183
    m_svnDirectories(svnDirectories()),
con's avatar
con committed
184 185 186 187 188
    m_addAction(0),
    m_deleteAction(0),
    m_revertAction(0),
    m_diffProjectAction(0),
    m_diffCurrentAction(0),
189 190
    m_logProjectAction(0),
    m_logRepositoryAction(0),
con's avatar
con committed
191 192 193 194
    m_commitAllAction(0),
    m_commitCurrentAction(0),
    m_filelogCurrentAction(0),
    m_annotateCurrentAction(0),
195
    m_statusProjectAction(0),
con's avatar
con committed
196
    m_updateProjectAction(0),
197
    m_describeAction(0),
con's avatar
con committed
198 199 200
    m_submitCurrentLogAction(0),
    m_submitDiffAction(0),
    m_submitUndoAction(0),
201
    m_submitRedoAction(0),
202
    m_menuAction(0),
203
    m_submitActionTriggered(false)
con's avatar
con committed
204 205 206 207 208
{
}

SubversionPlugin::~SubversionPlugin()
{
209
    cleanCommitMessageFile();
con's avatar
con committed
210 211
}

212
void SubversionPlugin::cleanCommitMessageFile()
con's avatar
con committed
213
{
214 215 216
    if (!m_commitMessageFileName.isEmpty()) {
        QFile::remove(m_commitMessageFileName);
        m_commitMessageFileName.clear();
217
        m_commitRepository.clear();
con's avatar
con committed
218 219 220
    }
}

221 222 223 224 225
bool SubversionPlugin::isCommitEditorOpen() const
{
    return !m_commitMessageFileName.isEmpty();
}

con's avatar
con committed
226 227
static const VCSBase::VCSBaseSubmitEditorParameters submitParameters = {
    Subversion::Constants::SUBVERSION_SUBMIT_MIMETYPE,
228 229
    Subversion::Constants::SUBVERSIONCOMMITEDITOR_ID,
    Subversion::Constants::SUBVERSIONCOMMITEDITOR_DISPLAY_NAME,
230
    Subversion::Constants::SUBVERSIONCOMMITEDITOR
con's avatar
con committed
231 232
};

233 234 235 236 237 238 239 240 241 242
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);
}

243
bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *errorMessage)
con's avatar
con committed
244 245 246 247 248 249 250 251
{
    typedef VCSBase::VCSSubmitEditorFactory<SubversionSubmitEditor> SubversionSubmitEditorFactory;
    typedef VCSBase::VCSEditorFactory<SubversionEditor> SubversionEditorFactory;
    using namespace Constants;

    using namespace Core::Constants;
    using namespace ExtensionSystem;

252 253
    VCSBase::VCSBasePlugin::initialize(new SubversionControl(this));

con's avatar
con committed
254
    m_subversionPluginInstance = this;
hjk's avatar
hjk committed
255
    Core::ICore *core = Core::ICore::instance();
con's avatar
con committed
256

hjk's avatar
hjk committed
257
    if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/trolltech.subversion/Subversion.mimetypes.xml"), errorMessage))
con's avatar
con committed
258 259
        return false;

hjk's avatar
hjk committed
260
    if (QSettings *settings = core->settings())
con's avatar
con committed
261 262
        m_settings.fromSettings(settings);

263
    addAutoReleasedObject(new SettingsPage);
con's avatar
con committed
264

265
    addAutoReleasedObject(new SubversionSubmitEditorFactory(&submitParameters));
con's avatar
con committed
266 267 268

    static const char *describeSlot = SLOT(describe(QString,QString));
    const int editorCount = sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters);
269 270
    for (int i = 0; i < editorCount; i++)
        addAutoReleasedObject(new SubversionEditorFactory(editorParameters + i, this, describeSlot));
con's avatar
con committed
271

272 273
    addAutoReleasedObject(new CheckoutWizard);

con's avatar
con committed
274
    //register actions
hjk's avatar
hjk committed
275
    Core::ActionManager *ami = core->actionManager();
276
    Core::ActionContainer *toolsContainer = ami->actionContainer(M_TOOLS);
con's avatar
con committed
277

278
    Core::ActionContainer *subversionMenu =
279
        ami->createMenu(QLatin1String(CMD_ID_SUBVERSION_MENU));
con's avatar
con committed
280 281
    subversionMenu->menu()->setTitle(tr("&Subversion"));
    toolsContainer->addMenu(subversionMenu);
282
    m_menuAction = subversionMenu->menu()->menuAction();
con's avatar
con committed
283
    QList<int> globalcontext;
hjk's avatar
hjk committed
284
    globalcontext << core->uniqueIDManager()->uniqueIdentifier(C_GLOBAL);
con's avatar
con committed
285

con's avatar
con committed
286
    Core::Command *command;
287
    m_addAction = new Utils::ParameterAction(tr("Add"), tr("Add \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
288
    command = ami->registerAction(m_addAction, CMD_ID_ADD,
con's avatar
con committed
289
        globalcontext);
con's avatar
con committed
290
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
291 292 293 294
    command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+A")));
    connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
    subversionMenu->addAction(command);

295
    m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
296
    command = ami->registerAction(m_deleteAction, CMD_ID_DELETE_FILE,
con's avatar
con committed
297
        globalcontext);
con's avatar
con committed
298
    command->setAttribute(Core::Command::CA_UpdateText);
299
    connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
con's avatar
con committed
300 301
    subversionMenu->addAction(command);

302
    m_revertAction = new Utils::ParameterAction(tr("Revert..."), tr("Revert \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
303
    command = ami->registerAction(m_revertAction, CMD_ID_REVERT,
con's avatar
con committed
304
        globalcontext);
con's avatar
con committed
305
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
306 307 308
    connect(m_revertAction, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
    subversionMenu->addAction(command);

309
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR0, globalcontext));
con's avatar
con committed
310

311
    m_diffProjectAction = new Utils::ParameterAction(tr("Diff Project"), tr("Diff Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
312
    command = ami->registerAction(m_diffProjectAction, CMD_ID_DIFF_PROJECT,
con's avatar
con committed
313
        globalcontext);
314
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
315 316 317
    connect(m_diffProjectAction, SIGNAL(triggered()), this, SLOT(diffProject()));
    subversionMenu->addAction(command);

318
    m_diffCurrentAction = new Utils::ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
con's avatar
con committed
319
    command = ami->registerAction(m_diffCurrentAction,
320
        CMD_ID_DIFF_CURRENT, globalcontext);
con's avatar
con committed
321
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
322 323 324 325
    command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+D")));
    connect(m_diffCurrentAction, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
    subversionMenu->addAction(command);

326
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR1, globalcontext));
con's avatar
con committed
327 328

    m_commitAllAction = new QAction(tr("Commit All Files"), this);
329
    command = ami->registerAction(m_commitAllAction, CMD_ID_COMMIT_ALL,
con's avatar
con committed
330 331 332 333
        globalcontext);
    connect(m_commitAllAction, SIGNAL(triggered()), this, SLOT(startCommitAll()));
    subversionMenu->addAction(command);

334
    m_commitCurrentAction = new Utils::ParameterAction(tr("Commit Current File"), tr("Commit \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
con's avatar
con committed
335
    command = ami->registerAction(m_commitCurrentAction,
336
        CMD_ID_COMMIT_CURRENT, globalcontext);
con's avatar
con committed
337
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
338 339 340 341
    command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+C")));
    connect(m_commitCurrentAction, SIGNAL(triggered()), this, SLOT(startCommitCurrentFile()));
    subversionMenu->addAction(command);

342
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR2, globalcontext));
con's avatar
con committed
343

344
    m_filelogCurrentAction = new Utils::ParameterAction(tr("Filelog Current File"), tr("Filelog \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
con's avatar
con committed
345
    command = ami->registerAction(m_filelogCurrentAction,
346
        CMD_ID_FILELOG_CURRENT, globalcontext);
con's avatar
con committed
347
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
348 349 350 351
    connect(m_filelogCurrentAction, SIGNAL(triggered()), this,
        SLOT(filelogCurrentFile()));
    subversionMenu->addAction(command);

352
    m_annotateCurrentAction = new Utils::ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
con's avatar
con committed
353
    command = ami->registerAction(m_annotateCurrentAction,
354
        CMD_ID_ANNOTATE_CURRENT, globalcontext);
con's avatar
con committed
355
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
356 357 358 359
    connect(m_annotateCurrentAction, SIGNAL(triggered()), this,
        SLOT(annotateCurrentFile()));
    subversionMenu->addAction(command);

360
    m_describeAction = new QAction(tr("Describe..."), this);
361
    command = ami->registerAction(m_describeAction, CMD_ID_DESCRIBE, globalcontext);
362 363 364
    connect(m_describeAction, SIGNAL(triggered()), this, SLOT(slotDescribe()));
    subversionMenu->addAction(command);

365
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR3, globalcontext));
con's avatar
con committed
366

367 368
    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,
con's avatar
con committed
369
        globalcontext);
370 371
    command->setAttribute(Core::Command::CA_UpdateText);
    connect(m_statusProjectAction, SIGNAL(triggered()), this, SLOT(projectStatus()));
con's avatar
con committed
372 373
    subversionMenu->addAction(command);

374 375 376 377 378 379
    m_logProjectAction = new Utils::ParameterAction(tr("Log Project Log"), 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()));
    subversionMenu->addAction(command);

380
    m_updateProjectAction = new Utils::ParameterAction(tr("Update Project"), tr("Update Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
381
    command = ami->registerAction(m_updateProjectAction, CMD_ID_UPDATE, globalcontext);
con's avatar
con committed
382
    connect(m_updateProjectAction, SIGNAL(triggered()), this, SLOT(updateProject()));
383
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
384 385
    subversionMenu->addAction(command);

386 387 388 389 390 391
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR4, globalcontext));
    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()));
    subversionMenu->addAction(command);

con's avatar
con committed
392 393
    // Actions of the submit editor
    QList<int> svncommitcontext;
394
    svncommitcontext << Core::UniqueIDManager::instance()->uniqueIdentifier(Constants::SUBVERSIONCOMMITEDITOR);
con's avatar
con committed
395

396
    m_submitCurrentLogAction = new QAction(VCSBase::VCSBaseSubmitEditor::submitIcon(), tr("Commit"), this);
con's avatar
con committed
397 398 399
    command = ami->registerAction(m_submitCurrentLogAction, Constants::SUBMIT_CURRENT, svncommitcontext);
    connect(m_submitCurrentLogAction, SIGNAL(triggered()), this, SLOT(submitCurrentLog()));

400
    m_submitDiffAction = new QAction(VCSBase::VCSBaseSubmitEditor::diffIcon(), tr("Diff Selected Files"), this);
con's avatar
con committed
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
    command = ami->registerAction(m_submitDiffAction , Constants::DIFF_SELECTED, svncommitcontext);

    m_submitUndoAction = new QAction(tr("&Undo"), this);
    command = ami->registerAction(m_submitUndoAction, Core::Constants::UNDO, svncommitcontext);

    m_submitRedoAction = new QAction(tr("&Redo"), this);
    command = ami->registerAction(m_submitRedoAction, Core::Constants::REDO, svncommitcontext);

    return true;
}

void SubversionPlugin::extensionsInitialized()
{
}

416
bool SubversionPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEditor)
con's avatar
con committed
417
{
418
    if (!isCommitEditorOpen())
con's avatar
con committed
419 420
        return true;

421 422
    Core::IFile *fileIFace = submitEditor->file();
    const SubversionSubmitEditor *editor = qobject_cast<SubversionSubmitEditor *>(submitEditor);
con's avatar
con committed
423 424 425 426 427 428
    if (!fileIFace || !editor)
        return true;

    // Submit editor closing. Make it write out the commit message
    // and retrieve files
    const QFileInfo editorFile(fileIFace->fileName());
429
    const QFileInfo changeFile(m_commitMessageFileName);
con's avatar
con committed
430 431 432
    if (editorFile.absoluteFilePath() != changeFile.absoluteFilePath())
        return true; // Oops?!

433 434
    // Prompt user. Force a prompt unless submit was actually invoked (that
    // is, the editor was closed or shutdown).
435
    SubversionSettings newSettings = m_settings;
436 437 438
    const VCSBase::VCSBaseSubmitEditor::PromptSubmitResult answer =
            editor->promptSubmit(tr("Closing Subversion Editor"),
                                 tr("Do you want to commit the change?"),
439
                                 tr("The commit message check failed. Do you want to commit the change?"),
440
                                 &newSettings.promptToSubmit, !m_submitActionTriggered);
441
    m_submitActionTriggered = false;
con's avatar
con committed
442
    switch (answer) {
443
    case VCSBase::VCSBaseSubmitEditor::SubmitCanceled:
con's avatar
con committed
444
        return false; // Keep editing and change file
445
    case VCSBase::VCSBaseSubmitEditor::SubmitDiscarded:
446
        cleanCommitMessageFile();
con's avatar
con committed
447 448 449 450
        return true; // Cancel all
    default:
        break;
    }
451
    setSettings(newSettings); // in case someone turned prompting off
con's avatar
con committed
452
    const QStringList fileList = editor->checkedFiles();
453
    bool closeEditor = true;
con's avatar
con committed
454 455
    if (!fileList.empty()) {
        // get message & commit
hjk's avatar
hjk committed
456
        Core::ICore::instance()->fileManager()->blockFileChange(fileIFace);
con's avatar
con committed
457
        fileIFace->save();
hjk's avatar
hjk committed
458
        Core::ICore::instance()->fileManager()->unblockFileChange(fileIFace);
459
        closeEditor= commit(m_commitMessageFileName, fileList);
con's avatar
con committed
460
    }
461
    if (closeEditor)
462
        cleanCommitMessageFile();
463
    return closeEditor;
con's avatar
con committed
464 465
}

466
void SubversionPlugin::diffCommitFiles(const QStringList &files)
con's avatar
con committed
467
{
468
    svnDiff(m_commitRepository, files);
con's avatar
con committed
469 470
}

471 472 473 474 475 476
static inline void setDiffBaseDirectory(Core::IEditor *editor, const QString &db)
{
    if (VCSBase::VCSBaseEditor *ve = qobject_cast<VCSBase::VCSBaseEditor*>(editor->widget()))
        ve->setDiffBaseDirectory(db);
}

477
void SubversionPlugin::svnDiff(const QString &workingDir, const QStringList &files, QString diffname)
con's avatar
con committed
478 479 480
{
    if (Subversion::Constants::debug)
        qDebug() << Q_FUNC_INFO << files << diffname;
481
    const QString source = VCSBase::VCSBaseEditor::getSource(workingDir, files);
482
    QTextCodec *codec = source.isEmpty() ? static_cast<QTextCodec *>(0) : VCSBase::VCSBaseEditor::getCodec(source);
con's avatar
con committed
483 484 485 486 487 488 489

    if (files.count() == 1 && diffname.isEmpty())
        diffname = QFileInfo(files.front()).fileName();

    QStringList args(QLatin1String("diff"));
    args << files;

490
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false, codec);
con's avatar
con committed
491 492 493 494 495 496 497
    if (response.error)
        return;

    // diff of a single file? re-use an existing view if possible to support
    // the common usage pattern of continuously changing and diffing a file
    if (files.count() == 1) {
        // Show in the same editor if diff has been executed before
hjk's avatar
hjk committed
498
        if (Core::IEditor *editor = locateEditor("originalFileName", files.front())) {
con's avatar
con committed
499
            editor->createNew(response.stdOut);
500
            Core::EditorManager::instance()->activateEditor(editor);
501
            setDiffBaseDirectory(editor, workingDir);
con's avatar
con committed
502 503 504
            return;
        }
    }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
505
    const QString title = QString::fromLatin1("svn diff %1").arg(diffname);
con's avatar
con committed
506
    Core::IEditor *editor = showOutputInEditor(title, response.stdOut, VCSBase::DiffOutput, source, codec);
507
    setDiffBaseDirectory(editor, workingDir);
con's avatar
con committed
508 509 510 511 512 513
    if (files.count() == 1)
        editor->setProperty("originalFileName", files.front());
}

SubversionSubmitEditor *SubversionPlugin::openSubversionSubmitEditor(const QString &fileName)
{
514
    Core::IEditor *editor = Core::EditorManager::instance()->openEditor(fileName, QLatin1String(Constants::SUBVERSIONCOMMITEDITOR_ID));
con's avatar
con committed
515
    SubversionSubmitEditor *submitEditor = qobject_cast<SubversionSubmitEditor*>(editor);
hjk's avatar
hjk committed
516
    QTC_ASSERT(submitEditor, /**/);
517
    submitEditor->registerActions(m_submitUndoAction, m_submitRedoAction, m_submitCurrentLogAction, m_submitDiffAction);
518
    connect(submitEditor, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(diffCommitFiles(QStringList)));
519
    submitEditor->setCheckScriptWorkingDirectory(m_commitRepository);
con's avatar
con committed
520 521 522 523

    return submitEditor;
}

524
void SubversionPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
con's avatar
con committed
525
{
526 527 528
    if (!VCSBase::VCSBasePlugin::enableMenuAction(as, m_menuAction))
        return;

529 530
    m_logRepositoryAction->setEnabled(currentState().hasTopLevel());

531 532 533 534
    const QString projectName = currentState().currentProjectName();
    m_diffProjectAction->setParameter(projectName);
    m_statusProjectAction->setParameter(projectName);
    m_updateProjectAction->setParameter(projectName);
535
    m_logProjectAction->setParameter(projectName);
536 537 538 539 540 541 542 543 544 545 546 547 548 549

    const bool repoEnabled = currentState().hasTopLevel();
    m_commitAllAction->setEnabled(repoEnabled);
    m_describeAction->setEnabled(repoEnabled);

    const QString fileName = currentState().currentFileName();

    m_addAction->setParameter(fileName);
    m_deleteAction->setParameter(fileName);
    m_revertAction->setParameter(fileName);
    m_diffCurrentAction->setParameter(fileName);
    m_commitCurrentAction->setParameter(fileName);
    m_filelogCurrentAction->setParameter(fileName);
    m_annotateCurrentAction->setParameter(fileName);
con's avatar
con committed
550 551 552 553
}

void SubversionPlugin::addCurrentFile()
{
554 555 556
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    vcsAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
557 558 559 560
}

void SubversionPlugin::revertCurrentFile()
{
561 562
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
con's avatar
con committed
563 564

    QStringList args(QLatin1String("diff"));
565
    args.push_back(state.relativeCurrentFile());
con's avatar
con committed
566

567
    const SubversionResponse diffResponse = runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMS(), false);
con's avatar
con committed
568 569 570 571 572
    if (diffResponse.error)
        return;

    if (diffResponse.stdOut.isEmpty())
        return;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
573
    if (QMessageBox::warning(0, QLatin1String("svn revert"), tr("The file has been changed. Do you want to revert it?"),
con's avatar
con committed
574 575 576
                             QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
        return;

577

578
    Core::FileChangeBlocker fcb(state.currentFile());
con's avatar
con committed
579 580 581

    // revert
    args.clear();
582
    args << QLatin1String("revert") << state.relativeCurrentFile();
con's avatar
con committed
583

584
    const SubversionResponse revertResponse = runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMS(), true);
585 586
    if (!revertResponse.error) {
        fcb.setModifiedReload(true);
587
        subVersionControl()->emitFilesChanged(QStringList(state.currentFile()));
con's avatar
con committed
588 589 590 591 592
    }
}

void SubversionPlugin::diffProject()
{
593 594 595
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)
    svnDiff(state.currentProjectTopLevel(), state.relativeCurrentProject(), state.currentProjectName());
con's avatar
con committed
596 597 598 599
}

void SubversionPlugin::diffCurrentFile()
{
600 601 602
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    svnDiff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
con's avatar
con committed
603 604 605 606
}

void SubversionPlugin::startCommitCurrentFile()
{
607 608 609
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    startCommit(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
con's avatar
con committed
610 611 612 613
}

void SubversionPlugin::startCommitAll()
{
614 615 616
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return);
    startCommit(state.topLevel());
con's avatar
con committed
617 618 619 620 621
}

/* Start commit of files of a single repository by displaying
 * template and files in a submit editor. On closing, the real
 * commit will start. */
622
void SubversionPlugin::startCommit(const QString &workingDir, const QStringList &files)
con's avatar
con committed
623
{
624 625
    if (VCSBase::VCSBaseSubmitEditor::raiseSubmitEditor())
        return;
626
    if (isCommitEditorOpen()) {
627
        VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("Another commit is currently being executed."));
con's avatar
con committed
628 629 630 631 632 633
        return;
    }

    QStringList args(QLatin1String("status"));
    args += files;

634
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false);
con's avatar
con committed
635 636
    if (response.error)
        return;
637

con's avatar
con committed
638
    // Get list of added/modified/deleted files
639
    const StatusList statusOutput = parseStatusOutput(response.stdOut);
con's avatar
con committed
640
    if (statusOutput.empty()) {
641
        VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("There are no modified files."));
con's avatar
con committed
642 643
        return;
    }
644
    m_commitRepository = workingDir;
con's avatar
con committed
645
    // Create a new submit change file containing the submit template
646 647 648 649
    QTemporaryFile changeTmpFile;
    changeTmpFile.setAutoRemove(false);
    if (!changeTmpFile.open()) {
        VCSBase::VCSBaseOutputWindow::instance()->appendError(tr("Cannot create temporary file: %1").arg(changeTmpFile.errorString()));
con's avatar
con committed
650 651
        return;
    }
652
    m_commitMessageFileName = changeTmpFile.fileName();
653
    // TODO: Regitctrieve submit template from
con's avatar
con committed
654 655
    const QString submitTemplate;
    // Create a submit
656 657 658
    changeTmpFile.write(submitTemplate.toUtf8());
    changeTmpFile.flush();
    changeTmpFile.close();
con's avatar
con committed
659
    // Create a submit editor and set file list
660
    SubversionSubmitEditor *editor = openSubversionSubmitEditor(m_commitMessageFileName);
661
    editor->setStatusList(statusOutput);
con's avatar
con committed
662 663 664 665 666 667 668 669 670 671 672
}

bool SubversionPlugin::commit(const QString &messageFile,
                              const QStringList &subVersionFileList)
{
    if (Subversion::Constants::debug)
        qDebug() << Q_FUNC_INFO << messageFile << subVersionFileList;
    // Transform the status list which is sth
    // "[ADM]<blanks>file" into an args list. The files of the status log
    // can be relative or absolute depending on where the command was run.
    QStringList args = QStringList(QLatin1String("commit"));
673
    args << QLatin1String(nonInteractiveOptionC) << QLatin1String("--file") << messageFile;
con's avatar
con committed
674
    args.append(subVersionFileList);
675
    const SubversionResponse response = runSvn(m_commitRepository, args, m_settings.longTimeOutMS(), true);
con's avatar
con committed
676 677 678 679 680
    return !response.error ;
}

void SubversionPlugin::filelogCurrentFile()
{
681 682
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
   filelog(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()), true);
}

void SubversionPlugin::logProject()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)
    filelog(state.currentProjectTopLevel(), state.relativeCurrentProject());
}

void SubversionPlugin::logRepository()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return)
    filelog(state.topLevel());
con's avatar
con committed
698 699
}

700 701 702
void SubversionPlugin::filelog(const QString &workingDir,
                               const QStringList &files,
                               bool enableAnnotationContextMenu)
con's avatar
con committed
703
{
704
    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(workingDir, files);
con's avatar
con committed
705 706
    // no need for temp file
    QStringList args(QLatin1String("log"));
707 708
    if (m_settings.logCount > 0)
        args << QLatin1String("-l") << QString::number(m_settings.logCount);
709 710
    foreach(const QString &file, files)
        args.append(QDir::toNativeSeparators(file));
con's avatar
con committed
711

712
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false, codec);
con's avatar
con committed
713 714 715 716 717 718
    if (response.error)
        return;

    // Re-use an existing view if possible to support
    // the common usage pattern of continuously changing and diffing a file

719 720
    const QString id = VCSBase::VCSBaseEditor::getTitleId(workingDir, files);
    if (Core::IEditor *editor = locateEditor("logFileName", id)) {
con's avatar
con committed
721
        editor->createNew(response.stdOut);
722
        Core::EditorManager::instance()->activateEditor(editor);
con's avatar
con committed
723
    } else {
724 725 726 727
        const QString title = QString::fromLatin1("svn log %1").arg(id);
        const QString source = VCSBase::VCSBaseEditor::getSource(workingDir, files);
        Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::LogOutput, source, codec);
        newEditor->setProperty("logFileName", id);
728 729
        if (enableAnnotationContextMenu)
            VCSBase::VCSBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true);
con's avatar
con committed
730 731 732 733 734
    }
}

void SubversionPlugin::updateProject()
{
735 736
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return);
con's avatar
con committed
737 738

    QStringList args(QLatin1String("update"));
739
    args.push_back(QLatin1String(nonInteractiveOptionC));
740
    args.append(state.relativeCurrentProject());
741
    const SubversionResponse response = runSvn(state.currentProjectTopLevel(), args, m_settings.longTimeOutMS(), true);
742 743
    if (!response.error)
        subVersionControl()->emitRepositoryChanged(state.currentProjectTopLevel());
con's avatar
con committed
744 745 746 747
}

void SubversionPlugin::annotateCurrentFile()
{
748 749 750
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return);
    annotate(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
751 752
}

753 754 755 756 757 758 759 760 761 762 763
void SubversionPlugin::annotateVersion(const QString &file,
                                       const QString &revision,
                                       int lineNr)
{
    const QFileInfo fi(file);
    annotate(fi.absolutePath(), fi.fileName(), revision, lineNr);
}

void SubversionPlugin::annotate(const QString &workingDir, const QString &file,
                                const QString &revision /* = QString() */,
                                int lineNumber /* = -1 */)
con's avatar
con committed
764
{
765
    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(file);
con's avatar
con committed
766 767

    QStringList args(QLatin1String("annotate"));
768 769
    if (m_settings.spaceIgnorantAnnotation)
        args << QLatin1String("-x") << QLatin1String("-uw");
770 771
    if (!revision.isEmpty())
        args << QLatin1String("-r") << revision;
con's avatar
con committed
772 773 774
    args.push_back(QLatin1String("-v"));
    args.append(QDir::toNativeSeparators(file));

775
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false, codec);
con's avatar
con committed
776 777 778 779 780
    if (response.error)
        return;

    // Re-use an existing view if possible to support
    // the common usage pattern of continuously changing and diffing a file
781
    const QString source = workingDir + QLatin1Char('/') + file;
782 783 784 785
    if (lineNumber <= 0)
        lineNumber = VCSBase::VCSBaseEditor::lineNumberOfCurrentEditor(source);
    // Determine id
    const QString id = VCSBase::VCSBaseEditor::getTitleId(workingDir, QStringList(file), revision);
con's avatar
con committed
786

787
    if (Core::IEditor *editor = locateEditor("annotateFileName", id)) {
con's avatar
con committed
788
        editor->createNew(response.stdOut);
789 790
        VCSBase::VCSBaseEditor::gotoLineOfEditor(editor, lineNumber);
        Core::EditorManager::instance()->activateEditor(editor);        
con's avatar
con committed
791
    } else {
792 793 794
        const QString title = QString::fromLatin1("svn annotate %1").arg(id);
        Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::AnnotateOutput, source, codec);
        newEditor->setProperty("annotateFileName", id);
795
        VCSBase::VCSBaseEditor::gotoLineOfEditor(newEditor, lineNumber);
con's avatar
con committed
796 797 798 799 800
    }
}

void SubversionPlugin::projectStatus()
{
801 802
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return);
con's avatar
con committed
803
    QStringList args(QLatin1String("status"));
804
    args += state.relativeCurrentProject();
805 806
    VCSBase::VCSBaseOutputWindow *outwin = VCSBase::VCSBaseOutputWindow::instance();
    outwin->setRepository(state.currentProjectTopLevel());
807
    runSvn(state.currentProjectTopLevel(), args, m_settings.timeOutMS(), true);
808
    outwin->clearRepository();
con's avatar
con committed
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
}

void SubversionPlugin::describe(const QString &source, const QString &changeNr)
{
    // To describe a complete change, find the top level and then do
    //svn diff -r 472958:472959 <top level>
    const QFileInfo fi(source);
    const QString topLevel = findTopLevelForDirectory(fi.isDir() ? source : fi.absolutePath());
    if (topLevel.isEmpty())
        return;
    if (Subversion::Constants::debug)
        qDebug() << Q_FUNC_INFO << source << topLevel << changeNr;
    // Number must be > 1
    bool ok;
    const int number = changeNr.toInt(&ok);
    if (!ok || number < 2)
        return;
826 827 828 829 830
    // Run log to obtain message (local utf8)
    QString description;
    QStringList args(QLatin1String("log"));
    args.push_back(QLatin1String("-r"));
    args.push_back(changeNr);
831
    const SubversionResponse logResponse = runSvn(topLevel, args, m_settings.timeOutMS(), false);
832 833 834 835 836 837 838
    if (logResponse.error)
        return;
    description = logResponse.stdOut;

    // Run diff (encoding via source codec)
    args.clear();
    args.push_back(QLatin1String("diff"));
con's avatar
con committed
839 840 841 842 843
    args.push_back(QLatin1String("-r"));
    QString diffArg;
    QTextStream(&diffArg) << (number - 1) << ':' << number;
    args.push_back(diffArg);

844
    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(source);
845
    const SubversionResponse response = runSvn(topLevel, args, m_settings.timeOutMS(), false, codec);
con's avatar
con committed
846 847
    if (response.error)
        return;
848
    description += response.stdOut;
con's avatar
con committed
849 850 851 852

    // Re-use an existing view if possible to support
    // the common usage pattern of continuously changing and diffing a file
    const QString id = diffArg + source;
hjk's avatar
hjk committed
853
    if (Core::IEditor *editor = locateEditor("describeChange", id)) {
854
        editor->createNew(description);
hjk's avatar
hjk committed
855
        Core::EditorManager::instance()->activateEditor(editor);
con's avatar
con committed
856
    } else {
857
        const QString title = QString::fromLatin1("svn describe %1#%2").arg(fi.fileName(), changeNr);
858
        Core::IEditor *newEditor = showOutputInEditor(title, description, VCSBase::DiffOutput, source, codec);
con's avatar
con committed
859 860 861 862
        newEditor->setProperty("describeChange", id);
    }
}

863 864
void SubversionPlugin::slotDescribe()
{
865 866
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return);
867 868 869 870 871 872 873 874 875 876 877

    QInputDialog inputDialog(Core::ICore::instance()->mainWindow());
    inputDialog.setWindowFlags(inputDialog.windowFlags() & ~Qt::WindowContextHelpButtonHint);
    inputDialog.setInputMode(QInputDialog::IntInput);
    inputDialog.setIntRange(2, INT_MAX);
    inputDialog.setWindowTitle(tr("Describe"));
    inputDialog.setLabelText(tr("Revision number:"));
    if (inputDialog.exec() != QDialog::Accepted)
        return;

    const int revision = inputDialog.intValue();
878
    describe(state.topLevel(), QString::number(revision));
879 880
}

con's avatar
con committed
881 882
void SubversionPlugin::submitCurrentLog()
{
883
    m_submitActionTriggered = true;
884 885
    Core::EditorManager::instance()->closeEditors(QList<Core::IEditor*>()
        << Core::EditorManager::instance()->currentEditor());
con's avatar
con committed
886 887 888 889 890 891 892 893 894 895 896 897 898 899
}

static inline QString processStdErr(QProcess &proc)
{
    return QString::fromLocal8Bit(proc.readAllStandardError()).remove(QLatin1Char('\r'));
}

static inline QString processStdOut(QProcess &proc, QTextCodec *outputCodec = 0)
{
    const QByteArray stdOutData = proc.readAllStandardOutput();
    QString stdOut = outputCodec ? outputCodec->toUnicode(stdOutData) : QString::fromLocal8Bit(stdOutData);
    return stdOut.remove(QLatin1Char('\r'));
}

900 901
SubversionResponse SubversionPlugin::runSvn(const QString &workingDir,
                                            const QStringList &arguments,
con's avatar
con committed
902 903 904 905 906 907 908 909 910 911 912 913 914
                                            int timeOut,
                                            bool showStdOutInOutputWindow,
                                            QTextCodec *outputCodec)
{
    const QString executable = m_settings.svnCommand;
    SubversionResponse response;
    if (executable.isEmpty()) {
        response.error = true;
        response.message =tr("No subversion executable specified!");
        return response;
    }
    const QStringList allArgs = m_settings.addOptions(arguments);

915
    VCSBase::VCSBaseOutputWindow *outputWindow = VCSBase::VCSBaseOutputWindow::instance();
con's avatar
con committed
916
    // Hide passwords, etc in the log window
917 918 919
    //: Executing: <executable> <arguments>
    const QString outputText = tr("Executing: %1 %2\n").arg(executable, SubversionSettings::formatArguments(allArgs));
    outputWindow->appendCommand(outputText);
con's avatar
con committed
920 921 922 923 924

    if (Subversion::Constants::debug)
        qDebug() << "runSvn" << timeOut << outputText;

    // Run, connect stderr to the output window
925
    Utils::SynchronousProcess process;
926 927
    if (!workingDir.isEmpty())
        process.setWorkingDirectory(workingDir);
con's avatar
con committed
928 929 930 931
    process.setTimeout(timeOut);
    process.setStdOutCodec(outputCodec);

    process.setStdErrBufferedSignalsEnabled(true);
932
    connect(&process, SIGNAL(stdErrBuffered(QString,bool)), outputWindow, SLOT(append(QString)));
con's avatar
con committed
933 934 935 936

    // connect stdout to the output window if desired
    if (showStdOutInOutputWindow) {
        process.setStdOutBufferedSignalsEnabled(true);
937
        connect(&process, SIGNAL(stdOutBuffered(QString,bool)), outputWindow, SLOT(append(QString)));
con's avatar
con committed
938 939
    }

940
    const Utils::SynchronousProcessResponse sp_resp = process.run(executable, allArgs);
con's avatar
con committed
941 942 943 944
    response.error = true;
    response.stdErr = sp_resp.stdErr;
    response.stdOut = sp_resp.stdOut;
    switch (sp_resp.result) {
945
    case Utils::SynchronousProcessResponse::Finished:
con's avatar
con committed
946 947
        response.error = false;
        break;
948
    case Utils::SynchronousProcessResponse::FinishedError:
con's avatar
con committed
949 950
        response.message = tr("The process terminated with exit code %1.").arg(sp_resp.exitCode);
        break;
951
    case Utils::SynchronousProcessResponse::TerminatedAbnormally:
con's avatar
con committed
952 953
        response.message = tr("The process terminated abnormally.");
        break;
954
    case Utils::SynchronousProcessResponse::StartFailed:
con's avatar
con committed
955 956
        response.message = tr("Could not start subversion '%1'. Please check your settings in the preferences.").arg(executable);
        break;
957
    case Utils::SynchronousProcessResponse::Hang:
con's avatar
con committed
958 959 960 961
        response.message = tr("Subversion did not respond within timeout limit (%1 ms).").arg(timeOut);
        break;
    }
    if (response.error)