Commit 9d4aafeb authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

VCS/git: Make blame go to current editor line

using queued slot/variant cookie magic in command
parent 01877b2c
......@@ -310,7 +310,7 @@ void GitClient::blame(const QString &workingDirectory, const QString &fileName,
const QString sourceFile = source(workingDirectory, fileName);
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, sourceFile, true, "blameFileName", sourceFile);
executeGit(workingDirectory, arguments, editor);
executeGit(workingDirectory, arguments, editor, false, GitCommand::NoReport, lineNumber);
}
void GitClient::checkoutBranch(const QString &workingDirectory, const QString &branch)
......@@ -473,13 +473,16 @@ bool GitClient::synchronousShow(const QString &workingDirectory, const QString &
// Factory function to create an asynchronous command
GitCommand *GitClient::createCommand(const QString &workingDirectory,
VCSBase::VCSBaseEditor* editor,
bool outputToWindow)
bool outputToWindow,
int editorLineNumber)
{
if (Git::Constants::debug)
qDebug() << Q_FUNC_INFO << workingDirectory << editor;
VCSBase::VCSBaseOutputWindow *outputWindow = VCSBase::VCSBaseOutputWindow::instance();
GitCommand* command = new GitCommand(binary(), workingDirectory, processEnvironment());
GitCommand* command = new GitCommand(binary(), workingDirectory, processEnvironment(), QVariant(editorLineNumber));
if (editor)
connect(command, SIGNAL(finished(bool,QVariant)), editor, SLOT(commandFinishedGotoLine(bool,QVariant)));
if (outputToWindow) {
if (editor) { // assume that the commands output is the important thing
connect(command, SIGNAL(outputData(QByteArray)), outputWindow, SLOT(appendDataSilently(QByteArray)));
......@@ -501,10 +504,11 @@ void GitClient::executeGit(const QString &workingDirectory,
const QStringList &arguments,
VCSBase::VCSBaseEditor* editor,
bool outputToWindow,
GitCommand::TerminationReportMode tm)
GitCommand::TerminationReportMode tm,
int editorLineNumber)
{
VCSBase::VCSBaseOutputWindow::instance()->appendCommand(formatCommand(QLatin1String(Constants::GIT_BINARY), arguments));
GitCommand *command = createCommand(workingDirectory, editor, outputToWindow);
GitCommand *command = createCommand(workingDirectory, editor, outputToWindow, editorLineNumber);
command->addJob(arguments, m_settings.timeout);
command->setTerminationReportMode(tm);
command->execute();
......
......@@ -155,13 +155,15 @@ private:
GitCommand *createCommand(const QString &workingDirectory,
VCSBase::VCSBaseEditor* editor = 0,
bool outputToWindow = false);
bool outputToWindow = false,
int editorLineNumber = -1);
void executeGit(const QString &workingDirectory,
const QStringList &arguments,
VCSBase::VCSBaseEditor* editor = 0,
bool outputToWindow = false,
GitCommand::TerminationReportMode tm = GitCommand::NoReport);
GitCommand::TerminationReportMode tm = GitCommand::NoReport,
int editorLineNumber = -1);
bool synchronousGit(const QString &workingDirectory,
const QStringList &arguments,
......
......@@ -41,6 +41,8 @@
#include <QtCore/QFileInfo>
#include <QtCore/QCoreApplication>
Q_DECLARE_METATYPE(QVariant)
namespace Git {
namespace Internal {
......@@ -60,15 +62,20 @@ GitCommand::Job::Job(const QStringList &a, int t) :
arguments(a),
timeout(t)
{
// Finished cookie is emitted via queued slot, needs metatype
static const int qvMetaId = qRegisterMetaType<QVariant>();
Q_UNUSED(qvMetaId)
}
GitCommand::GitCommand(const QStringList &binary,
const QString &workingDirectory,
const QStringList &environment) :
const QStringList &environment,
const QVariant &cookie) :
m_binaryPath(binary.front()),
m_basicArguments(binary),
m_workingDirectory(workingDirectory),
m_environment(environment),
m_cookie(cookie),
m_reportTerminationMode(NoReport)
{
m_basicArguments.pop_front();
......@@ -169,6 +176,7 @@ void GitCommand::run()
if (!error.isEmpty())
emit errorText(error);
emit finished(ok, m_cookie);
// As it is used asynchronously, we need to delete ourselves
this->deleteLater();
}
......
......@@ -32,10 +32,13 @@
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
namespace Git {
namespace Internal {
// Asynchronous command with output signals and a finished
// signal with a magic cookie
class GitCommand : public QObject
{
Q_DISABLE_COPY(GitCommand)
......@@ -48,7 +51,8 @@ public:
explicit GitCommand(const QStringList &binary,
const QString &workingDirectory,
const QStringList &environment);
const QStringList &environment,
const QVariant &cookie = QVariant());
void addJob(const QStringList &arguments, int timeout);
......@@ -68,6 +72,7 @@ private:
Q_SIGNALS:
void outputData(const QByteArray&);
void errorText(const QString&);
void finished(bool ok, const QVariant &cookie);
private:
struct Job {
......@@ -81,6 +86,7 @@ private:
QStringList m_basicArguments;
const QString m_workingDirectory;
const QStringList m_environment;
const QVariant m_cookie;
QList<Job> m_jobs;
TerminationReportMode m_reportTerminationMode;
......
......@@ -184,5 +184,14 @@ void GitEditor::setPlainTextDataFiltered(const QByteArray &a)
}
}
void GitEditor::commandFinishedGotoLine(bool ok, const QVariant &v)
{
if (ok && v.type() == QVariant::Int) {
const int line = v.toInt();
if (line >= 0)
gotoLine(line);
}
}
} // namespace Internal
} // namespace Git
......@@ -34,6 +34,10 @@
#include <QtCore/QRegExp>
QT_BEGIN_NAMESPACE
class QVariant;
QT_END_NAMESPACE
namespace Git {
namespace Internal {
......@@ -49,6 +53,8 @@ public:
public slots:
void setPlainTextDataFiltered(const QByteArray &a);
// Matches the signature of the finished signal of GitCommand
void commandFinishedGotoLine(bool ok, const QVariant &v);
private:
virtual QSet<QString> annotationChanges() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment