subversionplugin.cpp 54.8 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 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
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11 12 13 14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
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
**
con's avatar
con committed
25 26 27 28 29 30
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
con's avatar
con committed
31
**
32
**************************************************************************/
hjk's avatar
hjk committed
33

con's avatar
con committed
34 35 36 37 38 39 40 41
#include "subversionplugin.h"

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

#include "subversionsubmiteditor.h"
#include "subversionconstants.h"
#include "subversioncontrol.h"
42
#include "checkoutwizard.h"
con's avatar
con committed
43 44 45 46

#include <vcsbase/basevcseditorfactory.h>
#include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/basevcssubmiteditorfactory.h>
47
#include <vcsbase/vcsbaseoutputwindow.h>
con's avatar
con committed
48
#include <utils/synchronousprocess.h>
49
#include <utils/parameteraction.h>
con's avatar
con committed
50 51 52 53 54 55

#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/filemanager.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/mimedatabase.h>
56
#include <coreplugin/actionmanager/actionmanager.h>
57 58
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
59
#include <coreplugin/uniqueidmanager.h>
con's avatar
con committed
60
#include <coreplugin/editormanager/editormanager.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
61 62 63

#include <locator/commandlocator.h>

hjk's avatar
hjk committed
64
#include <utils/qtcassert.h>
con's avatar
con committed
65 66

#include <QtCore/QDebug>
67
#include <QtCore/QDir>
con's avatar
con committed
68 69
#include <QtCore/QFileInfo>
#include <QtCore/QTemporaryFile>
70 71
#include <QtCore/QTextCodec>
#include <QtCore/QtPlugin>
72
#include <QtCore/QProcessEnvironment>
73
#include <QtCore/QUrl>
con's avatar
con committed
74
#include <QtGui/QAction>
75 76
#include <QtGui/QFileDialog>
#include <QtGui/QMainWindow>
con's avatar
con committed
77 78
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
79
#include <QtGui/QInputDialog>
80
#include <QtXml/QXmlStreamReader>
81
#include <limits.h>
con's avatar
con committed
82 83 84

using namespace Subversion::Internal;

85 86 87 88 89 90 91 92 93
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";
94
static const char * const CMD_ID_REVERT_ALL         = "Subversion.RevertAll";
95 96 97 98 99
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";
100
static const char * const CMD_ID_SEPARATOR4         = "Subversion.Separator4";
101
static const char * const CMD_ID_STATUS             = "Subversion.Status";
102 103
static const char * const CMD_ID_PROJECTLOG         = "Subversion.ProjectLog";
static const char * const CMD_ID_REPOSITORYLOG      = "Subversion.RepositoryLog";
104 105 106
static const char * const CMD_ID_REPOSITORYUPDATE   = "Subversion.RepositoryUpdate";
static const char * const CMD_ID_REPOSITORYDIFF     = "Subversion.RepositoryDiff";
static const char * const CMD_ID_REPOSITORYSTATUS   = "Subversion.RepositoryStatus";
107
static const char * const CMD_ID_UPDATE             = "Subversion.Update";
108
static const char * const CMD_ID_COMMIT_PROJECT     = "Subversion.CommitProject";
109
static const char * const CMD_ID_DESCRIBE           = "Subversion.Describe";
con's avatar
con committed
110

111 112
static const char *nonInteractiveOptionC = "--non-interactive";

113 114


con's avatar
con committed
115 116 117
static const VCSBase::VCSBaseEditorParameters editorParameters[] = {
{
    VCSBase::RegularCommandOutput,
118 119
    "Subversion Command Log Editor", // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Command Log Editor"), // display name
120
    "Subversion Command Log Editor", // context
con's avatar
con committed
121 122 123
    "application/vnd.nokia.text.scs_svn_commandlog",
    "scslog"},
{   VCSBase::LogOutput,
124 125
    "Subversion File Log Editor",   // id
    QT_TRANSLATE_NOOP("VCS", "Subversion File Log Editor"),   // display_name
126
    "Subversion File Log Editor",   // context
con's avatar
con committed
127 128 129
    "application/vnd.nokia.text.scs_svn_filelog",
    "scsfilelog"},
{    VCSBase::AnnotateOutput,
130 131
    "Subversion Annotation Editor",  // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Annotation Editor"),   // display_name
132
    "Subversion Annotation Editor",  // context
con's avatar
con committed
133 134 135
    "application/vnd.nokia.text.scs_svn_annotation",
    "scsannotate"},
{   VCSBase::DiffOutput,
136 137
    "Subversion Diff Editor",  // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Diff Editor"),   // display_name
138
    "Subversion Diff Editor",  // context
con's avatar
con committed
139 140 141 142 143 144 145
    "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);
146
    return  VCSBase::VCSBaseEditorWidget::findType(editorParameters, sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters), et);
con's avatar
con committed
147 148 149 150 151 152 153
}

static inline QString debugCodec(const QTextCodec *c)
{
    return c ? QString::fromAscii(c->name()) : QString::fromAscii("Null codec");
}

hjk's avatar
hjk committed
154
Core::IEditor* locateEditor(const char *property, const QString &entry)
con's avatar
con committed
155
{
156
    foreach (Core::IEditor *ed, Core::EditorManager::instance()->openedEditors())
con's avatar
con committed
157 158 159 160 161
        if (ed->property(property).toString() == entry)
            return ed;
    return 0;
}

162 163 164 165 166 167 168 169 170 171 172 173 174 175
// 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')) {
176 177
                const QString fileName = line.mid(7); // Column 8 starting from svn 1.6
                changeSet.push_back(SubversionSubmitEditor::StatusFilePair(QString(state), fileName.trimmed()));
178 179 180 181 182 183 184
            }

        }
    }
    return changeSet;
}

185 186 187 188 189 190 191 192 193 194 195
// 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
196 197 198 199
// ------------- SubversionPlugin
SubversionPlugin *SubversionPlugin::m_subversionPluginInstance = 0;

SubversionPlugin::SubversionPlugin() :
200
    VCSBase::VCSBasePlugin(QLatin1String(Subversion::Constants::SUBVERSIONCOMMITEDITOR_ID)),
201
    m_svnDirectories(svnDirectories()),
Friedemann Kleint's avatar
Friedemann Kleint committed
202
    m_commandLocator(0),
con's avatar
con committed
203 204 205 206 207
    m_addAction(0),
    m_deleteAction(0),
    m_revertAction(0),
    m_diffProjectAction(0),
    m_diffCurrentAction(0),
208 209
    m_logProjectAction(0),
    m_logRepositoryAction(0),
con's avatar
con committed
210
    m_commitAllAction(0),
211
    m_revertRepositoryAction(0),
212 213 214
    m_diffRepositoryAction(0),
    m_statusRepositoryAction(0),
    m_updateRepositoryAction(0),
con's avatar
con committed
215 216 217
    m_commitCurrentAction(0),
    m_filelogCurrentAction(0),
    m_annotateCurrentAction(0),
218
    m_statusProjectAction(0),
con's avatar
con committed
219
    m_updateProjectAction(0),
220
    m_commitProjectAction(0),
221
    m_describeAction(0),
con's avatar
con committed
222 223 224
    m_submitCurrentLogAction(0),
    m_submitDiffAction(0),
    m_submitUndoAction(0),
225
    m_submitRedoAction(0),
226
    m_menuAction(0),
227
    m_submitActionTriggered(false)
con's avatar
con committed
228 229 230 231 232
{
}

SubversionPlugin::~SubversionPlugin()
{
233
    cleanCommitMessageFile();
con's avatar
con committed
234 235
}

236
void SubversionPlugin::cleanCommitMessageFile()
con's avatar
con committed
237
{
238 239 240
    if (!m_commitMessageFileName.isEmpty()) {
        QFile::remove(m_commitMessageFileName);
        m_commitMessageFileName.clear();
241
        m_commitRepository.clear();
con's avatar
con committed
242 243 244
    }
}

245 246 247 248 249
bool SubversionPlugin::isCommitEditorOpen() const
{
    return !m_commitMessageFileName.isEmpty();
}

con's avatar
con committed
250 251
static const VCSBase::VCSBaseSubmitEditorParameters submitParameters = {
    Subversion::Constants::SUBVERSION_SUBMIT_MIMETYPE,
252 253
    Subversion::Constants::SUBVERSIONCOMMITEDITOR_ID,
    Subversion::Constants::SUBVERSIONCOMMITEDITOR_DISPLAY_NAME,
254
    Subversion::Constants::SUBVERSIONCOMMITEDITOR
con's avatar
con committed
255 256
};

257 258 259
static inline Core::Command *createSeparator(QObject *parent,
                                             Core::ActionManager *ami,
                                             const char*id,
260
                                             const Core::Context &globalcontext)
261 262 263 264 265 266
{
    QAction *tmpaction = new QAction(parent);
    tmpaction->setSeparator(true);
    return ami->registerAction(tmpaction, id, globalcontext);
}

267
bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *errorMessage)
con's avatar
con committed
268 269 270 271 272 273 274 275
{
    typedef VCSBase::VCSSubmitEditorFactory<SubversionSubmitEditor> SubversionSubmitEditorFactory;
    typedef VCSBase::VCSEditorFactory<SubversionEditor> SubversionEditorFactory;
    using namespace Constants;

    using namespace Core::Constants;
    using namespace ExtensionSystem;

276 277
    VCSBase::VCSBasePlugin::initialize(new SubversionControl(this));

con's avatar
con committed
278
    m_subversionPluginInstance = this;
hjk's avatar
hjk committed
279
    Core::ICore *core = Core::ICore::instance();
con's avatar
con committed
280

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

hjk's avatar
hjk committed
284
    if (QSettings *settings = core->settings())
con's avatar
con committed
285 286
        m_settings.fromSettings(settings);

287
    addAutoReleasedObject(new SettingsPage);
con's avatar
con committed
288

289
    addAutoReleasedObject(new SubversionSubmitEditorFactory(&submitParameters));
con's avatar
con committed
290 291 292

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

296 297
    addAutoReleasedObject(new CheckoutWizard);

Friedemann Kleint's avatar
Friedemann Kleint committed
298 299 300 301 302
    const QString description = QLatin1String("Subversion");
    const QString prefix = QLatin1String("svn");
    m_commandLocator = new Locator::CommandLocator(description, prefix, prefix);
    addAutoReleasedObject(m_commandLocator);

con's avatar
con committed
303
    //register actions
hjk's avatar
hjk committed
304
    Core::ActionManager *ami = core->actionManager();
305
    Core::ActionContainer *toolsContainer = ami->actionContainer(M_TOOLS);
con's avatar
con committed
306

307
    Core::ActionContainer *subversionMenu =
hjk's avatar
hjk committed
308
        ami->createMenu(Core::Id(CMD_ID_SUBVERSION_MENU));
con's avatar
con committed
309 310
    subversionMenu->menu()->setTitle(tr("&Subversion"));
    toolsContainer->addMenu(subversionMenu);
311
    m_menuAction = subversionMenu->menu()->menuAction();
312
    Core::Context globalcontext(C_GLOBAL);
con's avatar
con committed
313
    Core::Command *command;
314 315 316 317

    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);
con's avatar
con committed
318
    command->setAttribute(Core::Command::CA_UpdateText);
319 320
    command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+D")));
    connect(m_diffCurrentAction, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
con's avatar
con committed
321
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
322
    m_commandLocator->appendCommand(command);
con's avatar
con committed
323

324 325 326
    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);
con's avatar
con committed
327
    command->setAttribute(Core::Command::CA_UpdateText);
328 329
    connect(m_filelogCurrentAction, SIGNAL(triggered()), this,
        SLOT(filelogCurrentFile()));
con's avatar
con committed
330
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
331
    m_commandLocator->appendCommand(command);
con's avatar
con committed
332

333 334 335
    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);
con's avatar
con committed
336
    command->setAttribute(Core::Command::CA_UpdateText);
337 338
    connect(m_annotateCurrentAction, SIGNAL(triggered()), this,
        SLOT(annotateCurrentFile()));
con's avatar
con committed
339
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
340
    m_commandLocator->appendCommand(command);
con's avatar
con committed
341

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

344 345
    m_addAction = new Utils::ParameterAction(tr("Add"), tr("Add \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_addAction, CMD_ID_ADD,
con's avatar
con committed
346
        globalcontext);
347
    command->setAttribute(Core::Command::CA_UpdateText);
348 349
    command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+A")));
    connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
con's avatar
con committed
350
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
351
    m_commandLocator->appendCommand(command);
con's avatar
con committed
352

353
    m_commitCurrentAction = new Utils::ParameterAction(tr("Commit Current File"), tr("Commit \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
con's avatar
con committed
354
    command = ami->registerAction(m_commitCurrentAction,
355
        CMD_ID_COMMIT_CURRENT, globalcontext);
con's avatar
con committed
356
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
357 358 359
    command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+C")));
    connect(m_commitCurrentAction, SIGNAL(triggered()), this, SLOT(startCommitCurrentFile()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
360
    m_commandLocator->appendCommand(command);
con's avatar
con committed
361

362 363 364
    m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_deleteAction, CMD_ID_DELETE_FILE,
        globalcontext);
con's avatar
con committed
365
    command->setAttribute(Core::Command::CA_UpdateText);
366
    connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
con's avatar
con committed
367
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
368
    m_commandLocator->appendCommand(command);
con's avatar
con committed
369

370 371 372
    m_revertAction = new Utils::ParameterAction(tr("Revert..."), tr("Revert \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_revertAction, CMD_ID_REVERT,
        globalcontext);
con's avatar
con committed
373
    command->setAttribute(Core::Command::CA_UpdateText);
374
    connect(m_revertAction, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
con's avatar
con committed
375
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
376
    m_commandLocator->appendCommand(command);
con's avatar
con committed
377

378
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR1, globalcontext));
379

380 381 382 383 384 385
    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()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
386
    m_commandLocator->appendCommand(command);
con's avatar
con committed
387

388 389
    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
390
        globalcontext);
391 392
    command->setAttribute(Core::Command::CA_UpdateText);
    connect(m_statusProjectAction, SIGNAL(triggered()), this, SLOT(projectStatus()));
con's avatar
con committed
393
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
394
    m_commandLocator->appendCommand(command);
con's avatar
con committed
395

Friedemann Kleint's avatar
Friedemann Kleint committed
396
    m_logProjectAction = new Utils::ParameterAction(tr("Log Project"), tr("Log Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
397 398 399 400
    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);
Friedemann Kleint's avatar
Friedemann Kleint committed
401
    m_commandLocator->appendCommand(command);
402

403
    m_updateProjectAction = new Utils::ParameterAction(tr("Update Project"), tr("Update Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
404
    command = ami->registerAction(m_updateProjectAction, CMD_ID_UPDATE, globalcontext);
con's avatar
con committed
405
    connect(m_updateProjectAction, SIGNAL(triggered()), this, SLOT(updateProject()));
406
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
407
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
408
    m_commandLocator->appendCommand(command);
con's avatar
con committed
409

410 411 412 413 414 415 416
    m_commitProjectAction = new Utils::ParameterAction(tr("Commit Project"), tr("Commit Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_commitProjectAction, CMD_ID_COMMIT_PROJECT, globalcontext);
    connect(m_commitProjectAction, SIGNAL(triggered()), this, SLOT(startCommitProject()));
    command->setAttribute(Core::Command::CA_UpdateText);
    subversionMenu->addAction(command);
    m_commandLocator->appendCommand(command);

417 418
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR2, globalcontext));

419 420 421 422 423 424 425 426 427 428 429 430 431
    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()));
    subversionMenu->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()));
    subversionMenu->addAction(command);
    m_commandLocator->appendCommand(command);

    m_logRepositoryAction = new QAction(tr("Log Repository"), this);
432 433 434
    command = ami->registerAction(m_logRepositoryAction, CMD_ID_REPOSITORYLOG, globalcontext);
    connect(m_logRepositoryAction, SIGNAL(triggered()), this, SLOT(logRepository()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
435
    m_commandLocator->appendCommand(command);
436

437 438 439
    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()));
440
    subversionMenu->addAction(command);
441
    m_commandLocator->appendCommand(command);
442 443 444 445 446 447

    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()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
448
    m_commandLocator->appendCommand(command);
449

450 451 452 453 454
    m_describeAction = new QAction(tr("Describe..."), this);
    command = ami->registerAction(m_describeAction, CMD_ID_DESCRIBE, globalcontext);
    connect(m_describeAction, SIGNAL(triggered()), this, SLOT(slotDescribe()));
    subversionMenu->addAction(command);

455 456 457 458 459
    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()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
460
    m_commandLocator->appendCommand(command);
461

con's avatar
con committed
462
    // Actions of the submit editor
463
    Core::Context svncommitcontext(Constants::SUBVERSIONCOMMITEDITOR);
con's avatar
con committed
464

465
    m_submitCurrentLogAction = new QAction(VCSBase::VCSBaseSubmitEditor::submitIcon(), tr("Commit"), this);
con's avatar
con committed
466
    command = ami->registerAction(m_submitCurrentLogAction, Constants::SUBMIT_CURRENT, svncommitcontext);
467
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
468 469
    connect(m_submitCurrentLogAction, SIGNAL(triggered()), this, SLOT(submitCurrentLog()));

470
    m_submitDiffAction = new QAction(VCSBase::VCSBaseSubmitEditor::diffIcon(), tr("Diff Selected Files"), this);
con's avatar
con committed
471 472 473 474 475 476 477 478 479 480 481
    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;
}

482
bool SubversionPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEditor)
con's avatar
con committed
483
{
484
    if (!isCommitEditorOpen())
con's avatar
con committed
485 486
        return true;

487 488
    Core::IFile *fileIFace = submitEditor->file();
    const SubversionSubmitEditor *editor = qobject_cast<SubversionSubmitEditor *>(submitEditor);
con's avatar
con committed
489 490 491 492 493 494
    if (!fileIFace || !editor)
        return true;

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

499 500
    // Prompt user. Force a prompt unless submit was actually invoked (that
    // is, the editor was closed or shutdown).
501
    SubversionSettings newSettings = m_settings;
502 503 504
    const VCSBase::VCSBaseSubmitEditor::PromptSubmitResult answer =
            editor->promptSubmit(tr("Closing Subversion Editor"),
                                 tr("Do you want to commit the change?"),
505
                                 tr("The commit message check failed. Do you want to commit the change?"),
506
                                 &newSettings.promptToSubmit, !m_submitActionTriggered);
507
    m_submitActionTriggered = false;
con's avatar
con committed
508
    switch (answer) {
509
    case VCSBase::VCSBaseSubmitEditor::SubmitCanceled:
con's avatar
con committed
510
        return false; // Keep editing and change file
511
    case VCSBase::VCSBaseSubmitEditor::SubmitDiscarded:
512
        cleanCommitMessageFile();
con's avatar
con committed
513 514 515 516
        return true; // Cancel all
    default:
        break;
    }
517
    setSettings(newSettings); // in case someone turned prompting off
con's avatar
con committed
518
    const QStringList fileList = editor->checkedFiles();
519
    bool closeEditor = true;
con's avatar
con committed
520 521
    if (!fileList.empty()) {
        // get message & commit
hjk's avatar
hjk committed
522
        Core::ICore::instance()->fileManager()->blockFileChange(fileIFace);
con's avatar
con committed
523
        fileIFace->save();
hjk's avatar
hjk committed
524
        Core::ICore::instance()->fileManager()->unblockFileChange(fileIFace);
525
        closeEditor= commit(m_commitMessageFileName, fileList);
con's avatar
con committed
526
    }
527
    if (closeEditor)
528
        cleanCommitMessageFile();
529
    return closeEditor;
con's avatar
con committed
530 531
}

532
void SubversionPlugin::diffCommitFiles(const QStringList &files)
con's avatar
con committed
533
{
534
    svnDiff(m_commitRepository, files);
con's avatar
con committed
535 536
}

537 538
static inline void setDiffBaseDirectory(Core::IEditor *editor, const QString &db)
{
539
    if (VCSBase::VCSBaseEditorWidget *ve = qobject_cast<VCSBase::VCSBaseEditorWidget*>(editor->widget()))
540 541 542
        ve->setDiffBaseDirectory(db);
}

543
void SubversionPlugin::svnDiff(const QString &workingDir, const QStringList &files, QString diffname)
con's avatar
con committed
544 545 546
{
    if (Subversion::Constants::debug)
        qDebug() << Q_FUNC_INFO << files << diffname;
547 548
    const QString source = VCSBase::VCSBaseEditorWidget::getSource(workingDir, files);
    QTextCodec *codec = source.isEmpty() ? static_cast<QTextCodec *>(0) : VCSBase::VCSBaseEditorWidget::getCodec(source);
con's avatar
con committed
549 550 551 552 553 554 555

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

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

556
    const SubversionResponse response =
557
            runSvn(workingDir, args, m_settings.timeOutMS(), 0, codec);
con's avatar
con committed
558 559 560 561 562 563 564
    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
565
        if (Core::IEditor *editor = locateEditor("originalFileName", files.front())) {
con's avatar
con committed
566
            editor->createNew(response.stdOut);
567
            Core::EditorManager::instance()->activateEditor(editor, Core::EditorManager::ModeSwitch);
568
            setDiffBaseDirectory(editor, workingDir);
con's avatar
con committed
569 570 571
            return;
        }
    }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
572
    const QString title = QString::fromLatin1("svn diff %1").arg(diffname);
con's avatar
con committed
573
    Core::IEditor *editor = showOutputInEditor(title, response.stdOut, VCSBase::DiffOutput, source, codec);
574
    setDiffBaseDirectory(editor, workingDir);
con's avatar
con committed
575 576 577 578 579 580
    if (files.count() == 1)
        editor->setProperty("originalFileName", files.front());
}

SubversionSubmitEditor *SubversionPlugin::openSubversionSubmitEditor(const QString &fileName)
{
581 582 583
    Core::IEditor *editor = Core::EditorManager::instance()->openEditor(fileName,
                                                                        QLatin1String(Constants::SUBVERSIONCOMMITEDITOR_ID),
                                                                        Core::EditorManager::ModeSwitch);
con's avatar
con committed
584
    SubversionSubmitEditor *submitEditor = qobject_cast<SubversionSubmitEditor*>(editor);
hjk's avatar
hjk committed
585
    QTC_ASSERT(submitEditor, /**/);
586
    submitEditor->registerActions(m_submitUndoAction, m_submitRedoAction, m_submitCurrentLogAction, m_submitDiffAction);
587
    connect(submitEditor, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(diffCommitFiles(QStringList)));
588
    submitEditor->setCheckScriptWorkingDirectory(m_commitRepository);
con's avatar
con committed
589 590 591
    return submitEditor;
}

592
void SubversionPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
con's avatar
con committed
593
{
Friedemann Kleint's avatar
Friedemann Kleint committed
594 595
    if (!enableMenuAction(as, m_menuAction)) {
        m_commandLocator->setEnabled(false);
596
        return;
Friedemann Kleint's avatar
Friedemann Kleint committed
597 598 599 600
    }
    const bool hasTopLevel = currentState().hasTopLevel();
    m_commandLocator->setEnabled(hasTopLevel);
    m_logRepositoryAction->setEnabled(hasTopLevel);
601

602 603 604 605
    const QString projectName = currentState().currentProjectName();
    m_diffProjectAction->setParameter(projectName);
    m_statusProjectAction->setParameter(projectName);
    m_updateProjectAction->setParameter(projectName);
606
    m_logProjectAction->setParameter(projectName);
607
    m_commitProjectAction->setParameter(projectName);
608 609 610 611

    const bool repoEnabled = currentState().hasTopLevel();
    m_commitAllAction->setEnabled(repoEnabled);
    m_describeAction->setEnabled(repoEnabled);
612
    m_revertRepositoryAction->setEnabled(repoEnabled);
613 614 615
    m_diffRepositoryAction->setEnabled(repoEnabled);
    m_statusRepositoryAction->setEnabled(repoEnabled);
    m_updateRepositoryAction->setEnabled(repoEnabled);
616 617 618 619 620 621 622 623 624 625

    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
626 627 628 629
}

void SubversionPlugin::addCurrentFile()
{
630 631 632
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    vcsAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
633 634
}

635 636 637 638 639
void SubversionPlugin::revertAll()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return)
    const QString title = tr("Revert repository");
Tobias Hunger's avatar
Tobias Hunger committed
640
    if (QMessageBox::warning(0, title, tr("Revert all pending changes to the repository?"),
641 642 643 644 645
                             QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
        return;
    // NoteL: Svn "revert ." doesn not work.
    QStringList args;
    args << QLatin1String("revert") << QLatin1String("--recursive") << state.topLevel();
646 647 648
    const SubversionResponse revertResponse =
            runSvn(state.topLevel(), args, m_settings.timeOutMS(),
                   SshPasswordPrompt|ShowStdOutInLogWindow);
649 650 651 652 653 654 655
    if (revertResponse.error) {
        QMessageBox::warning(0, title, tr("Revert failed: %1").arg(revertResponse.message), QMessageBox::Ok);
    } else {
        subVersionControl()->emitRepositoryChanged(state.topLevel());
    }
}

con's avatar
con committed
656 657
void SubversionPlugin::revertCurrentFile()
{
658 659
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
con's avatar
con committed
660 661

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

664 665
    const SubversionResponse diffResponse =
            runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMS(), 0);
con's avatar
con committed
666 667 668 669 670
    if (diffResponse.error)
        return;

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

675

676
    Core::FileChangeBlocker fcb(state.currentFile());
con's avatar
con committed
677 678 679

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

682 683 684 685
    const SubversionResponse revertResponse =
            runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMS(),
                   SshPasswordPrompt|ShowStdOutInLogWindow);

686
    if (!revertResponse.error) {
687
        subVersionControl()->emitFilesChanged(QStringList(state.currentFile()));
con's avatar
con committed
688 689 690 691 692
    }
}

void SubversionPlugin::diffProject()
{
693 694 695
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)
    svnDiff(state.currentProjectTopLevel(), state.relativeCurrentProject(), state.currentProjectName());
con's avatar
con committed
696 697 698 699
}

void SubversionPlugin::diffCurrentFile()
{
700 701 702
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    svnDiff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
con's avatar
con committed
703 704 705 706
}

void SubversionPlugin::startCommitCurrentFile()
{
707 708 709
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    startCommit(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
con's avatar
con committed
710 711 712 713
}

void SubversionPlugin::startCommitAll()
{
714 715 716
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return);
    startCommit(state.topLevel());
con's avatar
con committed
717 718
}

719 720 721 722 723 724 725
void SubversionPlugin::startCommitProject()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return);
    startCommit(state.currentProjectPath());
}

con's avatar
con committed
726 727 728
/* Start commit of files of a single repository by displaying
 * template and files in a submit editor. On closing, the real
 * commit will start. */
729
void SubversionPlugin::startCommit(const QString &workingDir, const QStringList &files)
con's avatar
con committed
730
{
731 732
    if (VCSBase::VCSBaseSubmitEditor::raiseSubmitEditor())
        return;
733
    if (isCommitEditorOpen()) {
734
        VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("Another commit is currently being executed."));
con's avatar
con committed
735 736 737 738 739 740
        return;
    }

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

741 742
    const SubversionResponse response =
            runSvn(workingDir, args, m_settings.timeOutMS(), 0);
con's avatar
con committed
743 744
    if (response.error)
        return;
745

con's avatar
con committed
746
    // Get list of added/modified/deleted files
747
    const StatusList statusOutput = parseStatusOutput(response.stdOut);
con's avatar
con committed
748
    if (statusOutput.empty()) {
749
        VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("There are no modified files."));
con's avatar
con committed
750 751
        return;
    }
752
    m_commitRepository = workingDir;
con's avatar
con committed
753
    // Create a new submit change file containing the submit template
754 755 756 757
    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
758 759
        return;
    }
760
    m_commitMessageFileName = changeTmpFile.fileName();
761
    // TODO: Regitctrieve submit template from
con's avatar
con committed
762 763
    const QString submitTemplate;
    // Create a submit
764 765 766
    changeTmpFile.write(submitTemplate.toUtf8());
    changeTmpFile.flush();
    changeTmpFile.close();
con's avatar
con committed
767
    // Create a submit editor and set file list
768
    SubversionSubmitEditor *editor = openSubversionSubmitEditor(m_commitMessageFileName);
769
    editor->setStatusList(statusOutput);
con's avatar
con committed
770 771 772 773 774 775 776 777 778 779 780
}

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"));
781
    args << QLatin1String(nonInteractiveOptionC) << QLatin1String("--file") << messageFile;
con's avatar
con committed
782
    args.append(subVersionFileList);
783 784 785
    const SubversionResponse response =
            runSvn(m_commitRepository, args, m_settings.longTimeOutMS(),
                   SshPasswordPrompt|ShowStdOutInLogWindow);
con's avatar
con committed
786 787 788 789 790
    return !response.error ;
}

void SubversionPlugin::filelogCurrentFile()
{
791 792
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
   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
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
void SubversionPlugin::diffRepository()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return)
    svnDiff(state.topLevel(), QStringList());
}

void SubversionPlugin::statusRepository()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return)
    svnStatus(state.topLevel());
}

void SubversionPlugin::updateRepository()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return)
    svnUpdate(state.topLevel());
}

void SubversionPlugin::svnStatus(const QString &workingDir, const QStringList &relativePaths)
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return)
    QStringList args(QLatin1String("status"));
    if (!relativePaths.isEmpty())
        args.append(relativePaths);
    VCSBase::VCSBaseOutputWindow *outwin = VCSBase::VCSBaseOutputWindow::instance();
    outwin->setRepository(workingDir);
840
    runSvn(workingDir, args, m_settings.timeOutMS(),
841
           ShowStdOutInLogWindow|ShowSuccessMessage);
842 843 844
    outwin->clearRepository();
}

845 846 847
void SubversionPlugin::filelog(const QString &workingDir,
                               const QStringList &files,
                               bool enableAnnotationContextMenu)
con's avatar
con committed
848 849 850
{
    // no need for temp file
    QStringList args(QLatin1String("log"));
851 852
    if (m_settings.logCount > 0)
        args << QLatin1String("-l") << QString::number(m_settings.logCount);
853 854
    foreach(const QString &file, files)
        args.append(QDir::toNativeSeparators(file));
con's avatar
con committed
855

Roman Kovalev's avatar
Roman Kovalev committed
856 857
    // subversion stores log in UTF-8 and returns it back in user system locale.
    // So we do not need to encode it.
858 859
    const SubversionResponse response =
            runSvn(workingDir, args, m_settings.timeOutMS(),
Roman Kovalev's avatar
Roman Kovalev committed
860
                   SshPasswordPrompt, 0/*codec*/);
con's avatar
con committed
861 862 863 864 865 866
    if (response.error)
        return;

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

867
    const QString id = VCSBase::VCSBaseEditorWidget::getTitleId(workingDir, files);
868
    if (Core::IEditor *editor = locateEditor("logFileName", id)) {
con's avatar
con committed
869
        editor->createNew(response.stdOut);
870
        Core::EditorManager::instance()->activateEditor(editor, Core::EditorManager::ModeSwitch);
con's avatar
con committed
871
    } else {
872
        const QString title = QString::fromLatin1("svn log %1").arg(id);
873
        const QString source = VCSBase::VCSBaseEditorWidget::getSource(workingDir, files);
Roman Kovalev's avatar
Roman Kovalev committed
874
        Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::LogOutput, source, /*codec*/0);
875
        newEditor->setProperty("logFileName", id);
876
        if (enableAnnotationContextMenu)
877
            VCSBase::VCSBaseEditorWidget::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true);
con's avatar
con committed
878 879 880 881 882
    }
}

void SubversionPlugin::updateProject()
{
883 884
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return);
885 886
    svnUpdate(state.currentProjectTopLevel(), state.relativeCurrentProject());
}
con's avatar
con committed
887

888 889
void SubversionPlugin::svnUpdate(const QString &workingDir, const QStringList &relativePaths)
{
con's avatar
con committed
890
    QStringList args(QLatin1String("update"));
891
    args.push_back(QLatin1String(nonInteractiveOptionC));
892 893
    if (!relativePaths.isEmpty())
        args.append(relativePaths);
894 895 896
        const SubversionResponse response =
                runSvn(workingDir, args, m_settings.longTimeOutMS(),
                       SshPasswordPrompt|ShowStdOutInLogWindow);
897
    if (!response.error)
898
        subVersionControl()->emitRepositoryChanged(workingDir);
con's avatar
con committed
899 900 901 902
}

void SubversionPlugin::annotateCurrentFile()
{
903 904
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return);
905
    vcsAnnotate(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
906 907
}

908 909 910 911 912
void SubversionPlugin::annotateVersion(const QString &file,
                                       const QString &revision,
                                       int lineNr)
{
    const QFileInfo fi(file);
913
    vcsAnnotate(fi.absolutePath(), fi.fileName(), revision, lineNr);
914 915
}

916
void SubversionPlugin::vcsAnnotate(const QString &workingDir, const QString &file,
917 918
                                const QString &revision /* = QString() */,
                                int lineNumber /* = -1 */)
con's avatar
con committed
919
{
920 921
    const QString source = VCSBase::VCSBaseEditorWidget::getSource(workingDir, file);
    QTextCodec *codec = VCSBase::VCSBaseEditorWidget::getCodec(source);
con's avatar
con committed
922 923

    QStringList args(QLatin1String("annotate"));
924 925
    if (m_settings.spaceIgnorantAnnotation)
        args << QLatin1String("-x") << QLatin1String("-uw");