From 252179b9383bb98ebfcaf89d0dc3d19a063d7669 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 21 Nov 2022 15:08:27 +0200 Subject: Git: Stop blame attempts for unmanaged files in the repository MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A file that is in the repository directory, but not managed by Git should not attempt to run instant blame on every cursor change. Change-Id: Ia7daa2ae9980cea4363e010a98fb1e2f2a3ec05f Reviewed-by: André Hartmann --- src/plugins/git/gitplugin.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/plugins/git/gitplugin.cpp') diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index d50bf9ac51..66969b4df5 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -430,6 +430,7 @@ public: Author m_author; int m_lastVisitedEditorLine = -1; QTimer *m_cursorPositionChangedTimer = nullptr; + QMetaObject::Connection m_blameCursorPosConn; GitSettingsPage settingPage{&m_settings}; @@ -1456,11 +1457,10 @@ void GitPluginPrivate::setupInstantBlame() if (qobject_cast(widget)) return; // Skip in VCS editors like log or blame - auto cursorPosConn = std::make_shared(); - *cursorPosConn = connect(widget, &QPlainTextEdit::cursorPositionChanged, this, - [this, cursorPosConn] { + m_blameCursorPosConn = connect(widget, &QPlainTextEdit::cursorPositionChanged, this, + [this] { if (!GitClient::instance()->settings().instantBlame.value()) { - disconnect(*cursorPosConn); + disconnect(m_blameCursorPosConn); return; } m_cursorPositionChangedTimer->start(500); @@ -1571,8 +1571,13 @@ void GitPluginPrivate::instantBlame() const QString lineString = QString("%1,%1").arg(line); const VcsCommand *command = GitClient::instance()->vcsExec( workingDirectory, {"blame", "-p", "-L", lineString, "--", filePath.toString()}, - nullptr, false, RunFlags::SuppressCommandLogging | RunFlags::ProgressiveOutput); + nullptr, false, RunFlags::NoOutput); connect(command, &VcsCommand::done, this, [command, filePath, line, this]() { + if (command->result() == ProcessResult::FinishedWithError && + command->cleanedStdErr().contains("no such path")) { + disconnect(m_blameCursorPosConn); + return; + } const QString output = command->cleanedStdOut(); const CommitInfo info = parseBlameOutput(output.split('\n'), filePath, m_author); m_blameMark.reset(new BlameMark(filePath, line, info)); -- cgit v1.2.1