subversionplugin.cpp 52 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 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>
54 55
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
con's avatar
con committed
56
#include <coreplugin/editormanager/editormanager.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
57 58 59

#include <locator/commandlocator.h>

hjk's avatar
hjk committed
60
#include <utils/qtcassert.h>
con's avatar
con committed
61 62

#include <QtCore/QDebug>
63
#include <QtCore/QDir>
con's avatar
con committed
64 65
#include <QtCore/QFileInfo>
#include <QtCore/QTemporaryFile>
66 67
#include <QtCore/QTextCodec>
#include <QtCore/QtPlugin>
68
#include <QtCore/QProcessEnvironment>
con's avatar
con committed
69
#include <QtGui/QAction>
70 71
#include <QtGui/QFileDialog>
#include <QtGui/QMainWindow>
con's avatar
con committed
72 73
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
74 75 76
#include <QtGui/QInputDialog>

#include <limits.h>
con's avatar
con committed
77 78 79

using namespace Subversion::Internal;

80 81 82 83 84 85 86 87 88
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";
89
static const char * const CMD_ID_REVERT_ALL         = "Subversion.RevertAll";
90 91 92 93 94
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";
95
static const char * const CMD_ID_SEPARATOR4         = "Subversion.Separator4";
96
static const char * const CMD_ID_STATUS             = "Subversion.Status";
97 98
static const char * const CMD_ID_PROJECTLOG         = "Subversion.ProjectLog";
static const char * const CMD_ID_REPOSITORYLOG      = "Subversion.RepositoryLog";
99 100 101
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";
102
static const char * const CMD_ID_UPDATE             = "Subversion.Update";
103
static const char * const CMD_ID_COMMIT_PROJECT     = "Subversion.CommitProject";
104
static const char * const CMD_ID_DESCRIBE           = "Subversion.Describe";
con's avatar
con committed
105

106 107
static const char *nonInteractiveOptionC = "--non-interactive";

con's avatar
con committed
108 109 110
static const VCSBase::VCSBaseEditorParameters editorParameters[] = {
{
    VCSBase::RegularCommandOutput,
111 112
    "Subversion Command Log Editor", // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Command Log Editor"), // display name
113
    "Subversion Command Log Editor", // context
con's avatar
con committed
114 115 116
    "application/vnd.nokia.text.scs_svn_commandlog",
    "scslog"},
{   VCSBase::LogOutput,
117 118
    "Subversion File Log Editor",   // id
    QT_TRANSLATE_NOOP("VCS", "Subversion File Log Editor"),   // display_name
119
    "Subversion File Log Editor",   // context
con's avatar
con committed
120 121 122
    "application/vnd.nokia.text.scs_svn_filelog",
    "scsfilelog"},
{    VCSBase::AnnotateOutput,
123 124
    "Subversion Annotation Editor",  // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Annotation Editor"),   // display_name
125
    "Subversion Annotation Editor",  // context
con's avatar
con committed
126 127 128
    "application/vnd.nokia.text.scs_svn_annotation",
    "scsannotate"},
{   VCSBase::DiffOutput,
129 130
    "Subversion Diff Editor",  // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Diff Editor"),   // display_name
131
    "Subversion Diff Editor",  // context
con's avatar
con committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    "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
147
Core::IEditor* locateEditor(const char *property, const QString &entry)
con's avatar
con committed
148
{
149
    foreach (Core::IEditor *ed, Core::EditorManager::instance()->openedEditors())
con's avatar
con committed
150 151 152 153 154
        if (ed->property(property).toString() == entry)
            return ed;
    return 0;
}

155 156 157 158 159 160 161 162 163 164 165 166 167 168
// 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')) {
169 170
                const QString fileName = line.mid(7); // Column 8 starting from svn 1.6
                changeSet.push_back(SubversionSubmitEditor::StatusFilePair(QString(state), fileName.trimmed()));
171 172 173 174 175 176 177
            }

        }
    }
    return changeSet;
}

178 179 180 181 182 183 184 185 186 187 188
// 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
189 190 191 192
// ------------- SubversionPlugin
SubversionPlugin *SubversionPlugin::m_subversionPluginInstance = 0;

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

SubversionPlugin::~SubversionPlugin()
{
226
    cleanCommitMessageFile();
con's avatar
con committed
227 228
}

229
void SubversionPlugin::cleanCommitMessageFile()
con's avatar
con committed
230
{
231 232 233
    if (!m_commitMessageFileName.isEmpty()) {
        QFile::remove(m_commitMessageFileName);
        m_commitMessageFileName.clear();
234
        m_commitRepository.clear();
con's avatar
con committed
235 236 237
    }
}

238 239 240 241 242
bool SubversionPlugin::isCommitEditorOpen() const
{
    return !m_commitMessageFileName.isEmpty();
}

con's avatar
con committed
243 244
static const VCSBase::VCSBaseSubmitEditorParameters submitParameters = {
    Subversion::Constants::SUBVERSION_SUBMIT_MIMETYPE,
245 246
    Subversion::Constants::SUBVERSIONCOMMITEDITOR_ID,
    Subversion::Constants::SUBVERSIONCOMMITEDITOR_DISPLAY_NAME,
247
    Subversion::Constants::SUBVERSIONCOMMITEDITOR
con's avatar
con committed
248 249
};

250 251 252 253 254 255 256 257 258 259
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);
}

260
bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *errorMessage)
con's avatar
con committed
261 262 263 264 265 266 267 268
{
    typedef VCSBase::VCSSubmitEditorFactory<SubversionSubmitEditor> SubversionSubmitEditorFactory;
    typedef VCSBase::VCSEditorFactory<SubversionEditor> SubversionEditorFactory;
    using namespace Constants;

    using namespace Core::Constants;
    using namespace ExtensionSystem;

269 270
    VCSBase::VCSBasePlugin::initialize(new SubversionControl(this));

con's avatar
con committed
271
    m_subversionPluginInstance = this;
hjk's avatar
hjk committed
272
    Core::ICore *core = Core::ICore::instance();
con's avatar
con committed
273

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

hjk's avatar
hjk committed
277
    if (QSettings *settings = core->settings())
con's avatar
con committed
278 279
        m_settings.fromSettings(settings);

280
    addAutoReleasedObject(new SettingsPage);
con's avatar
con committed
281

282
    addAutoReleasedObject(new SubversionSubmitEditorFactory(&submitParameters));
con's avatar
con committed
283 284 285

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

289 290
    addAutoReleasedObject(new CheckoutWizard);

Friedemann Kleint's avatar
Friedemann Kleint committed
291 292 293 294 295
    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
296
    //register actions
hjk's avatar
hjk committed
297
    Core::ActionManager *ami = core->actionManager();
298
    Core::ActionContainer *toolsContainer = ami->actionContainer(M_TOOLS);
con's avatar
con committed
299

300
    Core::ActionContainer *subversionMenu =
301
        ami->createMenu(QLatin1String(CMD_ID_SUBVERSION_MENU));
con's avatar
con committed
302 303
    subversionMenu->menu()->setTitle(tr("&Subversion"));
    toolsContainer->addMenu(subversionMenu);
304
    m_menuAction = subversionMenu->menu()->menuAction();
con's avatar
con committed
305
    QList<int> globalcontext;
hjk's avatar
hjk committed
306
    globalcontext << core->uniqueIDManager()->uniqueIdentifier(C_GLOBAL);
con's avatar
con committed
307

con's avatar
con committed
308
    Core::Command *command;
309 310 311 312

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

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

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

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

339 340
    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
341
        globalcontext);
342
    command->setAttribute(Core::Command::CA_UpdateText);
343 344
    command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+A")));
    connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
con's avatar
con committed
345
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
346
    m_commandLocator->appendCommand(command);
con's avatar
con committed
347

348
    m_commitCurrentAction = new Utils::ParameterAction(tr("Commit Current File"), tr("Commit \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
con's avatar
con committed
349
    command = ami->registerAction(m_commitCurrentAction,
350
        CMD_ID_COMMIT_CURRENT, globalcontext);
con's avatar
con committed
351
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
352 353 354
    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
355
    m_commandLocator->appendCommand(command);
con's avatar
con committed
356

357 358 359
    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
360
    command->setAttribute(Core::Command::CA_UpdateText);
361
    connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
con's avatar
con committed
362
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
363
    m_commandLocator->appendCommand(command);
con's avatar
con committed
364

365 366 367
    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
368
    command->setAttribute(Core::Command::CA_UpdateText);
369
    connect(m_revertAction, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
con's avatar
con committed
370
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
371
    m_commandLocator->appendCommand(command);
con's avatar
con committed
372

373
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR1, globalcontext));
374

375 376 377 378 379 380
    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
381
    m_commandLocator->appendCommand(command);
con's avatar
con committed
382

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

Friedemann Kleint's avatar
Friedemann Kleint committed
391
    m_logProjectAction = new Utils::ParameterAction(tr("Log Project"), tr("Log Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
392 393 394 395
    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
396
    m_commandLocator->appendCommand(command);
397

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

405 406 407 408 409 410 411
    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);

412 413
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR2, globalcontext));

414 415 416 417 418 419 420 421 422 423 424 425 426
    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);
427 428 429
    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
430
    m_commandLocator->appendCommand(command);
431

432 433 434
    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()));
435
    subversionMenu->addAction(command);
436
    m_commandLocator->appendCommand(command);
437 438 439 440 441 442

    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
443
    m_commandLocator->appendCommand(command);
444

445 446 447 448 449
    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);

450 451 452 453 454
    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
455
    m_commandLocator->appendCommand(command);
456

con's avatar
con committed
457 458
    // Actions of the submit editor
    QList<int> svncommitcontext;
459
    svncommitcontext << Core::UniqueIDManager::instance()->uniqueIdentifier(Constants::SUBVERSIONCOMMITEDITOR);
con's avatar
con committed
460

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

465
    m_submitDiffAction = new QAction(VCSBase::VCSBaseSubmitEditor::diffIcon(), tr("Diff Selected Files"), this);
con's avatar
con committed
466 467 468 469 470 471 472 473 474 475 476
    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;
}

477
bool SubversionPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEditor)
con's avatar
con committed
478
{
479
    if (!isCommitEditorOpen())
con's avatar
con committed
480 481
        return true;

482 483
    Core::IFile *fileIFace = submitEditor->file();
    const SubversionSubmitEditor *editor = qobject_cast<SubversionSubmitEditor *>(submitEditor);
con's avatar
con committed
484 485 486 487 488 489
    if (!fileIFace || !editor)
        return true;

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

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

527
void SubversionPlugin::diffCommitFiles(const QStringList &files)
con's avatar
con committed
528
{
529
    svnDiff(m_commitRepository, files);
con's avatar
con committed
530 531
}

532 533 534 535 536 537
static inline void setDiffBaseDirectory(Core::IEditor *editor, const QString &db)
{
    if (VCSBase::VCSBaseEditor *ve = qobject_cast<VCSBase::VCSBaseEditor*>(editor->widget()))
        ve->setDiffBaseDirectory(db);
}

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

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

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

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

SubversionSubmitEditor *SubversionPlugin::openSubversionSubmitEditor(const QString &fileName)
{
575
    Core::IEditor *editor = Core::EditorManager::instance()->openEditor(fileName, QLatin1String(Constants::SUBVERSIONCOMMITEDITOR_ID));
con's avatar
con committed
576
    SubversionSubmitEditor *submitEditor = qobject_cast<SubversionSubmitEditor*>(editor);
hjk's avatar
hjk committed
577
    QTC_ASSERT(submitEditor, /**/);
578
    submitEditor->registerActions(m_submitUndoAction, m_submitRedoAction, m_submitCurrentLogAction, m_submitDiffAction);
579
    connect(submitEditor, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(diffCommitFiles(QStringList)));
580
    submitEditor->setCheckScriptWorkingDirectory(m_commitRepository);
con's avatar
con committed
581 582 583
    return submitEditor;
}

584
void SubversionPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
con's avatar
con committed
585
{
Friedemann Kleint's avatar
Friedemann Kleint committed
586 587
    if (!enableMenuAction(as, m_menuAction)) {
        m_commandLocator->setEnabled(false);
588
        return;
Friedemann Kleint's avatar
Friedemann Kleint committed
589 590 591 592
    }
    const bool hasTopLevel = currentState().hasTopLevel();
    m_commandLocator->setEnabled(hasTopLevel);
    m_logRepositoryAction->setEnabled(hasTopLevel);
593

594 595 596 597
    const QString projectName = currentState().currentProjectName();
    m_diffProjectAction->setParameter(projectName);
    m_statusProjectAction->setParameter(projectName);
    m_updateProjectAction->setParameter(projectName);
598
    m_logProjectAction->setParameter(projectName);
599
    m_commitProjectAction->setParameter(projectName);
600 601 602 603

    const bool repoEnabled = currentState().hasTopLevel();
    m_commitAllAction->setEnabled(repoEnabled);
    m_describeAction->setEnabled(repoEnabled);
604
    m_revertRepositoryAction->setEnabled(repoEnabled);
605 606 607
    m_diffRepositoryAction->setEnabled(repoEnabled);
    m_statusRepositoryAction->setEnabled(repoEnabled);
    m_updateRepositoryAction->setEnabled(repoEnabled);
608 609 610 611 612 613 614 615 616 617

    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
618 619 620 621
}

void SubversionPlugin::addCurrentFile()
{
622 623 624
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    vcsAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
625 626
}

627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
void SubversionPlugin::revertAll()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return)
    const QString title = tr("Revert repository");
    if (QMessageBox::warning(0, title, tr("Would you like to revert all changes to the repository?"),
                             QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
        return;
    // NoteL: Svn "revert ." doesn not work.
    QStringList args;
    args << QLatin1String("revert") << QLatin1String("--recursive") << state.topLevel();
    const SubversionResponse revertResponse = runSvn(state.topLevel(), args, m_settings.timeOutMS(), true);
    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
646 647
void SubversionPlugin::revertCurrentFile()
{
648 649
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
con's avatar
con committed
650 651

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

654
    const SubversionResponse diffResponse = runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMS(), false);
con's avatar
con committed
655 656 657 658 659
    if (diffResponse.error)
        return;

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

664

665
    Core::FileChangeBlocker fcb(state.currentFile());
con's avatar
con committed
666 667 668

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

671
    const SubversionResponse revertResponse = runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMS(), true);
672
    if (!revertResponse.error) {
673
        subVersionControl()->emitFilesChanged(QStringList(state.currentFile()));
con's avatar
con committed
674 675 676 677 678
    }
}

void SubversionPlugin::diffProject()
{
679 680 681
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)
    svnDiff(state.currentProjectTopLevel(), state.relativeCurrentProject(), state.currentProjectName());
con's avatar
con committed
682 683 684 685
}

void SubversionPlugin::diffCurrentFile()
{
686 687 688
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    svnDiff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
con's avatar
con committed
689 690 691 692
}

void SubversionPlugin::startCommitCurrentFile()
{
693 694 695
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    startCommit(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
con's avatar
con committed
696 697 698 699
}

void SubversionPlugin::startCommitAll()
{
700 701 702
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return);
    startCommit(state.topLevel());
con's avatar
con committed
703 704
}

705 706 707 708 709 710 711
void SubversionPlugin::startCommitProject()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return);
    startCommit(state.currentProjectPath());
}

con's avatar
con committed
712 713 714
/* Start commit of files of a single repository by displaying
 * template and files in a submit editor. On closing, the real
 * commit will start. */
715
void SubversionPlugin::startCommit(const QString &workingDir, const QStringList &files)
con's avatar
con committed
716
{
717 718
    if (VCSBase::VCSBaseSubmitEditor::raiseSubmitEditor())
        return;
719
    if (isCommitEditorOpen()) {
720
        VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("Another commit is currently being executed."));
con's avatar
con committed
721 722 723 724 725 726
        return;
    }

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

727
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false);
con's avatar
con committed
728 729
    if (response.error)
        return;
730

con's avatar
con committed
731
    // Get list of added/modified/deleted files
732
    const StatusList statusOutput = parseStatusOutput(response.stdOut);
con's avatar
con committed
733
    if (statusOutput.empty()) {
734
        VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("There are no modified files."));
con's avatar
con committed
735 736
        return;
    }
737
    m_commitRepository = workingDir;
con's avatar
con committed
738
    // Create a new submit change file containing the submit template
739 740 741 742
    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
743 744
        return;
    }
745
    m_commitMessageFileName = changeTmpFile.fileName();
746
    // TODO: Regitctrieve submit template from
con's avatar
con committed
747 748
    const QString submitTemplate;
    // Create a submit
749 750 751
    changeTmpFile.write(submitTemplate.toUtf8());
    changeTmpFile.flush();
    changeTmpFile.close();
con's avatar
con committed
752
    // Create a submit editor and set file list
753
    SubversionSubmitEditor *editor = openSubversionSubmitEditor(m_commitMessageFileName);
754
    editor->setStatusList(statusOutput);
con's avatar
con committed
755 756 757 758 759 760 761 762 763 764 765
}

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"));
766
    args << QLatin1String(nonInteractiveOptionC) << QLatin1String("--file") << messageFile;
con's avatar
con committed
767
    args.append(subVersionFileList);
768
    const SubversionResponse response = runSvn(m_commitRepository, args, m_settings.longTimeOutMS(), true);
con's avatar
con committed
769 770 771 772 773
    return !response.error ;
}

void SubversionPlugin::filelogCurrentFile()
{
774 775
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
   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
791 792
}

793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
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);
    runSvn(workingDir, args, m_settings.timeOutMS(), true);
    outwin->clearRepository();
}

827 828 829
void SubversionPlugin::filelog(const QString &workingDir,
                               const QStringList &files,
                               bool enableAnnotationContextMenu)
con's avatar
con committed
830
{
831
    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(workingDir, files);
con's avatar
con committed
832 833
    // no need for temp file
    QStringList args(QLatin1String("log"));
834 835
    if (m_settings.logCount > 0)
        args << QLatin1String("-l") << QString::number(m_settings.logCount);
836 837
    foreach(const QString &file, files)
        args.append(QDir::toNativeSeparators(file));
con's avatar
con committed
838

839
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false, codec);
con's avatar
con committed
840 841 842 843 844 845
    if (response.error)
        return;

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

846 847
    const QString id = VCSBase::VCSBaseEditor::getTitleId(workingDir, files);
    if (Core::IEditor *editor = locateEditor("logFileName", id)) {
con's avatar
con committed
848
        editor->createNew(response.stdOut);
849
        Core::EditorManager::instance()->activateEditor(editor);
con's avatar
con committed
850
    } else {
851 852 853 854
        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);
855 856
        if (enableAnnotationContextMenu)
            VCSBase::VCSBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true);
con's avatar
con committed
857 858 859 860 861
    }
}

void SubversionPlugin::updateProject()
{
862 863
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return);
864 865
    svnUpdate(state.currentProjectTopLevel(), state.relativeCurrentProject());
}
con's avatar
con committed
866

867 868
void SubversionPlugin::svnUpdate(const QString &workingDir, const QStringList &relativePaths)
{
con's avatar
con committed
869
    QStringList args(QLatin1String("update"));
870
    args.push_back(QLatin1String(nonInteractiveOptionC));
871 872 873
    if (!relativePaths.isEmpty())
        args.append(relativePaths);
        const SubversionResponse response = runSvn(workingDir, args, m_settings.longTimeOutMS(), true);
874
    if (!response.error)
875
        subVersionControl()->emitRepositoryChanged(workingDir);
con's avatar
con committed
876 877 878 879
}

void SubversionPlugin::annotateCurrentFile()
{
880 881
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return);
882
    vcsAnnotate(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
883 884
}

885 886 887 888 889
void SubversionPlugin::annotateVersion(const QString &file,
                                       const QString &revision,
                                       int lineNr)
{
    const QFileInfo fi(file);
890
    vcsAnnotate(fi.absolutePath(), fi.fileName(), revision, lineNr);
891 892
}

893
void SubversionPlugin::vcsAnnotate(const QString &workingDir, const QString &file,
894 895
                                const QString &revision /* = QString() */,
                                int lineNumber /* = -1 */)
con's avatar
con committed
896
{
897
    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(file);
con's avatar
con committed
898 899

    QStringList args(QLatin1String("annotate"));
900 901
    if (m_settings.spaceIgnorantAnnotation)
        args << QLatin1String("-x") << QLatin1String("-uw");
902 903
    if (!revision.isEmpty())
        args << QLatin1String("-r") << revision;
con's avatar
con committed
904 905 906
    args.push_back(QLatin1String("-v"));
    args.append(QDir::toNativeSeparators(file));

907
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false, codec);
con's avatar
con committed
908 909 910 911 912
    if (response.error)
        return;

    // Re-use an existing view if possible to support
    // the common usage pattern of continuously changing and diffing a file
913
    const QString source = workingDir + QLatin1Char('/') + file;
914 915 916 917
    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
918

919
    if (Core::IEditor *editor = locateEditor("annotateFileName", id)) {
con's avatar
con committed
920
        editor->createNew(response.stdOut);
921
        VCSBase::VCSBaseEditor::gotoLineOfEditor(editor, lineNumber);
922
        Core::EditorManager::instance()->activateEditor(editor);
con's avatar
con committed
923
    } else {
924 925 926
        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);
927
        VCSBase::VCSBaseEditor::gotoLineOfEditor(newEditor, lineNumber);
con's avatar
con committed
928 929 930 931 932
    }
}

void SubversionPlugin::projectStatus()
{
933 934
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return);
935
    svnStatus(state.currentFileTopLevel(), state.relativeCurrentProject());
con's avatar
con committed
936 937 938 939 940 941 942
}

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);
943