vcsbaseclient.cpp 21.3 KB
Newer Older
cerf's avatar
cerf committed
1
2
3
4
5
6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Brian McGillion & Hugues Delorme
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
cerf's avatar
cerf committed
8
9
10
11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** 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.
cerf's avatar
cerf committed
18
19
**
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
cerf's avatar
cerf committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
cerf's avatar
cerf committed
28
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.nokia.com.
cerf's avatar
cerf committed
30
31
32
33
34
35
**
**************************************************************************/

#include "vcsbaseclient.h"
#include "vcsjobrunner.h"
#include "vcsbaseclientsettings.h"
36
#include "vcsbaseeditorparameterwidget.h"
cerf's avatar
cerf committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

#include <QtDebug>

#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>

#include <utils/qtcassert.h>
#include <utils/synchronousprocess.h>
#include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/vcsbaseoutputwindow.h>
#include <vcsbase/vcsbaseplugin.h>

#include <QtCore/QStringList>
#include <QtCore/QSharedPointer>
#include <QtCore/QDir>
#include <QtCore/QProcess>
#include <QtCore/QTextCodec>
#include <QtCore/QtDebug>
#include <QtCore/QFileInfo>
#include <QtCore/QByteArray>
#include <QtCore/QMetaType>

59
60
61
62
63
64
65
66
67
68
/*!
    \class VCSBase::VCSBaseClient

    \brief Base class for Mercurial and Bazaar 'clients'.

    Provides base functionality for common commands (diff, log, etc).

    \sa VCSBase::VCSJobRunner
*/

cerf's avatar
cerf committed
69
70
71
72
73
74
75
76
77
78
79
80
Q_DECLARE_METATYPE(QVariant)

inline Core::IEditor *locateEditor(const Core::ICore *core, const char *property, const QString &entry)
{
    foreach (Core::IEditor *ed, core->editorManager()->openedEditors())
        if (ed->file()->property(property).toString() == entry)
            return ed;
    return 0;
}

namespace VCSBase {

Friedemann Kleint's avatar
Friedemann Kleint committed
81
82
83
class VCSBaseClientPrivate
{
public:
84
85
86
87
88
    VCSBaseClientPrivate(VCSBaseClient *client, VCSBaseClientSettings *settings);

    void statusParser(QByteArray data);
    void annotateRevision(QString source, QString change, int lineNumber);
    void saveSettings();
Friedemann Kleint's avatar
Friedemann Kleint committed
89
90
91

    VCSJobRunner *m_jobManager;
    Core::ICore *m_core;
92
93
94
95
    VCSBaseClientSettings *m_clientSettings;

private:
    VCSBaseClient *m_client;
Friedemann Kleint's avatar
Friedemann Kleint committed
96
97
};

98
99
100
101
102
103
104
VCSBaseClientPrivate::VCSBaseClientPrivate(VCSBaseClient *client, VCSBaseClientSettings *settings) :
    m_jobManager(0), m_core(Core::ICore::instance()), m_clientSettings(settings), m_client(client)
{
}

void VCSBaseClientPrivate::statusParser(QByteArray data)
{
105
    QList<VCSBaseClient::StatusItem> lineInfoList;
106
107
108
109

    QStringList rawStatusList = QTextCodec::codecForLocale()->toUnicode(data).split(QLatin1Char('\n'));

    foreach (const QString &string, rawStatusList) {
110
111
112
        const VCSBaseClient::StatusItem lineInfo = m_client->parseStatusLine(string);
        if (!lineInfo.flags.isEmpty() && !lineInfo.file.isEmpty())
            lineInfoList.append(lineInfo);
113
114
    }

115
    emit m_client->parsedStatus(lineInfoList);
116
117
118
119
120
121
122
123
124
125
126
127
128
129
}

void VCSBaseClientPrivate::annotateRevision(QString source, QString change, int lineNumber)
{
    // This might be invoked with a verbose revision description
    // "SHA1 author subject" from the annotation context menu. Strip the rest.
    const int blankPos = change.indexOf(QLatin1Char(' '));
    if (blankPos != -1)
        change.truncate(blankPos);
    const QFileInfo fi(source);
    m_client->annotate(fi.absolutePath(), fi.fileName(), change, lineNumber);
}

void VCSBaseClientPrivate::saveSettings()
Friedemann Kleint's avatar
Friedemann Kleint committed
130
{
131
    m_clientSettings->writeSettings(m_core->settings());
Friedemann Kleint's avatar
Friedemann Kleint committed
132
133
}

134
135
136
137
138
139
140
141
142
VCSBaseClient::StatusItem::StatusItem()
{
}

VCSBaseClient::StatusItem::StatusItem(const QString &s, const QString &f) :
    flags(s), file(f)
{
}

143
VCSBaseClient::VCSBaseClient(VCSBaseClientSettings *settings) :
144
    d(new VCSBaseClientPrivate(this, settings))
cerf's avatar
cerf committed
145
146
{
    qRegisterMetaType<QVariant>();
147
    connect(d->m_core, SIGNAL(saveSettingsRequested()), this, SLOT(saveSettings()));
cerf's avatar
cerf committed
148
149
150
151
}

VCSBaseClient::~VCSBaseClient()
{
Friedemann Kleint's avatar
Friedemann Kleint committed
152
153
154
    if (d->m_jobManager) {
        delete d->m_jobManager;
        d->m_jobManager = 0;
cerf's avatar
cerf committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
    }
}

bool VCSBaseClient::synchronousCreateRepository(const QString &workingDirectory)
{
    const QStringList args(vcsCommandString(CreateRepositoryCommand));
    QByteArray outputData;
    if (!vcsFullySynchronousExec(workingDirectory, args, &outputData))
        return false;
    QString output = QString::fromLocal8Bit(outputData);
    output.remove(QLatin1Char('\r'));
    VCSBase::VCSBaseOutputWindow::instance()->append(output);
    return true;
}

bool VCSBaseClient::synchronousClone(const QString &workingDir,
                                     const QString &srcLocation,
                                     const QString &dstLocation,
173
                                     const QStringList &extraOptions)
cerf's avatar
cerf committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{
    QStringList args;
    args << vcsCommandString(CloneCommand)
         << cloneArguments(srcLocation, dstLocation, extraOptions);
    QByteArray stdOut;
    return vcsFullySynchronousExec(workingDir, args, &stdOut);
}

bool VCSBaseClient::synchronousAdd(const QString &workingDir, const QString &filename)
{
    QStringList args;
    args << vcsCommandString(AddCommand) << filename;
    QByteArray stdOut;
    return vcsFullySynchronousExec(workingDir, args, &stdOut);
}

bool VCSBaseClient::synchronousRemove(const QString &workingDir, const QString &filename)
{
    QStringList args;
    args << vcsCommandString(RemoveCommand) << filename;
    QByteArray stdOut;
    return vcsFullySynchronousExec(workingDir, args, &stdOut);
}

bool VCSBaseClient::synchronousMove(const QString &workingDir,
                                    const QString &from, const QString &to)
{
    QStringList args;
    args << vcsCommandString(MoveCommand) << from << to;
    QByteArray stdOut;
    return vcsFullySynchronousExec(workingDir, args, &stdOut);
}

bool VCSBaseClient::synchronousPull(const QString &workingDir,
                                    const QString &srcLocation,
209
                                    const QStringList &extraOptions)
cerf's avatar
cerf committed
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
{
    QStringList args;
    args << vcsCommandString(PullCommand) << pullArguments(srcLocation, extraOptions);
    // Disable UNIX terminals to suppress SSH prompting
    const unsigned flags =
            VCSBase::VCSBasePlugin::SshPasswordPrompt
            | VCSBase::VCSBasePlugin::ShowStdOutInLogWindow
            | VCSBase::VCSBasePlugin::ShowSuccessMessage;
    const Utils::SynchronousProcessResponse resp = vcsSynchronousExec(workingDir, args, flags);
    const bool ok = resp.result == Utils::SynchronousProcessResponse::Finished;
    if (ok)
        emit changed(QVariant(workingDir));
    return ok;
}

bool VCSBaseClient::synchronousPush(const QString &workingDir,
                                    const QString &dstLocation,
227
                                    const QStringList &extraOptions)
cerf's avatar
cerf committed
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
{
    QStringList args;
    args << vcsCommandString(PushCommand) << pushArguments(dstLocation, extraOptions);
    // Disable UNIX terminals to suppress SSH prompting
    const unsigned flags =
            VCSBase::VCSBasePlugin::SshPasswordPrompt
            | VCSBase::VCSBasePlugin::ShowStdOutInLogWindow
            | VCSBase::VCSBasePlugin::ShowSuccessMessage;
    const Utils::SynchronousProcessResponse resp = vcsSynchronousExec(workingDir, args, flags);
    return resp.result == Utils::SynchronousProcessResponse::Finished;
}

bool VCSBaseClient::vcsFullySynchronousExec(const QString &workingDir,
                                            const QStringList &args,
                                            QByteArray *output)
{
    QProcess vcsProcess;
    if (!workingDir.isEmpty())
        vcsProcess.setWorkingDirectory(workingDir);
    VCSJobRunner::setProcessEnvironment(&vcsProcess);

249
250
    const QString binary = settings()->binary();
    const QStringList arguments = settings()->standardArguments() + args;
cerf's avatar
cerf committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264

    VCSBase::VCSBaseOutputWindow *outputWindow = VCSBase::VCSBaseOutputWindow::instance();
    outputWindow->appendCommand(workingDir, binary, args);

    vcsProcess.start(binary, arguments);

    if (!vcsProcess.waitForStarted()) {
        outputWindow->appendError(VCSJobRunner::msgStartFailed(binary, vcsProcess.errorString()));
        return false;
    }

    vcsProcess.closeWriteChannel();

    QByteArray stdErr;
265
    if (!Utils::SynchronousProcess::readDataFromProcess(vcsProcess, settings()->timeoutMilliSeconds(),
cerf's avatar
cerf committed
266
267
                                                        output, &stdErr, true)) {
        Utils::SynchronousProcess::stopProcess(vcsProcess);
268
        outputWindow->appendError(VCSJobRunner::msgTimeout(binary, settings()->timeoutSeconds()));
cerf's avatar
cerf committed
269
270
271
272
273
274
275
276
277
278
279
280
281
282
        return false;
    }
    if (!stdErr.isEmpty())
        outputWindow->append(QString::fromLocal8Bit(stdErr));

    return vcsProcess.exitStatus() == QProcess::NormalExit && vcsProcess.exitCode() == 0;
}

Utils::SynchronousProcessResponse VCSBaseClient::vcsSynchronousExec(
    const QString &workingDirectory,
    const QStringList &args,
    unsigned flags,
    QTextCodec *outputCodec)
{
283
284
    const QString binary = settings()->binary();
    const QStringList arguments = settings()->standardArguments() + args;
cerf's avatar
cerf committed
285
    return VCSBase::VCSBasePlugin::runVCS(workingDirectory, binary, arguments,
286
                                          settings()->timeoutMilliSeconds(),
cerf's avatar
cerf committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
                                          flags, outputCodec);
}

void VCSBaseClient::annotate(const QString &workingDir, const QString &file,
                             const QString revision /* = QString() */,
                             int lineNumber /* = -1 */)
{
    Q_UNUSED(lineNumber)
    const QString vcsCmdString = vcsCommandString(AnnotateCommand);
    QStringList args;
    args << vcsCmdString << annotateArguments(file, revision, lineNumber);
    const QString kind = vcsEditorKind(AnnotateCommand);
    const QString id = VCSBase::VCSBaseEditorWidget::getSource(workingDir, QStringList(file));
    const QString title = vcsEditorTitle(vcsCmdString, id);
    const QString source = VCSBase::VCSBaseEditorWidget::getSource(workingDir, file);

    VCSBase::VCSBaseEditorWidget *editor = createVCSEditor(kind, title, source, true,
                                                           vcsCmdString.toLatin1().constData(), id);

    QSharedPointer<VCSJob> job(new VCSJob(workingDir, args, editor));
    enqueueJob(job);
}

310
void VCSBaseClient::diff(const QString &workingDir, const QStringList &files,
311
                         const QStringList &extraOptions)
cerf's avatar
cerf committed
312
313
314
315
316
317
318
319
{
    const QString vcsCmdString = vcsCommandString(DiffCommand);
    const QString kind = vcsEditorKind(DiffCommand);
    const QString id = VCSBase::VCSBaseEditorWidget::getTitleId(workingDir, files);
    const QString title = vcsEditorTitle(vcsCmdString, id);
    const QString source = VCSBase::VCSBaseEditorWidget::getSource(workingDir, files);
    VCSBase::VCSBaseEditorWidget *editor = createVCSEditor(kind, title, source, true,
                                                           vcsCmdString.toLatin1().constData(), id);
320
    editor->setRevertDiffChunkEnabled(true);
cerf's avatar
cerf committed
321
322
    editor->setDiffBaseDirectory(workingDir);

323
324
325
326
327
328
329
330
331
332
    VCSBaseEditorParameterWidget *paramWidget = createDiffEditor(workingDir, files, extraOptions);
    if (paramWidget != 0) {
        connect(editor, SIGNAL(diffChunkReverted(VCSBase::DiffChunk)),
                paramWidget, SLOT(executeCommand()));
        editor->setConfigurationWidget(paramWidget);
    }

    QStringList args;
    const QStringList paramArgs = paramWidget != 0 ? paramWidget->arguments() : QStringList();
    args << vcsCmdString << diffArguments(files, extraOptions + paramArgs);
cerf's avatar
cerf committed
333
334
335
336
337
    QSharedPointer<VCSJob> job(new VCSJob(workingDir, args, editor));
    enqueueJob(job);
}

void VCSBaseClient::log(const QString &workingDir, const QStringList &files,
338
                        const QStringList &extraOptions,
cerf's avatar
cerf committed
339
340
341
342
343
344
345
346
                        bool enableAnnotationContextMenu)
{
    const QString vcsCmdString = vcsCommandString(LogCommand);
    const QString kind = vcsEditorKind(LogCommand);
    const QString id = VCSBase::VCSBaseEditorWidget::getTitleId(workingDir, files);
    const QString title = vcsEditorTitle(vcsCmdString, id);
    const QString source = VCSBase::VCSBaseEditorWidget::getSource(workingDir, files);

347
    VCSBase::VCSBaseEditorWidget *editor = createVCSEditor(kind, title, source, true,
cerf's avatar
cerf committed
348
349
350
                                                           vcsCmdString.toLatin1().constData(), id);
    editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);

351
352
353
354
355
356
357
    VCSBaseEditorParameterWidget *paramWidget = createLogEditor(workingDir, files, extraOptions);
    if (paramWidget != 0)
        editor->setConfigurationWidget(paramWidget);

    QStringList args;
    const QStringList paramArgs = paramWidget != 0 ? paramWidget->arguments() : QStringList();
    args << vcsCmdString << logArguments(files, extraOptions + paramArgs);
cerf's avatar
cerf committed
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
    QSharedPointer<VCSJob> job(new VCSJob(workingDir, args, editor));
    enqueueJob(job);
}

void VCSBaseClient::revertFile(const QString &workingDir,
                               const QString &file,
                               const QString &revision)
{
    QStringList args(vcsCommandString(RevertCommand));
    args << revertArguments(file, revision);
    // Indicate repository change or file list
    QSharedPointer<VCSJob> job(new VCSJob(workingDir, args));
    job->setCookie(QStringList(workingDir + QLatin1Char('/') + file));
    connect(job.data(), SIGNAL(succeeded(QVariant)),
            this, SIGNAL(changed(QVariant)), Qt::QueuedConnection);
    enqueueJob(job);
}

void VCSBaseClient::revertAll(const QString &workingDir, const QString &revision)
{
    QStringList args(vcsCommandString(RevertCommand));
    args << revertAllArguments(revision);
    // Indicate repository change or file list
    QSharedPointer<VCSJob> job(new VCSJob(workingDir, args));
    connect(job.data(), SIGNAL(succeeded(QVariant)),
            this, SIGNAL(changed(QVariant)), Qt::QueuedConnection);
    enqueueJob(job);
}

void VCSBaseClient::status(const QString &workingDir, const QString &file)
{
    QStringList args(vcsCommandString(StatusCommand));
    args << statusArguments(file);
    VCSBase::VCSBaseOutputWindow *outwin = VCSBase::VCSBaseOutputWindow::instance();
    outwin->setRepository(workingDir);
    QSharedPointer<VCSJob> job(new VCSJob(workingDir, args));
    connect(job.data(), SIGNAL(succeeded(QVariant)),
            outwin, SLOT(clearRepository()), Qt::QueuedConnection);
    enqueueJob(job);
}

void VCSBaseClient::statusWithSignal(const QString &repositoryRoot)
{
    QStringList args(vcsCommandString(StatusCommand));
    args << statusArguments(QString());
    QSharedPointer<VCSJob> job(new VCSJob(repositoryRoot, args, VCSJob::RawDataEmitMode));
404
    connect(job.data(), SIGNAL(rawData(QByteArray)), this, SLOT(statusParser(QByteArray)));
cerf's avatar
cerf committed
405
406
407
408
409
    enqueueJob(job);
}

QString VCSBaseClient::vcsCommandString(VCSCommand cmd) const
{
Tobias Hunger's avatar
Tobias Hunger committed
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
    switch (cmd) {
    case CreateRepositoryCommand: return QLatin1String("init");
    case CloneCommand: return QLatin1String("clone");
    case AddCommand: return QLatin1String("add");
    case RemoveCommand: return QLatin1String("remove");
    case MoveCommand: return QLatin1String("rename");
    case PullCommand: return QLatin1String("pull");
    case PushCommand: return QLatin1String("push");
    case CommitCommand: return QLatin1String("commit");
    case ImportCommand: return QLatin1String("import");
    case UpdateCommand: return QLatin1String("update");
    case RevertCommand: return QLatin1String("revert");
    case AnnotateCommand: return QLatin1String("annotate");
    case DiffCommand: return QLatin1String("diff");
    case LogCommand: return QLatin1String("log");
    case StatusCommand: return QLatin1String("status");
cerf's avatar
cerf committed
426
    }
Tobias Hunger's avatar
Tobias Hunger committed
427
    return QString();
cerf's avatar
cerf committed
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
}

void VCSBaseClient::import(const QString &repositoryRoot, const QStringList &files)
{
    QStringList args(vcsCommandString(ImportCommand));
    args << importArguments(files);
    QSharedPointer<VCSJob> job(new VCSJob(repositoryRoot, args));
    enqueueJob(job);
}

void VCSBaseClient::view(const QString &source, const QString &id)
{
    QStringList args(viewArguments(id));
    const QString kind = vcsEditorKind(DiffCommand);
    const QString title = vcsEditorTitle(vcsCommandString(LogCommand), id);

    VCSBase::VCSBaseEditorWidget *editor = createVCSEditor(kind, title, source,
                                                           true, "view", id);

447
448
449
    const QFileInfo fi(source);
    const QString workingDirPath = fi.isFile() ? fi.absolutePath() : source;
    QSharedPointer<VCSJob> job(new VCSJob(workingDirPath, args, editor));
cerf's avatar
cerf committed
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
    enqueueJob(job);
}

void VCSBaseClient::update(const QString &repositoryRoot, const QString &revision)
{
    QStringList args(vcsCommandString(UpdateCommand));
    args.append(updateArguments(revision));

    QSharedPointer<VCSJob> job(new VCSJob(repositoryRoot, args));
    job->setCookie(repositoryRoot);
    // Suppress SSH prompting
    job->setUnixTerminalDisabled(VCSBase::VCSBasePlugin::isSshPromptConfigured());
    connect(job.data(), SIGNAL(succeeded(QVariant)), this, SIGNAL(changed(QVariant)), Qt::QueuedConnection);
    enqueueJob(job);
}

void VCSBaseClient::commit(const QString &repositoryRoot,
                           const QStringList &files,
                           const QString &commitMessageFile,
469
                           const QStringList &extraOptions)
cerf's avatar
cerf committed
470
471
472
473
474
475
476
{
    QStringList args(vcsCommandString(CommitCommand));
    args.append(commitArguments(files, commitMessageFile, extraOptions));
    QSharedPointer<VCSJob> job(new VCSJob(repositoryRoot, args));
    enqueueJob(job);
}

477
VCSBaseClientSettings *VCSBaseClient::settings() const
478
479
480
481
{
    return d->m_clientSettings;
}

482
void VCSBaseClient::handleSettingsChanged()
cerf's avatar
cerf committed
483
{
Friedemann Kleint's avatar
Friedemann Kleint committed
484
    if (d->m_jobManager) {
485
486
487
        d->m_jobManager->setSettings(settings()->binary(),
                                     settings()->standardArguments(),
                                     settings()->timeoutMilliSeconds());
Friedemann Kleint's avatar
Friedemann Kleint committed
488
        d->m_jobManager->restart();
cerf's avatar
cerf committed
489
490
491
    }
}

492
493
494
VCSBaseEditorParameterWidget *VCSBaseClient::createDiffEditor(const QString &workingDir,
                                                              const QStringList &files,
                                                              const QStringList &extraOptions)
495
{
496
497
498
499
    Q_UNUSED(workingDir);
    Q_UNUSED(files);
    Q_UNUSED(extraOptions);
    return 0;
500
501
}

502
503
504
505
506
507
508
509
510
VCSBaseEditorParameterWidget *VCSBaseClient::createLogEditor(const QString &workingDir,
                                                             const QStringList &files,
                                                             const QStringList &extraOptions)
{
    Q_UNUSED(workingDir);
    Q_UNUSED(files);
    Q_UNUSED(extraOptions);
    return 0;
}
511

cerf's avatar
cerf committed
512
513
QString VCSBaseClient::vcsEditorTitle(const QString &vcsCmd, const QString &sourceId) const
{
514
    return QFileInfo(settings()->binary()).baseName() +
515
516
            QLatin1Char(' ') + vcsCmd + QLatin1Char(' ') +
            QFileInfo(sourceId).fileName();
cerf's avatar
cerf committed
517
518
519
520
521
522
523
524
}

VCSBase::VCSBaseEditorWidget *VCSBaseClient::createVCSEditor(const QString &kind, QString title,
                                                             const QString &source, bool setSourceCodec,
                                                             const char *registerDynamicProperty,
                                                             const QString &dynamicPropertyValue) const
{
    VCSBase::VCSBaseEditorWidget *baseEditor = 0;
Friedemann Kleint's avatar
Friedemann Kleint committed
525
    Core::IEditor *outputEditor = locateEditor(d->m_core, registerDynamicProperty, dynamicPropertyValue);
cerf's avatar
cerf committed
526
527
528
529
530
531
532
    const QString progressMsg = tr("Working...");
    if (outputEditor) {
        // Exists already
        outputEditor->createNew(progressMsg);
        baseEditor = VCSBase::VCSBaseEditorWidget::getVcsBaseEditor(outputEditor);
        QTC_ASSERT(baseEditor, return 0);
    } else {
Friedemann Kleint's avatar
Friedemann Kleint committed
533
        outputEditor = d->m_core->editorManager()->openEditorWithContents(kind, &title, progressMsg);
cerf's avatar
cerf committed
534
535
536
        outputEditor->file()->setProperty(registerDynamicProperty, dynamicPropertyValue);
        baseEditor = VCSBase::VCSBaseEditorWidget::getVcsBaseEditor(outputEditor);
        connect(baseEditor, SIGNAL(annotateRevisionRequested(QString,QString,int)),
537
                this, SLOT(annotateRevision(QString,QString,int)));
cerf's avatar
cerf committed
538
539
540
541
542
543
544
        QTC_ASSERT(baseEditor, return 0);
        baseEditor->setSource(source);
        if (setSourceCodec)
            baseEditor->setCodec(VCSBase::VCSBaseEditorWidget::getCodec(source));
    }

    baseEditor->setForceReadOnly(true);
545
    d->m_core->editorManager()->activateEditor(outputEditor, Core::EditorManager::ModeSwitch);
cerf's avatar
cerf committed
546
547
548
549
550
    return baseEditor;
}

void VCSBaseClient::enqueueJob(const QSharedPointer<VCSJob> &job)
{
Friedemann Kleint's avatar
Friedemann Kleint committed
551
552
    if (!d->m_jobManager) {
        d->m_jobManager = new VCSJobRunner();
553
554
555
        d->m_jobManager->setSettings(settings()->binary(),
                                     settings()->standardArguments(),
                                     settings()->timeoutMilliSeconds());
Friedemann Kleint's avatar
Friedemann Kleint committed
556
        d->m_jobManager->start();
cerf's avatar
cerf committed
557
    }
Friedemann Kleint's avatar
Friedemann Kleint committed
558
    d->m_jobManager->enqueueJob(job);
cerf's avatar
cerf committed
559
560
561
}

} // namespace VCSBase
562
563

#include "moc_vcsbaseclient.cpp"